Skip to content

Commit 99cf509

Browse files
committed
Fix CheckTask's up-to-date behaviour
Previously, CheckTask instances would never be up-to-date as the task had an action but did not declare any outputs. As the task does not produce any output, this commit fixes its up-to-date checks by marking its outputs as always being up-to-date. Closes gh-116
1 parent 03877f7 commit 99cf509

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/main/java/io/spring/javaformat/gradle/CheckTask.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public class CheckTask extends FormatterTask {
4343
*/
4444
public static final String DESCRIPTION = "Run Spring Java formatting checks";
4545

46+
public CheckTask() {
47+
getOutputs().upToDateWhen((task) -> true);
48+
}
49+
4650
@TaskAction
4751
public void checkFormatting() throws IOException, InterruptedException {
4852
List<File> problems = formatFiles().filter(FileEdit::hasEdits).map(FileEdit::getFile)

spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/test/java/io/spring/javaformat/gradle/CheckTaskTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,28 @@ public void checkOk() throws IOException {
4343
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
4444
}
4545

46+
@Test
47+
public void whenFirstInvocationSucceedsThenSecondInvocationIsUpToDate() throws IOException {
48+
GradleBuild gradleBuild = this.gradleBuild.source("src/test/resources/check-ok");
49+
BuildResult result = gradleBuild.build("check");
50+
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
51+
result = gradleBuild.build("check");
52+
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
53+
}
54+
4655
@Test
4756
public void checkBad() throws IOException {
4857
BuildResult result = this.gradleBuild.source("src/test/resources/check-bad").buildAndFail("check");
4958
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.FAILED);
5059
}
5160

61+
@Test
62+
public void whenFirstInvocationFailsThenSecondInvocationFails() throws IOException {
63+
GradleBuild gradleBuild = this.gradleBuild.source("src/test/resources/check-bad");
64+
BuildResult result = gradleBuild.buildAndFail("check");
65+
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.FAILED);
66+
result = gradleBuild.buildAndFail("check");
67+
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.FAILED);
68+
}
69+
5270
}

spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/test/java/io/spring/javaformat/gradle/testkit/GradleBuild.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ private void copyFolder(Path source, Path target) throws IOException {
154154
try {
155155
Path relative = source.relativize(child);
156156
Path destination = target.resolve(relative);
157-
Files.copy(child, destination, StandardCopyOption.REPLACE_EXISTING);
157+
if (!destination.toFile().isDirectory()) {
158+
Files.copy(child, destination, StandardCopyOption.REPLACE_EXISTING);
159+
}
158160
}
159161
catch (Exception ex) {
160162
throw new IllegalStateException(ex);

0 commit comments

Comments
 (0)