Skip to content

Commit abb3901

Browse files
author
Vincent Potucek
committed
Apply unused io.spring.javaformat plugin
Signed-off-by: Vincent Potucek <[email protected]>
1 parent 12146c4 commit abb3901

21 files changed

+219
-194
lines changed

buildSrc/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
plugins {
22
id 'java-gradle-plugin'
33
id 'checkstyle'
4+
id 'io.spring.javaformat' version "${javaFormatVersion}"
45
}
56

67
repositories {
78
mavenCentral()
89
gradlePluginPortal()
910
}
1011

12+
tasks.named('compileJava') {
13+
dependsOn 'format'
14+
mustRunAfter 'format'
15+
}
16+
1117
ext {
1218
def propertiesFile = new File(new File("$projectDir").parentFile, "gradle.properties")
1319
propertiesFile.withInputStream {
@@ -64,4 +70,4 @@ test {
6470
useJUnitPlatform()
6571
}
6672

67-
jar.dependsOn check
73+
jar.dependsOn check

buildSrc/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
org.gradle.caching=true
22
assertjVersion=3.27.3
3-
javaFormatVersion=0.0.43
3+
javaFormatVersion=0.0.47
44
junitVersion=5.12.2

buildSrc/src/main/java/org/springframework/build/CheckstyleConventions.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,21 @@ public void apply(Project project) {
5353
checkstyle.setToolVersion("10.25.0");
5454
checkstyle.getConfigDirectory().set(project.getRootProject().file("src/checkstyle"));
5555
String version = SpringJavaFormatPlugin.class.getPackage().getImplementationVersion();
56-
DependencySet checkstyleDependencies = project.getConfigurations().getByName("checkstyle").getDependencies();
57-
checkstyleDependencies.add(
58-
project.getDependencies().create("io.spring.javaformat:spring-javaformat-checkstyle:" + version));
56+
DependencySet checkstyleDependencies = project.getConfigurations()
57+
.getByName("checkstyle")
58+
.getDependencies();
59+
checkstyleDependencies
60+
.add(project.getDependencies().create("io.spring.javaformat:spring-javaformat-checkstyle:" + version));
5961
});
6062
}
6163

6264
private static void configureNoHttpPlugin(Project project) {
6365
project.getPlugins().apply(NoHttpPlugin.class);
6466
NoHttpExtension noHttp = project.getExtensions().getByType(NoHttpExtension.class);
6567
noHttp.setAllowlistFile(project.file("src/nohttp/allowlist.lines"));
66-
noHttp.getSource().exclude("**/test-output/**", "**/.settings/**", "**/.classpath",
67-
"**/.project", "**/.gradle/**", "**/node_modules/**", "**/spring-jcl/**", "buildSrc/build/**");
68+
noHttp.getSource()
69+
.exclude("**/test-output/**", "**/.settings/**", "**/.classpath", "**/.project", "**/.gradle/**",
70+
"**/node_modules/**", "**/spring-jcl/**", "buildSrc/build/**");
6871
List<String> buildFolders = List.of("bin", "build", "out");
6972
project.allprojects(subproject -> {
7073
Path rootPath = project.getRootDir().toPath();

buildSrc/src/main/java/org/springframework/build/ConventionsPlugin.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
* Plugin to apply conventions to projects that are part of Spring Framework's build.
2828
* Conventions are applied in response to various plugins being applied.
2929
*
30-
* <p>When the {@link JavaBasePlugin} is applied, the conventions in {@link CheckstyleConventions},
31-
* {@link TestConventions} and {@link JavaConventions} are applied.
32-
* The {@link ArchitecturePlugin} plugin is also applied.
33-
* When the {@link KotlinBasePlugin} is applied, the conventions in {@link KotlinConventions}
34-
* are applied.
30+
* <p>
31+
* When the {@link JavaBasePlugin} is applied, the conventions in
32+
* {@link CheckstyleConventions}, {@link TestConventions} and {@link JavaConventions} are
33+
* applied. The {@link ArchitecturePlugin} plugin is also applied. When the
34+
* {@link KotlinBasePlugin} is applied, the conventions in {@link KotlinConventions} are
35+
* applied.
3536
*
3637
* @author Brian Clozel
3738
*/

buildSrc/src/main/java/org/springframework/build/JavaConventions.java

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,26 @@ public class JavaConventions {
4242

4343
/**
4444
* The Java version we should use as the JVM baseline for building the project.
45-
* <p>NOTE: If you update this value, you should also update the value used in
46-
* the {@code javadoc} task in {@code framework-api.gradle}.
45+
* <p>
46+
* NOTE: If you update this value, you should also update the value used in the
47+
* {@code javadoc} task in {@code framework-api.gradle}.
4748
*/
4849
private static final JavaLanguageVersion DEFAULT_LANGUAGE_VERSION = JavaLanguageVersion.of(24);
4950

5051
/**
51-
* The Java version we should use as the baseline for the compiled bytecode
52-
* (the "-release" compiler argument).
52+
* The Java version we should use as the baseline for the compiled bytecode (the
53+
* "-release" compiler argument).
5354
*/
5455
private static final JavaLanguageVersion DEFAULT_RELEASE_VERSION = JavaLanguageVersion.of(17);
5556

5657
static {
57-
List<String> commonCompilerArgs = List.of(
58-
"-Xlint:serial", "-Xlint:cast", "-Xlint:classfile", "-Xlint:dep-ann",
59-
"-Xlint:divzero", "-Xlint:empty", "-Xlint:finally", "-Xlint:overrides",
60-
"-Xlint:path", "-Xlint:processing", "-Xlint:static", "-Xlint:try", "-Xlint:-options",
61-
"-parameters"
62-
);
58+
List<String> commonCompilerArgs = List.of("-Xlint:serial", "-Xlint:cast", "-Xlint:classfile", "-Xlint:dep-ann",
59+
"-Xlint:divzero", "-Xlint:empty", "-Xlint:finally", "-Xlint:overrides", "-Xlint:path",
60+
"-Xlint:processing", "-Xlint:static", "-Xlint:try", "-Xlint:-options", "-parameters");
6361
COMPILER_ARGS = new ArrayList<>();
6462
COMPILER_ARGS.addAll(commonCompilerArgs);
65-
COMPILER_ARGS.addAll(List.of(
66-
"-Xlint:varargs", "-Xlint:fallthrough", "-Xlint:rawtypes", "-Xlint:deprecation",
67-
"-Xlint:unchecked", "-Werror"
68-
));
63+
COMPILER_ARGS.addAll(List.of("-Xlint:varargs", "-Xlint:fallthrough", "-Xlint:rawtypes", "-Xlint:deprecation",
64+
"-Xlint:unchecked", "-Werror"));
6965
TEST_COMPILER_ARGS = new ArrayList<>();
7066
TEST_COMPILER_ARGS.addAll(commonCompilerArgs);
7167
TEST_COMPILER_ARGS.addAll(List.of("-Xlint:-varargs", "-Xlint:-fallthrough", "-Xlint:-rawtypes",
@@ -96,21 +92,23 @@ private static void applyToolchainConventions(Project project) {
9692
*/
9793
private void applyJavaCompileConventions(Project project) {
9894
project.afterEvaluate(p -> {
99-
p.getTasks().withType(JavaCompile.class)
100-
.matching(compileTask -> compileTask.getName().startsWith(JavaPlugin.COMPILE_JAVA_TASK_NAME))
101-
.forEach(compileTask -> {
102-
compileTask.getOptions().setCompilerArgs(COMPILER_ARGS);
103-
compileTask.getOptions().setEncoding("UTF-8");
104-
setJavaRelease(compileTask);
105-
});
106-
p.getTasks().withType(JavaCompile.class)
107-
.matching(compileTask -> compileTask.getName().startsWith(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME)
108-
|| compileTask.getName().equals("compileTestFixturesJava"))
109-
.forEach(compileTask -> {
110-
compileTask.getOptions().setCompilerArgs(TEST_COMPILER_ARGS);
111-
compileTask.getOptions().setEncoding("UTF-8");
112-
setJavaRelease(compileTask);
113-
});
95+
p.getTasks()
96+
.withType(JavaCompile.class)
97+
.matching(compileTask -> compileTask.getName().startsWith(JavaPlugin.COMPILE_JAVA_TASK_NAME))
98+
.forEach(compileTask -> {
99+
compileTask.getOptions().setCompilerArgs(COMPILER_ARGS);
100+
compileTask.getOptions().setEncoding("UTF-8");
101+
setJavaRelease(compileTask);
102+
});
103+
p.getTasks()
104+
.withType(JavaCompile.class)
105+
.matching(compileTask -> compileTask.getName().startsWith(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME)
106+
|| compileTask.getName().equals("compileTestFixturesJava"))
107+
.forEach(compileTask -> {
108+
compileTask.getOptions().setCompilerArgs(TEST_COMPILER_ARGS);
109+
compileTask.getOptions().setEncoding("UTF-8");
110+
setJavaRelease(compileTask);
111+
});
114112

115113
});
116114
}
@@ -123,7 +121,7 @@ private void setJavaRelease(JavaCompile task) {
123121
int defaultVersion = DEFAULT_RELEASE_VERSION.asInt();
124122
int releaseVersion = defaultVersion;
125123
int compilerVersion = task.getJavaCompiler().get().getMetadata().getLanguageVersion().asInt();
126-
for (int version = defaultVersion ; version <= compilerVersion ; version++) {
124+
for (int version = defaultVersion; version <= compilerVersion; version++) {
127125
if (task.getName().contains("Java" + version)) {
128126
releaseVersion = version;
129127
break;

buildSrc/src/main/java/org/springframework/build/KotlinConventions.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
public class KotlinConventions {
2929

3030
void apply(Project project) {
31-
project.getPlugins().withId("org.jetbrains.kotlin.jvm",
32-
(plugin) -> project.getTasks().withType(KotlinCompile.class, this::configure));
31+
project.getPlugins()
32+
.withId("org.jetbrains.kotlin.jvm",
33+
(plugin) -> project.getTasks().withType(KotlinCompile.class, this::configure));
3334
}
3435

3536
private void configure(KotlinCompile compile) {
@@ -39,11 +40,14 @@ private void configure(KotlinCompile compile) {
3940
options.getJvmTarget().set(JvmTarget.JVM_17);
4041
options.getJavaParameters().set(true);
4142
options.getAllWarningsAsErrors().set(true);
42-
options.getFreeCompilerArgs().addAll(
43-
"-Xsuppress-version-warnings",
44-
"-Xjsr305=strict", // For dependencies using JSR 305
45-
"-opt-in=kotlin.RequiresOptIn",
46-
"-Xjdk-release=17" // Needed due to https://youtrack.jetbrains.com/issue/KT-49746
43+
options.getFreeCompilerArgs()
44+
.addAll("-Xsuppress-version-warnings", "-Xjsr305=strict", // For
45+
// dependencies
46+
// using JSR
47+
// 305
48+
"-opt-in=kotlin.RequiresOptIn", "-Xjdk-release=17" // Needed due
49+
// to
50+
// https://youtrack.jetbrains.com/issue/KT-49746
4751
);
4852
});
4953
}

buildSrc/src/main/java/org/springframework/build/SpringFrameworkExtension.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ public class SpringFrameworkExtension {
3131

3232
public SpringFrameworkExtension(Project project) {
3333
this.enableJavaPreviewFeatures = project.getObjects().property(Boolean.class);
34-
project.getTasks().withType(JavaCompile.class).configureEach(javaCompile ->
35-
javaCompile.getOptions().getCompilerArgumentProviders().add(asArgumentProvider()));
36-
project.getTasks().withType(Test.class).configureEach(test ->
37-
test.getJvmArgumentProviders().add(asArgumentProvider()));
34+
project.getTasks()
35+
.withType(JavaCompile.class)
36+
.configureEach(
37+
javaCompile -> javaCompile.getOptions().getCompilerArgumentProviders().add(asArgumentProvider()));
38+
project.getTasks()
39+
.withType(Test.class)
40+
.configureEach(test -> test.getJvmArgumentProviders().add(asArgumentProvider()));
3841

3942
}
4043

@@ -50,4 +53,5 @@ private CommandLineArgumentProvider asArgumentProvider() {
5053
return Collections.emptyList();
5154
};
5255
}
56+
5357
}

buildSrc/src/main/java/org/springframework/build/TestConventions.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
* Conventions that are applied in the presence of the {@link JavaBasePlugin}. When the
3131
* plugin is applied:
3232
* <ul>
33-
* <li>The {@link TestRetryPlugin Test Retry} plugin is applied so that flaky tests
34-
* are retried 3 times when running on the CI server.
33+
* <li>The {@link TestRetryPlugin Test Retry} plugin is applied so that flaky tests are
34+
* retried 3 times when running on the CI server.
3535
* </ul>
3636
*
3737
* @author Brian Clozel
@@ -45,11 +45,10 @@ void apply(Project project) {
4545
}
4646

4747
private void configureTestConventions(Project project) {
48-
project.getTasks().withType(Test.class,
49-
test -> {
50-
configureTests(project, test);
51-
configureTestRetryPlugin(project, test);
52-
});
48+
project.getTasks().withType(Test.class, test -> {
49+
configureTests(project, test);
50+
configureTestRetryPlugin(project, test);
51+
});
5352
}
5453

5554
private void configureTests(Project project, Test test) {
@@ -60,18 +59,12 @@ private void configureTests(Project project, Test test) {
6059
}
6160
});
6261
test.include("**/*Tests.class", "**/*Test.class");
63-
test.setSystemProperties(Map.of(
64-
"java.awt.headless", "true",
65-
"io.netty.leakDetection.level", "paranoid"
66-
));
62+
test.setSystemProperties(Map.of("java.awt.headless", "true", "io.netty.leakDetection.level", "paranoid"));
6763
if (project.hasProperty("testGroups")) {
6864
test.systemProperty("testGroups", project.getProperties().get("testGroups"));
6965
}
70-
test.jvmArgs(
71-
"--add-opens=java.base/java.lang=ALL-UNNAMED",
72-
"--add-opens=java.base/java.util=ALL-UNNAMED",
73-
"-Xshare:off"
74-
);
66+
test.jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED",
67+
"-Xshare:off");
7568
}
7669

7770
private void configureTestRetryPlugin(Project project, Test test) {

buildSrc/src/main/java/org/springframework/build/architecture/ArchitectureCheck.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ public abstract class ArchitectureCheck extends DefaultTask {
6464
public ArchitectureCheck() {
6565
getOutputDirectory().convention(getProject().getLayout().getBuildDirectory().dir(getName()));
6666
getProhibitObjectsRequireNonNull().convention(true);
67-
getRules().addAll(packageInfoShouldBeNullMarked(),
68-
classesShouldNotImportForbiddenTypes(),
69-
javaClassesShouldNotImportKotlinAnnotations(),
70-
allPackagesShouldBeFreeOfTangles(),
67+
getRules().addAll(packageInfoShouldBeNullMarked(), classesShouldNotImportForbiddenTypes(),
68+
javaClassesShouldNotImportKotlinAnnotations(), allPackagesShouldBeFreeOfTangles(),
7169
noClassesShouldCallStringToLowerCaseWithoutLocale(),
7270
noClassesShouldCallStringToUpperCaseWithoutLocale());
7371
getRuleDescriptions().set(getRules().map((rules) -> rules.stream().map(ArchRule::getDescription).toList()));
@@ -76,12 +74,12 @@ public ArchitectureCheck() {
7674
@TaskAction
7775
void checkArchitecture() throws IOException {
7876
JavaClasses javaClasses = new ClassFileImporter()
79-
.importPaths(this.classes.getFiles().stream().map(File::toPath).toList());
77+
.importPaths(this.classes.getFiles().stream().map(File::toPath).toList());
8078
List<EvaluationResult> violations = getRules().get()
81-
.stream()
82-
.map((rule) -> rule.evaluate(javaClasses))
83-
.filter(EvaluationResult::hasViolation)
84-
.toList();
79+
.stream()
80+
.map((rule) -> rule.evaluate(javaClasses))
81+
.filter(EvaluationResult::hasViolation)
82+
.toList();
8583
File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
8684
outputFile.getParentFile().mkdirs();
8785
if (!violations.isEmpty()) {
@@ -134,4 +132,5 @@ final FileTree getInputClasses() {
134132
// The rules themselves can't be an input as they aren't serializable so we use
135133
// their descriptions instead
136134
abstract ListProperty<String> getRuleDescriptions();
135+
137136
}

buildSrc/src/main/java/org/springframework/build/architecture/ArchitecturePlugin.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ private void registerTasks(Project project) {
4848
continue;
4949
}
5050
TaskProvider<ArchitectureCheck> checkArchitecture = project.getTasks()
51-
.register(taskName(sourceSet), ArchitectureCheck.class,
52-
(task) -> {
53-
task.setClasses(sourceSet.getOutput().getClassesDirs());
54-
task.getResourcesDirectory().set(sourceSet.getOutput().getResourcesDir());
55-
task.dependsOn(sourceSet.getProcessResourcesTaskName());
56-
task.setDescription("Checks the architecture of the classes of the " + sourceSet.getName()
57-
+ " source set.");
58-
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
59-
});
51+
.register(taskName(sourceSet), ArchitectureCheck.class, (task) -> {
52+
task.setClasses(sourceSet.getOutput().getClassesDirs());
53+
task.getResourcesDirectory().set(sourceSet.getOutput().getResourcesDir());
54+
task.dependsOn(sourceSet.getProcessResourcesTaskName());
55+
task.setDescription(
56+
"Checks the architecture of the classes of the " + sourceSet.getName() + " source set.");
57+
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
58+
});
6059
architectureChecks.add(checkArchitecture);
6160
}
6261
if (!architectureChecks.isEmpty()) {
@@ -66,8 +65,7 @@ private void registerTasks(Project project) {
6665
}
6766

6867
private static String taskName(SourceSet sourceSet) {
69-
return "checkArchitecture"
70-
+ sourceSet.getName().substring(0, 1).toUpperCase()
68+
return "checkArchitecture" + sourceSet.getName().substring(0, 1).toUpperCase()
7169
+ sourceSet.getName().substring(1);
7270
}
7371

0 commit comments

Comments
 (0)