Skip to content

Support configuration cache within a single daemon (JvmLocalCache) #986

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

Merged
merged 15 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make the diff a little smaller.
  • Loading branch information
nedtwigg committed Nov 9, 2021
commit cfc82911b2e0961ee0927d92ab1ca5f519628b75
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,26 @@
* apply already did).
*/
public abstract class SpotlessTaskService implements BuildService<BuildServiceParameters.None>, AutoCloseable, OperationCompletionListener {
private Map<String, SpotlessApply> apply = Collections.synchronizedMap(new HashMap<>());
private Map<String, SpotlessTask> source = Collections.synchronizedMap(new HashMap<>());
private Map<String, Provisioner> provisioner = Collections.synchronizedMap(new HashMap<>());

void registerSourceAlreadyRan(SpotlessTask task) {
source.put(task.getPath(), task);
}
private final Map<String, SpotlessApply> apply = Collections.synchronizedMap(new HashMap<>());
private final Map<String, SpotlessTask> source = Collections.synchronizedMap(new HashMap<>());
private final Map<String, Provisioner> provisioner = Collections.synchronizedMap(new HashMap<>());

Provisioner provisionerFor(Project project) {
return provisioner.computeIfAbsent(project.getPath(), unused -> {
return GradleProvisioner.newDedupingProvisioner(project);
});
}

void registerSourceAlreadyRan(SpotlessTask task) {
source.put(task.getPath(), task);
}

void registerApplyAlreadyRan(SpotlessApply task) {
apply.put(task.sourceTaskPath(), task);
}

/////////////////
// <GitRatchet>
private GitRatchetGradle ratchet = new GitRatchetGradle();
private final GitRatchetGradle ratchet = new GitRatchetGradle();

GitRatchetGradle getRatchet() {
return ratchet;
Expand All @@ -80,7 +79,6 @@ public void close() throws Exception {
ratchet.close();
}
// </GitRatchet>
//////////////////

static String INDEPENDENT_HELPER = "Helper";

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;

import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -59,4 +60,39 @@ public void helpConfiguresIfTasksAreCreated() throws IOException {
"tasks.named('spotlessJavaApply').get()");
gradleRunner().withArguments("help").build();
}

@Test
public void jvmLocalCache() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'com.diffplug.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless {",
" java {",
" target file('test.java')",
" googleJavaFormat('1.2')",
" }",
"}");

// first run works
setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");

// and it keeps working!
gradleRunner().withArguments("spotlessApply", "--stacktrace").build();
gradleRunner().withArguments("spotlessApply").build();
gradleRunner().withArguments("spotlessApply").build();

setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
gradleRunner().withArguments("spotlessCheck").buildAndFail();
gradleRunner().withArguments("spotlessApply").build();
assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");

BuildResult failure = gradleRunner().withDebug(true).withArguments("spotlessApply", "--stacktrace").buildAndFail();
failure.getOutput().contains("Spotless daemon-local cache is stale. Regenerate the cache with\n" +
" rm -rf .gradle/configuration-cache\n" +
"For more information see #123\n");
}
}