Skip to content

Commit

Permalink
Add a new warnCommon mode similar to failCommon
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 30, 2024
1 parent e3c7b90 commit f2b4a83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public enum BaselineMode {
*/
warn,

/**
* Warn about discrepancies between build and baseline artifacts but do not fail the build.
* Attached artifacts only present in the build do not result in a warning.
*/
warnCommon,

/**
* Fail the build if there are discrepancies between artifacts present both in build and
* baseline. Attached artifacts only present in the build do not result in build failure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public Map<String, IP2Artifact> validateAndReplace(MavenProject project, Compari
classifier.getValue().writeDetails(new File(logdir, classifier.getKey()));
}
}
if (baselineMode == fail || (baselineMode == failCommon && !isMissingOnlyDelta(delta))) {
if (shouldFail(baselineMode, delta)) {
throw new MojoExecutionException(delta.getDetailedMessage());
} else {
} else if (shouldWarn(baselineMode, delta)) {
log.warn(project.toString() + ": " + delta.getDetailedMessage());
}
}
Expand Down Expand Up @@ -198,7 +198,18 @@ public Map<String, IP2Artifact> validateAndReplace(MavenProject project, Compari
return result;
}

private boolean isMissingOnlyDelta(ArtifactDelta delta) {
private static boolean shouldFail(BaselineMode baselineMode, CompoundArtifactDelta delta) {
return baselineMode == fail || (baselineMode == failCommon && !isMissingOnlyDelta(delta));
}

private static boolean shouldWarn(BaselineMode baselineMode, CompoundArtifactDelta delta) {
if (baselineMode == BaselineMode.warnCommon) {
return !isMissingOnlyDelta(delta);
}
return true;
}

private static boolean isMissingOnlyDelta(ArtifactDelta delta) {
if (delta instanceof MissingArtifactDelta) {
return true;
}
Expand Down

0 comments on commit f2b4a83

Please sign in to comment.