diff --git a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/artifactcomparator/ArtifactComparator.java b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/artifactcomparator/ArtifactComparator.java index 411180709c..dff561cd15 100644 --- a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/artifactcomparator/ArtifactComparator.java +++ b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/artifactcomparator/ArtifactComparator.java @@ -19,22 +19,22 @@ public interface ArtifactComparator { - public static class ComparisonData { + public static record ComparisonData(List ignoredPattern, boolean writeDelta, boolean showDiffDetails) { - public ComparisonData(List ignoredPattern, boolean writeDelta) { - this.ignoredPattern = ignoredPattern != null ? List.copyOf(ignoredPattern) : List.of(); - this.writeDelta = writeDelta; - } + /** + * System property that control if a detailed diff is desired or not, false + * (default) = no detailed diff is shown, true show detailed difference. + */ + private static final boolean SHOW_DIFF_DETAILS = Boolean.getBoolean("tycho.comparator.showDiff"); - private final List ignoredPattern; - private boolean writeDelta; - - public List ignoredPattern() { - return ignoredPattern; + public ComparisonData(List ignoredPattern, boolean writeDelta) { + this(ignoredPattern, writeDelta, SHOW_DIFF_DETAILS); } - public boolean writeDelta() { - return writeDelta; + public ComparisonData(List ignoredPattern, boolean writeDelta, boolean showDiffDetails) { + this.ignoredPattern = ignoredPattern != null ? List.copyOf(ignoredPattern) : List.of(); + this.writeDelta = writeDelta; + this.showDiffDetails = showDiffDetails; } } diff --git a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ContentsComparator.java b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ContentsComparator.java index dd8964068d..a72a8e4954 100644 --- a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ContentsComparator.java +++ b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ContentsComparator.java @@ -21,12 +21,6 @@ public interface ContentsComparator { - /** - * System property that control if a detailed diff is desired or not, false - * (default) = no detailed diff is shown, true show detailed difference. - */ - static final boolean SHOW_DIFF_DETAILS = Boolean.getBoolean("tycho.comparator.showDiff"); - /** * System property that controls the threshold size where a direct byte compare is performed * (default 5 mb) @@ -36,7 +30,7 @@ public interface ContentsComparator { /** * Computes the delta for the given {@link InputStream}s, the streams passed will support * mark/reset for repeated reads. - * + * * @param baseline * the baseline data * @param reactor @@ -51,7 +45,7 @@ public ArtifactDelta getDelta(ComparatorInputStream baseline, ComparatorInputStr /** * Check if this comparator matches the given name or extension - * + * * @param nameOrExtension * the extension or name to match * @return true if this comparator matches, false otherwise diff --git a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/TextComparator.java b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/TextComparator.java index d73adfa70f..46b9ebabaa 100644 --- a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/TextComparator.java +++ b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/TextComparator.java @@ -6,7 +6,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * Christoph Läubrich - initial API and implementation *******************************************************************************/ @@ -48,12 +48,12 @@ public static ArtifactDelta compareText(ComparatorInputStream baseline, Comparat ByteIterator reactorIterator = new ByteIterator(reactor.asBytes()); while (baselineIterator.hasNext() && reactorIterator.hasNext()) { if (baselineIterator.next() != reactorIterator.next()) { - return createDelta(ArtifactDelta.DEFAULT.getMessage(), baseline, reactor); + return createDelta(ArtifactDelta.DEFAULT.getMessage(), baseline, reactor, data); } } //now both need to be at the end of the stream if they are the same! if (baselineIterator.hasNext() || reactorIterator.hasNext()) { - return createDelta(ArtifactDelta.DEFAULT.getMessage(), baseline, reactor); + return createDelta(ArtifactDelta.DEFAULT.getMessage(), baseline, reactor, data); } return ArtifactDelta.NO_DIFFERENCE; } @@ -100,8 +100,8 @@ public boolean matches(String nameOrExtension) { } public static ArtifactDelta createDelta(String message, ComparatorInputStream baseline, - ComparatorInputStream reactor) { - if (SHOW_DIFF_DETAILS) { + ComparatorInputStream reactor, ComparisonData data) { + if (data.showDiffDetails()) { String detailed; try { List source = IOUtils.readLines(baseline.asNewStream(), StandardCharsets.UTF_8); diff --git a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/XmlComparator.java b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/XmlComparator.java index 688396f59d..7ef0b3e7a0 100644 --- a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/XmlComparator.java +++ b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/XmlComparator.java @@ -6,7 +6,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * Christoph Läubrich - initial API and implementation *******************************************************************************/ @@ -43,21 +43,20 @@ public ArtifactDelta getDelta(ComparatorInputStream baseline, ComparatorInputStr Diff baselineDiff = computeDiff(baseline, reactor); if (baselineDiff.hasDifferences()) { String message = baselineDiff.fullDescription(); - return TextComparator.createDelta(message, baseline, reactor); + return TextComparator.createDelta(message, baseline, reactor, data); } return null; } catch (RuntimeException e) { - return TextComparator.createDelta(ArtifactDelta.DEFAULT.getMessage(), baseline, reactor); + return TextComparator.createDelta(ArtifactDelta.DEFAULT.getMessage(), baseline, reactor, data); } } private Diff computeDiff(InputStream baseline, InputStream reactor) { - Diff baselineDiff = DiffBuilder.compare(Input.fromStream(baseline))// + return DiffBuilder.compare(Input.fromStream(baseline))// .withTest(Input.fromStream(reactor))// .checkForSimilar()// .ignoreComments() // .ignoreWhitespace().build(); - return baselineDiff; } @Override