Skip to content

Commit

Permalink
clean now runs after all SpotlessTask. Fixes #159.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Oct 31, 2017
1 parent fcd01e5 commit 9707b1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Version 3.7.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-plugin-gradle/))

* Updated default eclipse-jdt version to `4.7.1` from `4.6.3`.
* All spotless tasks now run before the `clean` task. ([#159](https://github.com/diffplug/spotless/issues/159))

### Version 3.6.0 - September 29th 2017 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.6.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.6.0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.execution.TaskExecutionGraph;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.JavaBasePlugin;

import com.diffplug.common.base.Errors;
import com.diffplug.spotless.SpotlessCache;

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

public class SpotlessPlugin implements Plugin<Project> {
Project project;
SpotlessExtension spotlessExtension;

static final String EXTENSION = "spotless";
Expand All @@ -41,13 +40,14 @@ public class SpotlessPlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
this.project = project;
// make sure there's a `clean` task
project.getPlugins().apply(BasePlugin.class);

// setup the extension
spotlessExtension = project.getExtensions().create(EXTENSION, SpotlessExtension.class, project);

// after the project has been evaluated, configure the check and format tasks per source set
project.afterEvaluate(unused -> Errors.rethrow().run(this::createTasks));
project.afterEvaluate(this::createTasks);
}

/** The extension for this plugin. */
Expand All @@ -56,7 +56,7 @@ public SpotlessExtension getExtension() {
}

@SuppressWarnings("rawtypes")
void createTasks() throws Exception {
void createTasks(Project project) {
Task rootCheckTask = project.task(EXTENSION + CHECK);
rootCheckTask.setGroup(TASK_GROUP);
rootCheckTask.setDescription(CHECK_DESCRIPTION);
Expand Down Expand Up @@ -107,10 +107,12 @@ public Object doCall(TaskExecutionGraph graph) {
.all(task -> task.dependsOn(rootCheckTask));
}

// clear spotless' cache when the user does a clean
// clear spotless' cache when the user does a clean, but only after any spotless tasks
Task clean = project.getTasks().getByName(BasePlugin.CLEAN_TASK_NAME);
clean.doLast(unused -> SpotlessCache.clear());
project.getTasks()
.matching(task -> task.getName().equals("clean"))
.all(task -> task.doLast(unused -> SpotlessCache.clear()));
.matching(task -> task instanceof SpotlessTask)
.all(task -> clean.mustRunAfter(task));
}

static String capitalize(String input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static Project createProject(Consumer<SpotlessExtension> test) throws Ex
SpotlessPlugin plugin = project.getPlugins().apply(SpotlessPlugin.class);
// setup the plugin
test.accept(plugin.getExtension());
plugin.createTasks();
plugin.createTasks(project);
// return the configured plugin
return project;
}
Expand Down

0 comments on commit 9707b1c

Please sign in to comment.