Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message on class uniqueness lock file failure #1452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-1452.v2.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions gradle-baseline-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> onDiskLines = Splitter.on('\n').splitToList(onDisk);
Patch<String> 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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down