Skip to content

Commit

Permalink
Makes check enforcement configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
gdecaso authored and nedtwigg committed Apr 3, 2017
1 parent 0b20cd0 commit a8ab1c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ public void removeFormat(String name) {
}
}

boolean enforceCheck = true;

/** Returns `true` if Gradle's `check` task should run `spotlessCheck`; `false` otherwise. */
public boolean isEnforceCheck() {
return enforceCheck;
}

/**
* Configures Gradle's `check` task to run `spotlessCheck` if `true`,
* but to not do so if `false`.
*
* `true` by default.
*/
public void setEnforceCheck(boolean enforceCheck) {
this.enforceCheck = enforceCheck;
}

private <T extends FormatExtension> void configure(String name, Class<T> clazz, Action<T> configure) {
T value = maybeCreate(name, clazz);
configure.execute(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ public Object doCall(TaskExecutionGraph graph) {
// Add our check task as a dependency on the global check task
// getTasks() returns a "live" collection, so this works even if the
// task doesn't exist at the time this call is made
project.getTasks()
.matching(task -> task.getName().equals(JavaBasePlugin.CHECK_TASK_NAME))
.all(task -> task.dependsOn(rootCheckTask));
if (spotlessExtension.enforceCheck) {
project.getTasks()
.matching(task -> task.getName().equals(JavaBasePlugin.CHECK_TASK_NAME))
.all(task -> task.dependsOn(rootCheckTask));
}

// clear spotless' cache when the user does a clean
project.getTasks()
Expand Down

0 comments on commit a8ab1c1

Please sign in to comment.