Skip to content

Commit cfc8291

Browse files
committed
Make the diff a little smaller.
1 parent ee5aaf8 commit cfc8291

File tree

3 files changed

+44
-75
lines changed

3 files changed

+44
-75
lines changed

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,26 @@
4444
* apply already did).
4545
*/
4646
public abstract class SpotlessTaskService implements BuildService<BuildServiceParameters.None>, AutoCloseable, OperationCompletionListener {
47-
private Map<String, SpotlessApply> apply = Collections.synchronizedMap(new HashMap<>());
48-
private Map<String, SpotlessTask> source = Collections.synchronizedMap(new HashMap<>());
49-
private Map<String, Provisioner> provisioner = Collections.synchronizedMap(new HashMap<>());
50-
51-
void registerSourceAlreadyRan(SpotlessTask task) {
52-
source.put(task.getPath(), task);
53-
}
47+
private final Map<String, SpotlessApply> apply = Collections.synchronizedMap(new HashMap<>());
48+
private final Map<String, SpotlessTask> source = Collections.synchronizedMap(new HashMap<>());
49+
private final Map<String, Provisioner> provisioner = Collections.synchronizedMap(new HashMap<>());
5450

5551
Provisioner provisionerFor(Project project) {
5652
return provisioner.computeIfAbsent(project.getPath(), unused -> {
5753
return GradleProvisioner.newDedupingProvisioner(project);
5854
});
5955
}
6056

57+
void registerSourceAlreadyRan(SpotlessTask task) {
58+
source.put(task.getPath(), task);
59+
}
60+
6161
void registerApplyAlreadyRan(SpotlessApply task) {
6262
apply.put(task.sourceTaskPath(), task);
6363
}
6464

65-
/////////////////
6665
// <GitRatchet>
67-
private GitRatchetGradle ratchet = new GitRatchetGradle();
66+
private final GitRatchetGradle ratchet = new GitRatchetGradle();
6867

6968
GitRatchetGradle getRatchet() {
7069
return ratchet;
@@ -80,7 +79,6 @@ public void close() throws Exception {
8079
ratchet.close();
8180
}
8281
// </GitRatchet>
83-
//////////////////
8482

8583
static String INDEPENDENT_HELPER = "Helper";
8684

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheJvmLocalTest.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.IOException;
1919

20+
import org.gradle.testkit.runner.BuildResult;
2021
import org.gradle.testkit.runner.GradleRunner;
2122
import org.junit.jupiter.api.Test;
2223

@@ -59,4 +60,39 @@ public void helpConfiguresIfTasksAreCreated() throws IOException {
5960
"tasks.named('spotlessJavaApply').get()");
6061
gradleRunner().withArguments("help").build();
6162
}
63+
64+
@Test
65+
public void jvmLocalCache() throws IOException {
66+
setFile("build.gradle").toLines(
67+
"plugins {",
68+
" id 'com.diffplug.spotless'",
69+
"}",
70+
"repositories { mavenCentral() }",
71+
"spotless {",
72+
" java {",
73+
" target file('test.java')",
74+
" googleJavaFormat('1.2')",
75+
" }",
76+
"}");
77+
78+
// first run works
79+
setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
80+
gradleRunner().withArguments("spotlessApply").build();
81+
assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
82+
83+
// and it keeps working!
84+
gradleRunner().withArguments("spotlessApply", "--stacktrace").build();
85+
gradleRunner().withArguments("spotlessApply").build();
86+
gradleRunner().withArguments("spotlessApply").build();
87+
88+
setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
89+
gradleRunner().withArguments("spotlessCheck").buildAndFail();
90+
gradleRunner().withArguments("spotlessApply").build();
91+
assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
92+
93+
BuildResult failure = gradleRunner().withDebug(true).withArguments("spotlessApply", "--stacktrace").buildAndFail();
94+
failure.getOutput().contains("Spotless daemon-local cache is stale. Regenerate the cache with\n" +
95+
" rm -rf .gradle/configuration-cache\n" +
96+
"For more information see #123\n");
97+
}
6298
}

0 commit comments

Comments
 (0)