Skip to content

Commit

Permalink
#284 if exception happen during the artifact resolution they are only…
Browse files Browse the repository at this point in the history
… logged, the build is not broken

#283 the ignoreMissingArtifact option is evaluated properly when the artifact is missing
  • Loading branch information
siom79 committed Mar 6, 2021
1 parent f0f8452 commit 854a131
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ private enum ConfigurationVersion {
OLD, NEW
}

private Artifact getComparisonArtifact(final MavenParameters mavenParameters, final PluginParameters pluginParameters) throws MojoFailureException, MojoExecutionException {
private Artifact getComparisonArtifact(final MavenParameters mavenParameters, final PluginParameters pluginParameters,
final ConfigurationVersion configurationVersion) throws MojoFailureException, MojoExecutionException {
MavenProject mavenProject = mavenParameters.getMavenProject();
DefaultArtifact artifactVersionRange = new DefaultArtifact(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getPackaging(), mavenParameters.getVersionRangeWithProjectVersion());
VersionRangeRequest versionRangeRequest = new VersionRangeRequest(artifactVersionRange, mavenParameters.getRemoteRepos(), null);
Expand All @@ -223,9 +224,7 @@ private Artifact getComparisonArtifact(final MavenParameters mavenParameters, fi
versions.get(versions.size()-1).toString());
ArtifactRequest artifactRequest = new ArtifactRequest(artifactVersion, mavenParameters.getRemoteRepos(), null);
ArtifactResult artifactResult = mavenParameters.getRepoSystem().resolveArtifact(mavenParameters.getRepoSession(), artifactRequest);
if (artifactResult.isMissing() || (artifactResult.getExceptions() != null && !artifactResult.getExceptions().isEmpty())){
throw new MojoFailureException("Could not resolve artifact: " + artifactVersion);
}
processArtifacResult(artifactVersion, artifactResult, pluginParameters, configurationVersion);
return artifactResult.getArtifact();
} else {
throw new MojoFailureException("Could not find previous version for artifact: " + artifactVersionRange.getGroupId() + ":"
Expand All @@ -237,6 +236,23 @@ private Artifact getComparisonArtifact(final MavenParameters mavenParameters, fi
}
}

private void processArtifacResult(DefaultArtifact artifactVersion, ArtifactResult artifactResult,
PluginParameters pluginParameters, ConfigurationVersion configurationVersion) throws MojoFailureException {
if (artifactResult.getExceptions() != null && !artifactResult.getExceptions().isEmpty()) {
List<Exception> exceptions = artifactResult.getExceptions();
for (Exception exception : exceptions) {
getLog().debug(exception.getMessage(), exception);
}
}
if (artifactResult.isMissing()){
if (ignoreMissingArtifact(pluginParameters, configurationVersion)) {
getLog().warn("Ignoring missing artifact: " + artifactResult.getArtifact());
} else {
throw new MojoFailureException("Could not resolve artifact: " + artifactVersion);
}
}
}

private void filterVersionPattern(List<org.eclipse.aether.version.Version> availableVersions, PluginParameters pluginParameters) throws MojoFailureException {
if (pluginParameters.getParameterParam() != null && pluginParameters.getParameterParam().getOldVersionPattern() != null) {
String versionPattern = pluginParameters.getParameterParam().getOldVersionPattern();
Expand Down Expand Up @@ -278,7 +294,7 @@ private void populateArchivesListsFromParameters(PluginParameters pluginParamete
}
if (pluginParameters.getOldVersionParam() == null && pluginParameters.getOldVersionsParam() == null) {
try {
Artifact comparisonArtifact = getComparisonArtifact(mavenParameters, pluginParameters);
Artifact comparisonArtifact = getComparisonArtifact(mavenParameters, pluginParameters, ConfigurationVersion.OLD);
if (comparisonArtifact.getVersion() != null) {
Set<Artifact> artifacts = resolveArtifact(comparisonArtifact, mavenParameters, pluginParameters, ConfigurationVersion.OLD);
for (Artifact artifact : artifacts) {
Expand Down Expand Up @@ -887,20 +903,15 @@ private Set<Artifact> resolveArtifact(Artifact artifact, MavenParameters mavenPa
if (resolutionResult != null) {
if (resolutionResult.getExceptions() != null && !resolutionResult.getExceptions().isEmpty()) {
List<Exception> exceptions = resolutionResult.getExceptions();
String message = "Could not resolve " + artifact;
if (ignoreMissingArtifact(pluginParameters, configurationVersion)) {
getLog().warn(message);
} else {
throw new MojoFailureException(message, exceptions.get(0));
for (Exception exception : exceptions) {
getLog().debug(exception.getMessage(), exception);
}
return new HashSet<>();
}
if (resolutionResult.isMissing()) {
String msg = "Could not resolve artifact " + request.getArtifact();
if (ignoreMissingArtifact(pluginParameters, configurationVersion)) {
getLog().warn(msg);
getLog().warn("Ignoring missing artifact " + request.getArtifact());
} else {
throw new MojoFailureException(msg);
throw new MojoFailureException("Could not resolve artifact " + request.getArtifact());
}
return new HashSet<>();
}
Expand Down

0 comments on commit 854a131

Please sign in to comment.