From f2b4a83646efaa3293a4d0458630350b2a2b67ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 30 Jan 2024 11:39:17 +0100 Subject: [PATCH] Add a new warnCommon mode similar to failCommon --- .../eclipse/tycho/plugins/p2/BaselineMode.java | 6 ++++++ .../tycho/plugins/p2/BaselineValidator.java | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/BaselineMode.java b/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/BaselineMode.java index 3a7a7f54bb..02fb39d39c 100644 --- a/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/BaselineMode.java +++ b/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/BaselineMode.java @@ -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. diff --git a/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/BaselineValidator.java b/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/BaselineValidator.java index 64e520ec9a..6cfff835d9 100644 --- a/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/BaselineValidator.java +++ b/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/BaselineValidator.java @@ -105,9 +105,9 @@ public Map 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()); } } @@ -198,7 +198,18 @@ public Map 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; }