From 0971799d3e6a0f410e3d452c850524208ca61081 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 9 Jul 2020 11:22:18 +0100 Subject: [PATCH 1/2] Better error message on class uniqueness lock file failure --- gradle-baseline-java/build.gradle | 1 + .../tasks/CheckClassUniquenessLockTask.java | 27 ++++++++++++++++--- versions.lock | 2 +- versions.props | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/gradle-baseline-java/build.gradle b/gradle-baseline-java/build.gradle index da2b9504d..1c4331d53 100644 --- a/gradle-baseline-java/build.gradle +++ b/gradle-baseline-java/build.gradle @@ -17,6 +17,7 @@ dependencies { implementation 'com.palantir.javaformat:palantir-java-format-spi' // Add an explicit dependency to ensure consumers can use JDK14 source compat implementation 'org.ow2.asm:asm' + implementation 'com.googlecode.java-diff-utils:diffutils' runtimeOnly 'com.palantir.javaformat:gradle-palantir-java-format' diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/tasks/CheckClassUniquenessLockTask.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/tasks/CheckClassUniquenessLockTask.java index 17ad6255e..e0d5e1c5c 100644 --- a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/tasks/CheckClassUniquenessLockTask.java +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/tasks/CheckClassUniquenessLockTask.java @@ -16,11 +16,15 @@ package com.palantir.baseline.tasks; +import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedMap; +import difflib.DiffUtils; +import difflib.Patch; import java.io.File; import java.util.Collection; import java.util.Comparator; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -159,9 +163,26 @@ private void ensureLockfileContains(String expected) { String onDisk = GFileUtils.readFile(lockFile); if (!onDisk.equals(expected)) { - throw new GradleException(lockFile - + " is out of date, please run `./gradlew " - + "checkClassUniqueness --write-locks` to update this file"); + List onDiskLines = Splitter.on('\n').splitToList(onDisk); + Patch diff = DiffUtils.diff(onDiskLines, Splitter.on('\n').splitToList(expected)); + + throw new GradleException(String.join( + "\n", + String.format( + "%s is out of date, please run `./gradlew checkClassUniqueness --write-locks` " + + "to update this file. The diff is:", + lockFile), + "", + String.join( + "\n", + DiffUtils.generateUnifiedDiff("on disk", "expected", onDiskLines, diff, Integer.MAX_VALUE)), + "", + "On disk was:", + "", + onDisk, + "", + "Expected was:", + expected)); } } diff --git a/versions.lock b/versions.lock index 1da890134..8dde24a57 100644 --- a/versions.lock +++ b/versions.lock @@ -35,7 +35,7 @@ com.google.protobuf:protobuf-java:3.4.0 (1 constraints: f4102eb8) com.google.testing.compile:compile-testing:0.18 (1 constraints: 3114b84c) com.google.truth:truth:0.45 (2 constraints: 1d266427) com.googlecode.concurrent-trees:concurrent-trees:2.6.1 (1 constraints: 761166da) -com.googlecode.java-diff-utils:diffutils:1.3.0 (2 constraints: 3a1dc41d) +com.googlecode.java-diff-utils:diffutils:1.3.0 (3 constraints: 3f226bf4) com.googlecode.javaewah:JavaEWAH:1.1.7 (1 constraints: 490e7f50) com.jcraft:jsch:0.1.55 (1 constraints: 7b0ef35e) com.jcraft:jzlib:1.1.1 (1 constraints: 430e7950) diff --git a/versions.props b/versions.props index 52e2f27fd..09482b889 100644 --- a/versions.props +++ b/versions.props @@ -13,6 +13,7 @@ org.jooq:jooq = 3.13.2 org.slf4j:slf4j-api = 1.7.30 org.immutables:* = 2.8.8 org.ow2.asm:asm = 8.0.1 +com.googlecode.java-diff-utils:diffutils = 1.3.0 # test deps com.fasterxml.jackson.*:* = 2.11.1 From b3dca601af80713fd72cfccf72321cc91f604712 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Thu, 9 Jul 2020 10:22:18 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-1452.v2.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/@unreleased/pr-1452.v2.yml diff --git a/changelog/@unreleased/pr-1452.v2.yml b/changelog/@unreleased/pr-1452.v2.yml new file mode 100644 index 000000000..00c671f61 --- /dev/null +++ b/changelog/@unreleased/pr-1452.v2.yml @@ -0,0 +1,6 @@ +type: fix +fix: + description: When `checkClassUniqueness` fails, it will show the difference between + the actual and expected lock file. + links: + - https://github.com/palantir/gradle-baseline/pull/1452