Skip to content

Commit

Permalink
Convert GitRatchetGradle into a BuildService, just to get around `bui…
Browse files Browse the repository at this point in the history
…ldFinished`, so that Spotless tasks don't interfere with config cache for other tasks.
  • Loading branch information
nedtwigg committed Oct 16, 2020
1 parent 02ec8ee commit fa01f46
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import javax.annotation.Nullable;

import org.gradle.api.Project;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceParameters;

import com.diffplug.spotless.extra.GitRatchet;

/** Gradle implementation of GitRatchet. */
final class GitRatchetGradle extends GitRatchet<Project> {
public abstract class GitRatchetGradle extends GitRatchet<Project> implements BuildService<BuildServiceParameters.None> {
@Override
protected File getDir(Project project) {
return project.getProjectDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
import com.diffplug.common.io.Files;
import com.diffplug.spotless.FormatterStep;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import groovy.lang.Closure;

/**
* NOT AN END-USER TASK, DO NOT USE FOR ANYTHING!
*
Expand Down Expand Up @@ -86,18 +83,11 @@ public GradleProvisioner.RootProvisioner getRootProvisioner() {
return rootProvisioner;
}

@SuppressWarnings({"rawtypes", "serial"})
void setup() {
Preconditions.checkArgument(getProject().getRootProject() == getProject(), "Can only be used on the root project");
unitOutput = new File(getProject().getBuildDir(), "tmp/spotless-register-dependencies");
rootProvisioner = new GradleProvisioner.RootProvisioner(getProject());
getProject().getGradle().buildFinished(new Closure(null) {
@SuppressFBWarnings("UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS")
public Object doCall() {
gitRatchet.close();
return null;
}
});
gitRatchet = getProject().getGradle().getSharedServices().registerIfAbsent("GitRatchetGradle", GitRatchetGradle.class, unused -> {}).get();
}

@TaskAction
Expand All @@ -106,7 +96,7 @@ public void trivialFunction() throws IOException {
Files.write(Integer.toString(getSteps().size()), unitOutput, StandardCharsets.UTF_8);
}

GitRatchetGradle gitRatchet = new GitRatchetGradle();
GitRatchetGradle gitRatchet;

@Internal
GitRatchetGradle getGitRatchet() {
Expand Down

0 comments on commit fa01f46

Please sign in to comment.