|
@@ -17,13 +17,14 @@
|
|
package org.springframework.gradle.checkstyle;
|
|
package org.springframework.gradle.checkstyle;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
import io.spring.javaformat.gradle.tasks.CheckFormat;
|
|
import io.spring.javaformat.gradle.tasks.CheckFormat;
|
|
import org.gradle.api.Plugin;
|
|
import org.gradle.api.Plugin;
|
|
import org.gradle.api.Project;
|
|
import org.gradle.api.Project;
|
|
|
|
+import org.gradle.api.artifacts.VersionCatalog;
|
|
|
|
+import org.gradle.api.artifacts.VersionCatalogsExtension;
|
|
import org.gradle.api.plugins.JavaPlugin;
|
|
import org.gradle.api.plugins.JavaPlugin;
|
|
import org.gradle.api.plugins.quality.CheckstyleExtension;
|
|
import org.gradle.api.plugins.quality.CheckstyleExtension;
|
|
import org.gradle.api.plugins.quality.CheckstylePlugin;
|
|
import org.gradle.api.plugins.quality.CheckstylePlugin;
|
|
@@ -36,12 +37,6 @@ import org.gradle.api.plugins.quality.CheckstylePlugin;
|
|
*/
|
|
*/
|
|
public class SpringJavaCheckstylePlugin implements Plugin<Project> {
|
|
public class SpringJavaCheckstylePlugin implements Plugin<Project> {
|
|
private static final String CHECKSTYLE_DIR = "etc/checkstyle";
|
|
private static final String CHECKSTYLE_DIR = "etc/checkstyle";
|
|
- private static final String SPRING_JAVAFORMAT_VERSION_PROPERTY = "springJavaformatVersion";
|
|
|
|
- private static final String DEFAULT_SPRING_JAVAFORMAT_VERSION = "0.0.41";
|
|
|
|
- private static final String NOHTTP_CHECKSTYLE_VERSION_PROPERTY = "nohttpCheckstyleVersion";
|
|
|
|
- private static final String DEFAULT_NOHTTP_CHECKSTYLE_VERSION = "0.0.11";
|
|
|
|
- private static final String CHECKSTYLE_TOOL_VERSION_PROPERTY = "checkstyleToolVersion";
|
|
|
|
- private static final String DEFAULT_CHECKSTYLE_TOOL_VERSION = "8.34";
|
|
|
|
private static final String SPRING_JAVAFORMAT_EXCLUDE_PACKAGES_PROPERTY = "springJavaformatExcludePackages";
|
|
private static final String SPRING_JAVAFORMAT_EXCLUDE_PACKAGES_PROPERTY = "springJavaformatExcludePackages";
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -51,15 +46,14 @@ public class SpringJavaCheckstylePlugin implements Plugin<Project> {
|
|
if (checkstyleDir.exists() && checkstyleDir.isDirectory()) {
|
|
if (checkstyleDir.exists() && checkstyleDir.isDirectory()) {
|
|
project.getPluginManager().apply(CheckstylePlugin.class);
|
|
project.getPluginManager().apply(CheckstylePlugin.class);
|
|
|
|
|
|
- // NOTE: See gradle.properties#springJavaformatVersion for actual version number
|
|
|
|
- project.getDependencies().add("checkstyle", "io.spring.javaformat:spring-javaformat-checkstyle:" + getSpringJavaformatVersion(project));
|
|
|
|
- // NOTE: See gradle.properties#nohttpCheckstyleVersion for actual version number
|
|
|
|
- project.getDependencies().add("checkstyle", "io.spring.nohttp:nohttp-checkstyle:" + getNohttpCheckstyleVersion(project));
|
|
|
|
|
|
+ VersionCatalog versionCatalog = project.getRootProject().getExtensions().getByType(VersionCatalogsExtension.class).named("libs");
|
|
|
|
+
|
|
|
|
+ project.getDependencies().add("checkstyle", versionCatalog.findLibrary("io-spring-javaformat-spring-javaformat-checkstyle").get());
|
|
|
|
+ project.getDependencies().add("checkstyle", versionCatalog.findLibrary("io-spring-nohttp-nohttp-checkstyle").get());
|
|
|
|
|
|
CheckstyleExtension checkstyle = project.getExtensions().getByType(CheckstyleExtension.class);
|
|
CheckstyleExtension checkstyle = project.getExtensions().getByType(CheckstyleExtension.class);
|
|
checkstyle.getConfigDirectory().set(checkstyleDir);
|
|
checkstyle.getConfigDirectory().set(checkstyleDir);
|
|
- // NOTE: See gradle.properties#checkstyleToolVersion for actual version number
|
|
|
|
- checkstyle.setToolVersion(getCheckstyleToolVersion(project));
|
|
|
|
|
|
+ checkstyle.setToolVersion("8.34");
|
|
}
|
|
}
|
|
|
|
|
|
// Configure checkFormat task
|
|
// Configure checkFormat task
|
|
@@ -73,30 +67,6 @@ public class SpringJavaCheckstylePlugin implements Plugin<Project> {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- private static String getSpringJavaformatVersion(Project project) {
|
|
|
|
- String springJavaformatVersion = DEFAULT_SPRING_JAVAFORMAT_VERSION;
|
|
|
|
- if (project.hasProperty(SPRING_JAVAFORMAT_VERSION_PROPERTY)) {
|
|
|
|
- springJavaformatVersion = Objects.requireNonNull(project.findProperty(SPRING_JAVAFORMAT_VERSION_PROPERTY)).toString();
|
|
|
|
- }
|
|
|
|
- return springJavaformatVersion;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static String getNohttpCheckstyleVersion(Project project) {
|
|
|
|
- String nohttpCheckstyleVersion = DEFAULT_NOHTTP_CHECKSTYLE_VERSION;
|
|
|
|
- if (project.hasProperty(NOHTTP_CHECKSTYLE_VERSION_PROPERTY)) {
|
|
|
|
- nohttpCheckstyleVersion = Objects.requireNonNull(project.findProperty(NOHTTP_CHECKSTYLE_VERSION_PROPERTY)).toString();
|
|
|
|
- }
|
|
|
|
- return nohttpCheckstyleVersion;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static String getCheckstyleToolVersion(Project project) {
|
|
|
|
- String checkstyleToolVersion = DEFAULT_CHECKSTYLE_TOOL_VERSION;
|
|
|
|
- if (project.hasProperty(CHECKSTYLE_TOOL_VERSION_PROPERTY)) {
|
|
|
|
- checkstyleToolVersion = Objects.requireNonNull(project.findProperty(CHECKSTYLE_TOOL_VERSION_PROPERTY)).toString();
|
|
|
|
- }
|
|
|
|
- return checkstyleToolVersion;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Nullable
|
|
@Nullable
|
|
private String[] getSpringJavaformatExcludePackages(Project project) {
|
|
private String[] getSpringJavaformatExcludePackages(Project project) {
|
|
String springJavaformatExcludePackages = (String) project.findProperty(SPRING_JAVAFORMAT_EXCLUDE_PACKAGES_PROPERTY);
|
|
String springJavaformatExcludePackages = (String) project.findProperty(SPRING_JAVAFORMAT_EXCLUDE_PACKAGES_PROPERTY);
|