Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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()));
.withType(SpotlessTask.class)
.all(task -> task.mustRunAfter(clean));
}

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