Temporarily exclude project from checkFormat task

This commit is contained in:
Steve Riesenberg
2022-03-31 17:11:07 -05:00
committed by Steve Riesenberg
parent 72c2e15487
commit 7845b6a369
2 changed files with 20 additions and 0 deletions

View File

@@ -19,6 +19,9 @@ package org.springframework.gradle.checkstyle;
import java.io.File;
import java.util.Objects;
import javax.annotation.Nullable;
import io.spring.javaformat.gradle.tasks.CheckFormat;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
@@ -39,6 +42,7 @@ public class SpringJavaCheckstylePlugin implements Plugin<Project> {
private static final String DEFAULT_NOHTTP_CHECKSTYLE_VERSION = "0.0.10";
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";
@Override
public void apply(Project project) {
@@ -57,6 +61,15 @@ public class SpringJavaCheckstylePlugin implements Plugin<Project> {
// NOTE: See gradle.properties#checkstyleToolVersion for actual version number
checkstyle.setToolVersion(getCheckstyleToolVersion(project));
}
// Configure checkFormat task
project.getTasks().withType(CheckFormat.class, (checkFormat) -> {
// NOTE: See gradle.properties#springJavaformatExcludePackages for excluded packages
String[] springJavaformatExcludePackages = getSpringJavaformatExcludePackages(project);
if (springJavaformatExcludePackages != null) {
checkFormat.exclude(springJavaformatExcludePackages);
}
});
});
}
@@ -83,4 +96,10 @@ public class SpringJavaCheckstylePlugin implements Plugin<Project> {
}
return checkstyleToolVersion;
}
@Nullable
private String[] getSpringJavaformatExcludePackages(Project project) {
String springJavaformatExcludePackages = (String) project.findProperty(SPRING_JAVAFORMAT_EXCLUDE_PACKAGES_PROPERTY);
return (springJavaformatExcludePackages != null) ? springJavaformatExcludePackages.split(" ") : null;
}
}

View File

@@ -5,6 +5,7 @@ org.gradle.caching=true
springFrameworkVersion=5.3.19
springSecurityVersion=5.5.6
springJavaformatVersion=0.0.31
springJavaformatExcludePackages=org/springframework/security/config org/springframework/security/oauth2
checkstyleToolVersion=8.34
nohttpCheckstyleVersion=0.0.10
jacocoToolVersion=0.8.7