Skip to content

Commit 99cec0c

Browse files
committed
Rename and relocate Gradle task classes
Use idiomatic naming for the 'format' and 'checkFormat' tasks. Closes gh-271
1 parent ddbaea9 commit 99cec0c

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,10 @@
2525
import org.gradle.api.plugins.JavaPluginConvention;
2626
import org.gradle.api.tasks.SourceSet;
2727

28+
import io.spring.javaformat.gradle.tasks.CheckFormat;
29+
import io.spring.javaformat.gradle.tasks.Format;
30+
import io.spring.javaformat.gradle.tasks.FormatterTask;
31+
2832
/**
2933
* Spring Format Gradle Plugin.
3034
*
@@ -42,28 +46,28 @@ public void apply(Project project) {
4246

4347
private void addSourceTasks() {
4448
this.project.getPlugins().withType(JavaBasePlugin.class, (plugin) -> {
45-
Task formatAll = this.project.task(FormatTask.NAME);
46-
formatAll.setDescription(FormatTask.DESCRIPTION);
47-
Task checkAll = this.project.task(CheckTask.NAME);
48-
checkAll.setDescription(CheckTask.DESCRIPTION);
49+
Task formatAll = this.project.task(Format.NAME);
50+
formatAll.setDescription(Format.DESCRIPTION);
51+
Task checkAll = this.project.task(CheckFormat.NAME);
52+
checkAll.setDescription(CheckFormat.DESCRIPTION);
4953
this.project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(checkAll);
5054
this.project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets()
5155
.all((sourceSet) -> addSourceTasks(sourceSet, checkAll, formatAll));
5256
});
5357
}
5458

5559
private void addSourceTasks(SourceSet sourceSet, Task checkAll, Task formatAll) {
56-
CheckTask checkTask = addSourceTask(sourceSet, CheckTask.class, CheckTask.NAME, CheckTask.DESCRIPTION);
60+
CheckFormat checkTask = addFormatterTask(sourceSet, CheckFormat.class, CheckFormat.NAME,
61+
CheckFormat.DESCRIPTION);
5762
checkTask.setReportLocation(
5863
new File(this.project.getBuildDir(), "reports/format/" + sourceSet.getName() + "/check-format.txt"));
5964
checkAll.dependsOn(checkTask);
60-
FormatTask formatSourceSet = addSourceTask(sourceSet, FormatTask.class, FormatTask.NAME,
61-
FormatTask.DESCRIPTION);
65+
Format formatSourceSet = addFormatterTask(sourceSet, Format.class, Format.NAME, Format.DESCRIPTION);
6266
formatSourceSet.conventionMapping("encoding", () -> "UTF-8");
6367
formatAll.dependsOn(formatSourceSet);
6468
}
6569

66-
private <T extends FormatterTask> T addSourceTask(SourceSet sourceSet, Class<T> taskType, String name,
70+
private <T extends FormatterTask> T addFormatterTask(SourceSet sourceSet, Class<T> taskType, String name,
6771
String desc) {
6872
String taskName = sourceSet.getTaskName(name, null);
6973
T task = this.project.getTasks().create(taskName, taskType);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.spring.javaformat.gradle;
17+
package io.spring.javaformat.gradle.tasks;
1818

1919
import java.io.File;
2020
import java.io.IOException;
@@ -40,7 +40,7 @@
4040
* @author Phillip Webb
4141
*/
4242
@CacheableTask
43-
public class CheckTask extends FormatterTask {
43+
public class CheckFormat extends FormatterTask {
4444

4545
/**
4646
* The name of the task.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.spring.javaformat.gradle;
17+
package io.spring.javaformat.gradle.tasks;
1818

1919
import java.io.IOException;
2020

@@ -29,7 +29,7 @@
2929
*
3030
* @author Phillip Webb
3131
*/
32-
public class FormatTask extends FormatterTask {
32+
public class Format extends FormatterTask {
3333

3434
/**
3535
* The name of the task.
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.spring.javaformat.gradle;
17+
package io.spring.javaformat.gradle.tasks;
1818

1919
import java.nio.charset.Charset;
2020
import java.util.stream.Stream;
@@ -32,10 +32,13 @@
3232
*
3333
* @author Phillip Webb
3434
*/
35-
abstract class FormatterTask extends SourceTask {
35+
public abstract class FormatterTask extends SourceTask {
3636

3737
private String encoding;
3838

39+
FormatterTask() {
40+
}
41+
3942
/**
4043
* Get the file encoding in use.
4144
* @return the encoding the file encoding

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
import org.junit.jupiter.api.extension.ExtendWith;
3232
import org.junit.jupiter.api.io.TempDir;
3333

34+
import io.spring.javaformat.gradle.tasks.CheckFormat;
3435
import io.spring.javaformat.gradle.testkit.GradleBuild;
3536
import io.spring.javaformat.gradle.testkit.GradleBuildExtension;
3637

3738
import static org.assertj.core.api.Assertions.assertThat;
3839

3940
/**
40-
* Tests for {@link CheckTask}.
41+
* Tests for {@link CheckFormat}.
4142
*
4243
* @author Phillip Webb
4344
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
import org.junit.jupiter.api.Test;
2626
import org.junit.jupiter.api.extension.ExtendWith;
2727

28+
import io.spring.javaformat.gradle.tasks.Format;
2829
import io.spring.javaformat.gradle.testkit.GradleBuild;
2930
import io.spring.javaformat.gradle.testkit.GradleBuildExtension;
3031

3132
import static org.assertj.core.api.Assertions.assertThat;
3233

3334
/**
34-
* Tests for {@link FormatTask}.
35+
* Tests for {@link Format}.
3536
*
3637
* @author Phillip Webb
3738
*/

0 commit comments

Comments
 (0)