Skip to content

Commit

Permalink
Some refinements on top of PR #720 (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Sep 17, 2021
2 parents 2a43453 + e13f97a commit dd1dd60
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ protected void setupTask(SpotlessTask task) {
spotless.getRegisterDependenciesTask().hookSubprojectTask(task);
}
if (getRatchetFrom() != null) {
task.setupRatchet(spotless.getRegisterDependenciesTask().gitRatchet, getRatchetFrom());
task.setupRatchet(spotless.getRegisterDependenciesTask().getGitRatchet().get(), getRatchetFrom());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import org.gradle.api.Project;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceParameters;
import org.gradle.tooling.events.FinishEvent;
import org.gradle.tooling.events.OperationCompletionListener;

import com.diffplug.spotless.extra.GitRatchet;

/** Gradle implementation of GitRatchet. */
public abstract class GitRatchetGradle extends GitRatchet<Project> implements BuildService<BuildServiceParameters.None> {
public abstract class GitRatchetGradle extends GitRatchet<Project> implements BuildService<BuildServiceParameters.None>, OperationCompletionListener {
@Override
protected File getDir(Project project) {
return project.getProjectDir();
Expand All @@ -36,4 +38,9 @@ protected File getDir(Project project) {
protected @Nullable Project getParent(Project project) {
return project.getParent();
}

@Override
public void onFinish(FinishEvent finishEvent) {
// NOOP
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.gradle.api.DefaultTask;
import org.gradle.api.execution.TaskExecutionGraph;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.build.event.BuildEventsListenerRegistry;

import com.diffplug.common.base.Preconditions;
import com.diffplug.common.io.Files;
Expand All @@ -42,7 +47,7 @@
* - When this "registerDependencies" task does its up-to-date check, it queries the task execution graph to see which
* SpotlessTasks are at risk of being executed, and causes them all to be evaluated safely in the root buildscript.
*/
public class RegisterDependenciesTask extends DefaultTask {
public abstract class RegisterDependenciesTask extends DefaultTask {
static final String TASK_NAME = "spotlessInternalRegisterDependencies";

@Input
Expand Down Expand Up @@ -86,7 +91,9 @@ 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());
gitRatchet = getProject().getGradle().getSharedServices().registerIfAbsent("GitRatchetGradle", GitRatchetGradle.class, unused -> {}).get();
Provider<GitRatchetGradle> gitRatchetProvider = getProject().getGradle().getSharedServices().registerIfAbsent("GitRatchetGradle", GitRatchetGradle.class, unused -> {});
getBuildEventsListenerRegistry().onTaskCompletion(gitRatchetProvider);
getGitRatchet().set(gitRatchetProvider);
}

@TaskAction
Expand All @@ -95,10 +102,9 @@ public void trivialFunction() throws IOException {
Files.write(Integer.toString(getSteps().size()), unitOutput, StandardCharsets.UTF_8);
}

GitRatchetGradle gitRatchet;

@Internal
GitRatchetGradle getGitRatchet() {
return gitRatchet;
}
public abstract Property<GitRatchetGradle> getGitRatchet();

@Inject
protected abstract BuildEventsListenerRegistry getBuildEventsListenerRegistry();
}

0 comments on commit dd1dd60

Please sign in to comment.