diff --git a/src/main/java/com/inteligr8/maven/ban/AbstractBanConfiguration.java b/src/main/java/com/inteligr8/maven/ban/AbstractBanConfiguration.java index 35b7fea..076740e 100644 --- a/src/main/java/com/inteligr8/maven/ban/AbstractBanConfiguration.java +++ b/src/main/java/com/inteligr8/maven/ban/AbstractBanConfiguration.java @@ -86,15 +86,19 @@ public abstract class AbstractBanConfiguration implements BanConfiguration { if (!"xml".equals(artifact.getExtension())) artifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "xml", artifact.getVersion()); - Version latestLocalVersion = this.findLatestLocalVersion(artifact, child.getValue()); + Version latestVersion = this.findLatestVersion(artifact, child.getValue()); Artifact latestArtifact = this.findLatestArtifact(artifact, child.getValue()); - if (latestArtifact == null && latestLocalVersion != null) { - this.logger.debug("A latest version was found locally, but could not resolve the artifact; trying to resolve the artifact with the specific version: {}: {}", latestLocalVersion, child.getValue()); - artifact = artifact.setVersion(latestLocalVersion.toString()); + if (latestArtifact == null && latestVersion != null) { + this.logger.debug("A latest version was found, but could not resolve the artifact using the range; trying to resolve the artifact with the specific version: {}: {}", latestVersion, child.getValue()); + artifact = artifact.setVersion(latestVersion.toString()); latestArtifact = this.findLatestArtifact(artifact, child.getValue()); } - if (artifact != null) { + if (latestArtifact != null && latestArtifact.getFile() != null) { + this.logger.debug("The latest artifact was found: {}", latestArtifact); + File file = latestArtifact.getFile(); + downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, this.versionRangeResolver, file); + } else if (artifact != null) { File file = artifact.getFile(); downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, this.versionRangeResolver, file); } @@ -109,16 +113,16 @@ public abstract class AbstractBanConfiguration implements BanConfiguration { } } - private Version findLatestLocalVersion(Artifact artifact, String logId) { - this.logger.trace("Inspecting the local repository to select the version to import: {}", logId); + private Version findLatestVersion(Artifact artifact, String logId) { + this.logger.trace("Inspecting the local and remote repositories to select the version to import: {}", logId); VersionRangeRequest vrrequest = new VersionRangeRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null); try { VersionRangeResult vrresult = this.versionRangeResolver.resolveVersionRange(this.session.getRepositorySession(), vrrequest); if (vrresult.getVersions().isEmpty()) { - this.logger.info("The artifact version range could not be resolved locally; trying remote: {}", logId); + this.logger.info("The artifact version range could not be resolved: {}", logId); return null; } else { - this.logger.debug("The artifact version discovered locally: {}; trying remote: {}", vrresult.getHighestVersion(), logId); + this.logger.debug("The artifact version discovered: {}: {}", vrresult.getHighestVersion(), logId); return vrresult.getHighestVersion(); } } catch (VersionRangeResolutionException vrre) { @@ -132,7 +136,7 @@ public abstract class AbstractBanConfiguration implements BanConfiguration { ArtifactRequest arequest = new ArtifactRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null); try { ArtifactResult aresult = this.artifactResolver.resolveArtifact(this.session.getRepositorySession(), arequest); - this.logger.debug("This artifact version discovered remotely: {}: {}", aresult.getArtifact().getVersion(), logId); + this.logger.debug("This artifact version discovered: {}: {}", aresult.getArtifact().getVersion(), logId); return aresult.getArtifact(); } catch (ArtifactResolutionException are) { this.logger.warn("The artifact could not be resolved; skipping: {}", artifact);