diff --git a/README.adoc b/README.adoc
index 4329cd42..c35fa3a3 100644
--- a/README.adoc
+++ b/README.adoc
@@ -1,4 +1,4 @@
-:release-version: 0.0.22
+:release-version: 0.0.24
:checkstyle-version: 8.32
== Spring Java Format
@@ -223,7 +223,7 @@ If you want most `SpringChecks` but need to exclude one or two, you can do somet
"https://checkstyle.org/dtds/configuration_1_3.dtd">
-
+
----
diff --git a/pom.xml b/pom.xml
index 243d139e..3c8d3cfa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
io.spring.javaformat
spring-javaformat-build
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
pom
Spring JavaFormat Build
Spring JavaFormat
diff --git a/samples/spring-javaformat-gradle-sample/build.gradle b/samples/spring-javaformat-gradle-sample/build.gradle
index 075efe57..0df2a370 100644
--- a/samples/spring-javaformat-gradle-sample/build.gradle
+++ b/samples/spring-javaformat-gradle-sample/build.gradle
@@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath("io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.23-SNAPSHOT")
+ classpath("io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.25-SNAPSHOT")
}
}
@@ -25,5 +25,5 @@ checkstyle {
}
dependencies {
- checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.23-SNAPSHOT")
+ checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.25-SNAPSHOT")
}
diff --git a/samples/spring-javaformat-maven-sample/pom.xml b/samples/spring-javaformat-maven-sample/pom.xml
index 7f9f1c53..9325adc1 100644
--- a/samples/spring-javaformat-maven-sample/pom.xml
+++ b/samples/spring-javaformat-maven-sample/pom.xml
@@ -8,7 +8,7 @@
0.0.1-SNAPSHOT
UTF-8
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/feature.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/feature.xml
index b5ebc18e..8c4f2410 100755
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/feature.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/feature.xml
@@ -2,7 +2,7 @@
@@ -22,7 +22,7 @@
id="io.spring.javaformat.eclipse"
download-size="0"
install-size="0"
- version="0.0.23.qualifier"
+ version="0.0.25.qualifier"
unpack="false"/>
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/pom.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/pom.xml
index e5f303df..a3de484f 100755
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/pom.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-eclipse
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
io.spring.javaformat.eclipse.feature
eclipse-feature
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/category.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/category.xml
index 76b1ee96..6d541652 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/category.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/category.xml
@@ -3,7 +3,7 @@
Maven Integration for Eclipse (maven-eclipse-plugin support)
-
+
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/io.spring.javaformat.eclipse.product b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/io.spring.javaformat.eclipse.product
index 14b8d588..398d7069 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/io.spring.javaformat.eclipse.product
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/io.spring.javaformat.eclipse.product
@@ -1,7 +1,7 @@
-
+
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/pom.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/pom.xml
index d6ccf561..8f60b424 100755
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/pom.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-eclipse
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
io.spring.javaformat.eclipse.site
eclipse-repository
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/META-INF/MANIFEST.MF b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/META-INF/MANIFEST.MF
index a50c2468..82dccb8e 100755
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/META-INF/MANIFEST.MF
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Spring Java Format Tests
Bundle-SymbolicName: io.spring.javaformat.eclipse.tests
Automatic-Module-Name: io.spring.javaformat.eclipse.tests
-Bundle-Version: 0.0.23.qualifier
+Bundle-Version: 0.0.25.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.junit;bundle-version="4.12"
Bundle-ClassPath: .,
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/pom.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/pom.xml
index 29a92fcb..c835929c 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/pom.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-eclipse
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
io.spring.javaformat.eclipse.tests
eclipse-test-plugin
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/META-INF/MANIFEST.MF b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/META-INF/MANIFEST.MF
index 79044b08..e55f9d1a 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/META-INF/MANIFEST.MF
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Spring Java Format
Bundle-SymbolicName: io.spring.javaformat.eclipse;singleton:=true
Automatic-Module-Name: io.spring.javaformat.eclipse
-Bundle-Version: 0.0.23.qualifier
+Bundle-Version: 0.0.25.qualifier
Bundle-Activator: io.spring.javaformat.eclipse.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.ui,
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/pom.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/pom.xml
index b7ca66b1..120d690b 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/pom.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-eclipse
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
io.spring.javaformat.eclipse
eclipse-plugin
diff --git a/spring-javaformat-eclipse/pom.xml b/spring-javaformat-eclipse/pom.xml
index 507e7335..080af208 100644
--- a/spring-javaformat-eclipse/pom.xml
+++ b/spring-javaformat-eclipse/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-eclipse
pom
diff --git a/spring-javaformat-gradle/pom.xml b/spring-javaformat-gradle/pom.xml
index ef99254e..bb021236 100644
--- a/spring-javaformat-gradle/pom.xml
+++ b/spring-javaformat-gradle/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-gradle
pom
diff --git a/spring-javaformat-gradle/spring-javaformat-gradle-plugin/pom.xml b/spring-javaformat-gradle/spring-javaformat-gradle-plugin/pom.xml
index 1307025c..b9f63b20 100644
--- a/spring-javaformat-gradle/spring-javaformat-gradle-plugin/pom.xml
+++ b/spring-javaformat-gradle/spring-javaformat-gradle-plugin/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-gradle
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-gradle-plugin
pom
diff --git a/spring-javaformat-intellij/pom.xml b/spring-javaformat-intellij/pom.xml
index 1529ec05..f37c92e7 100644
--- a/spring-javaformat-intellij/pom.xml
+++ b/spring-javaformat-intellij/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-intellij
pom
diff --git a/spring-javaformat-intellij/spring-javaformat-intellij-plugin/pom.xml b/spring-javaformat-intellij/spring-javaformat-intellij-plugin/pom.xml
index afbd4f70..087a48a6 100644
--- a/spring-javaformat-intellij/spring-javaformat-intellij-plugin/pom.xml
+++ b/spring-javaformat-intellij/spring-javaformat-intellij-plugin/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat-intellij
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-intellij-plugin
Spring JavaFormat IntelliJ Plugin
diff --git a/spring-javaformat-intellij/spring-javaformat-intellij-runtime/pom.xml b/spring-javaformat-intellij/spring-javaformat-intellij-runtime/pom.xml
index b61392d1..d4f97448 100644
--- a/spring-javaformat-intellij/spring-javaformat-intellij-runtime/pom.xml
+++ b/spring-javaformat-intellij/spring-javaformat-intellij-runtime/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-intellij
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-intellij-runtime
pom
diff --git a/spring-javaformat-maven/pom.xml b/spring-javaformat-maven/pom.xml
index 16207743..7a2a5884 100644
--- a/spring-javaformat-maven/pom.xml
+++ b/spring-javaformat-maven/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-maven
pom
diff --git a/spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml b/spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml
index 8625c281..cf113120 100644
--- a/spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml
+++ b/spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat-maven
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-maven-plugin
maven-plugin
diff --git a/spring-javaformat-maven/spring-javaformat-maven-plugin/src/main/java/io/spring/format/maven/FormatMojo.java b/spring-javaformat-maven/spring-javaformat-maven-plugin/src/main/java/io/spring/format/maven/FormatMojo.java
index a738f046..549ccefe 100644
--- a/spring-javaformat-maven/spring-javaformat-maven-plugin/src/main/java/io/spring/format/maven/FormatMojo.java
+++ b/spring-javaformat-maven/spring-javaformat-maven-plugin/src/main/java/io/spring/format/maven/FormatMojo.java
@@ -88,8 +88,18 @@ public abstract class FormatMojo extends AbstractMojo {
@Parameter(property = "spring-javaformat.includeGeneratedSource", defaultValue = "false")
private boolean includeGeneratedSource;
+ /**
+ * Specifies the line separator to use when formatting.
+ */
+ @Parameter(property = "spring-javaformat.lineSeparator")
+ private LineSeparator lineSeparator;
+
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
+ if (this.lineSeparator != null) {
+ System.getProperties().setProperty("line.separator", this.lineSeparator.getSymbol());
+ }
+
List directories = new ArrayList<>();
resolve(this.sourceDirectories).forEach(directories::add);
resolve(this.testSourceDirectories).forEach(directories::add);
@@ -158,4 +168,35 @@ private boolean hasLength(Object[] array) {
protected abstract void execute(List files, Charset encoding)
throws MojoExecutionException, MojoFailureException;
+
+ /*
+ * The types of line separator. {@link FormatMojo#lineSeparator}
+ */
+ enum LineSeparator {
+
+ /**
+ * Carriage Return.
+ */
+ CR("\r"),
+
+ /**
+ * Linefeed.
+ */
+ LF("\n"),
+
+ /**
+ * Carriage Return & Linefeed.
+ */
+ CRLF("\r\n");
+
+ LineSeparator(String symbol) {
+ this.symbol = symbol;
+ }
+
+ private final String symbol;
+
+ private String getSymbol() {
+ return this.symbol;
+ }
+ }
}
diff --git a/spring-javaformat/pom.xml b/spring-javaformat/pom.xml
index e32b07c7..e5ba0a38 100644
--- a/spring-javaformat/pom.xml
+++ b/spring-javaformat/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat
pom
diff --git a/spring-javaformat/spring-javaformat-checkstyle/pom.xml b/spring-javaformat/spring-javaformat-checkstyle/pom.xml
index 1bad5f59..6416abfb 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/pom.xml
+++ b/spring-javaformat/spring-javaformat-checkstyle/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-checkstyle
Spring JavaFormat CheckStyle
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/FilteredModuleFactory.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/FilteredModuleFactory.java
index e9ffd67e..3a5a9921 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/FilteredModuleFactory.java
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/FilteredModuleFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2019 the original author or authors.
+ * Copyright 2017-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,9 +23,19 @@
import com.puppycrawl.tools.checkstyle.TreeWalkerFilter;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
+import com.puppycrawl.tools.checkstyle.api.Configuration;
class FilteredModuleFactory implements ModuleFactory {
+ static final TreeWalkerFilter FILTERED = new TreeWalkerFilter() {
+
+ @Override
+ public boolean accept(TreeWalkerAuditEvent treeWalkerAuditEvent) {
+ return true;
+ }
+
+ };
+
private final ModuleFactory moduleFactory;
private final Set excludes;
@@ -38,32 +48,25 @@ class FilteredModuleFactory implements ModuleFactory {
@Override
public Object createModule(String name) throws CheckstyleException {
Object module = this.moduleFactory.createModule(name);
- if (module instanceof AbstractCheck) {
- module = filter((AbstractCheck) module);
+ if (isFiltered(module)) {
+ if (module instanceof AbstractCheck) {
+ return FILTERED;
+ }
+ throw new IllegalStateException("Unable to filter module " + module.getClass().getName());
}
return module;
}
- private Object filter(AbstractCheck check) {
- if (this.excludes != null && this.excludes.contains(check.getClass().getName())) {
- return new FilteredCheck(check);
- }
- return check;
+ boolean nonFiltered(Configuration configuration) {
+ return !isFiltered(configuration.getName());
}
- static class FilteredCheck implements TreeWalkerFilter {
-
- private final AbstractCheck check;
-
- FilteredCheck(AbstractCheck check) {
- this.check = check;
- }
-
- @Override
- public boolean accept(TreeWalkerAuditEvent treeWalkerAuditEvent) {
- return true;
- }
+ private boolean isFiltered(Object module) {
+ return isFiltered(module.getClass().getName());
+ }
+ private boolean isFiltered(String name) {
+ return this.excludes != null && this.excludes.contains(name);
}
}
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringChecks.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringChecks.java
index eaedc007..8209e030 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringChecks.java
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringChecks.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2019 the original author or authors.
+ * Copyright 2017-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,12 +19,14 @@
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.util.stream.Collectors;
import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.DefaultContext;
@@ -61,6 +63,8 @@ public class SpringChecks extends AbstractFileSetCheck implements ExternalResour
private String headerFile;
+ private Set avoidStaticImportExcludes = Collections.emptySet();
+
private String projectRootPackage = SpringImportOrderCheck.DEFAULT_PROJECT_ROOT_PACKAGE;
private Set excludes;
@@ -83,7 +87,7 @@ public void setModuleFactory(ModuleFactory moduleFactory) {
@Override
public void finishLocalSetup() {
- ModuleFactory moduleFactory = new FilteredModuleFactory(this.moduleFactory, this.excludes);
+ FilteredModuleFactory moduleFactory = new FilteredModuleFactory(this.moduleFactory, this.excludes);
DefaultContext context = new DefaultContext();
context.add("classLoader", this.classLoader);
context.add("severity", getSeverity());
@@ -94,6 +98,8 @@ public void finishLocalSetup() {
put(properties, "headerCopyrightPattern", this.headerCopyrightPattern);
put(properties, "headerFile", this.headerFile);
put(properties, "projectRootPackage", this.projectRootPackage);
+ put(properties, "avoidStaticImportExcludes",
+ this.avoidStaticImportExcludes.stream().collect(Collectors.joining(",")));
this.checks = new SpringConfigurationLoader(context, moduleFactory).load(new PropertiesExpander(properties));
}
@@ -153,6 +159,10 @@ public void setHeaderFile(String headerFile) {
this.headerFile = headerFile;
}
+ public void setAvoidStaticImportExcludes(String[] avoidStaticImportExcludes) {
+ this.avoidStaticImportExcludes = new LinkedHashSet<>(Arrays.asList(avoidStaticImportExcludes));
+ }
+
public void setProjectRootPackage(String projectRootPackage) {
this.projectRootPackage = projectRootPackage;
}
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringConfigurationLoader.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringConfigurationLoader.java
index ac1b1069..f801f130 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringConfigurationLoader.java
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringConfigurationLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2019 the original author or authors.
+ * Copyright 2017-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
import com.puppycrawl.tools.checkstyle.ConfigurationLoader.IgnoredModulesOptions;
-import com.puppycrawl.tools.checkstyle.ModuleFactory;
import com.puppycrawl.tools.checkstyle.PropertyResolver;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
@@ -42,9 +41,9 @@ class SpringConfigurationLoader {
private final Context context;
- private final ModuleFactory moduleFactory;
+ private final FilteredModuleFactory moduleFactory;
- SpringConfigurationLoader(Context context, ModuleFactory moduleFactory) {
+ SpringConfigurationLoader(Context context, FilteredModuleFactory moduleFactory) {
this.context = context;
this.moduleFactory = moduleFactory;
}
@@ -52,7 +51,8 @@ class SpringConfigurationLoader {
public Collection load(PropertyResolver propertyResolver) {
Configuration config = loadConfiguration(getClass().getResourceAsStream("spring-checkstyle.xml"),
propertyResolver);
- return Arrays.stream(config.getChildren()).map(this::load).collect(Collectors.toList());
+ return Arrays.stream(config.getChildren()).filter(this.moduleFactory::nonFiltered).map(this::load)
+ .collect(Collectors.toList());
}
private Configuration loadConfiguration(InputStream inputStream, PropertyResolver propertyResolver) {
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringAvoidStaticImportCheck.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringAvoidStaticImportCheck.java
new file mode 100644
index 00000000..9293f1dc
--- /dev/null
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringAvoidStaticImportCheck.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2017-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.spring.javaformat.checkstyle.check;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck;
+import com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck;
+
+/**
+ * Spring variant of {@link AvoidStarImportCheck}.
+ *
+ * @author Phillip Webb
+ */
+public class SpringAvoidStaticImportCheck extends AvoidStaticImportCheck {
+
+ private static final Set ALWAYS_EXCLUDED;
+ static {
+ Set excludes = new LinkedHashSet<>();
+ excludes.add("io.restassured.RestAssured.*");
+ excludes.add("org.assertj.core.api.Assertions.*");
+ excludes.add("org.assertj.core.api.Assumptions.*");
+ excludes.add("org.assertj.core.api.HamcrestCondition.*");
+ excludes.add("org.awaitility.Awaitility.*");
+ excludes.add("org.hamcrest.CoreMatchers.*");
+ excludes.add("org.hamcrest.Matchers.*");
+ excludes.add("org.junit.Assert.*");
+ excludes.add("org.junit.Assume.*");
+ excludes.add("org.junit.internal.matchers.ThrowableMessageMatcher.*");
+ excludes.add("org.junit.jupiter.api.Assertions.*");
+ excludes.add("org.junit.jupiter.api.Assumptions.*");
+ excludes.add("org.junit.jupiter.api.Assertions.*");
+ excludes.add("org.mockito.ArgumentMatchers.*");
+ excludes.add("org.mockito.BDDMockito.*");
+ excludes.add("org.mockito.Matchers.*");
+ excludes.add("org.mockito.AdditionalMatchers.*");
+ excludes.add("org.mockito.Mockito.*");
+ excludes.add("org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*");
+ excludes.add("org.springframework.boot.configurationprocessor.TestCompiler.*");
+ excludes.add("org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*");
+ excludes.add("org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo");
+ excludes.add("org.springframework.restdocs.headers.HeaderDocumentation.*");
+ excludes.add("org.springframework.restdocs.hypermedia.HypermediaDocumentation.*");
+ excludes.add("org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*");
+ excludes.add("org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*");
+ excludes.add("org.springframework.restdocs.operation.preprocess.Preprocessors.*");
+ excludes.add("org.springframework.restdocs.payload.PayloadDocumentation.*");
+ excludes.add("org.springframework.restdocs.request.RequestDocumentation.*");
+ excludes.add("org.springframework.restdocs.restassured3.operation.preprocess.RestAssuredPreprocessors.*");
+ excludes.add("org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.*");
+ excludes.add("org.springframework.restdocs.snippet.Attributes.*");
+ excludes.add("org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.*");
+ excludes.add("org.springframework.security.config.Customizer.*");
+ excludes.add("org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.*");
+ excludes.add("org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*");
+ excludes.add("org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.*");
+ excludes.add("org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*");
+ excludes.add("org.springframework.test.web.client.ExpectedCount.*");
+ excludes.add("org.springframework.test.web.client.match.MockRestRequestMatchers.*");
+ excludes.add("org.springframework.test.web.client.response.MockRestResponseCreators.*");
+ excludes.add("org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*");
+ excludes.add("org.springframework.test.web.servlet.result.MockMvcResultHandlers.*");
+ excludes.add("org.springframework.test.web.servlet.result.MockMvcResultMatchers.*");
+ excludes.add("org.springframework.test.web.servlet.setup.MockMvcBuilders.*");
+ excludes.add("org.springframework.web.reactive.function.BodyInserters.*");
+ excludes.add("org.springframework.web.reactive.function.server.RequestPredicates.*");
+ excludes.add("org.springframework.web.reactive.function.server.RouterFunctions.*");
+ excludes.add("org.springframework.ws.test.client.RequestMatchers.*");
+ excludes.add("org.springframework.ws.test.client.ResponseCreators.*");
+ ALWAYS_EXCLUDED = Collections.unmodifiableSet(excludes);
+ }
+
+ public SpringAvoidStaticImportCheck() {
+ setExcludes(ALWAYS_EXCLUDED.toArray(new String[0]));
+ }
+
+ @Override
+ public void setExcludes(String... excludes) {
+ Set merged = new LinkedHashSet<>(ALWAYS_EXCLUDED);
+ merged.addAll(Arrays.asList(excludes));
+ super.setExcludes(merged.toArray(new String[0]));
+ }
+
+}
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java
index 848479e3..b477f23a 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2019 the original author or authors.
+ * Copyright 2017-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/check/messages.properties b/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/check/messages.properties
index d0958caa..3aa0427a 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/check/messages.properties
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/check/messages.properties
@@ -2,6 +2,9 @@ catch.singleLetter=Single letter catch variable (use "ex" instead).
catch.wideEye=''o_O'' catch variable (use "ex" instead).
header.unexpected=Unexpected header.
header.mismatch=Line does not match expected header line of ''{0}''.
+hide.utility.class=Utility classes should not have a public or default constructor.
+import.avoidStatic=Using a static member import should be avoided - {0}.
+import.ordering=Wrong order for ''{0}'' import.
javadoc.badCase=Javadoc element descriptions should not start with an uppercase letter.
javadoc.bannedTag=Javadoc tag ''{0}'' should not be used.
javadoc.missingSince=Missing Javadoc @since tag.
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml b/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml
index 7541a6ec..067c03f3 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml
@@ -7,13 +7,11 @@
-
-
-
-
-
-
+
+
+
+
@@ -73,56 +71,6 @@
-
-
-
@@ -208,6 +156,9 @@
+
+
+
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java b/spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java
index e95ccaad..cbca2fe7 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2019 the original author or authors.
+ * Copyright 2017-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
import java.util.Set;
import com.puppycrawl.tools.checkstyle.DefaultContext;
-import com.puppycrawl.tools.checkstyle.ModuleFactory;
import com.puppycrawl.tools.checkstyle.PackageObjectFactory;
import com.puppycrawl.tools.checkstyle.PropertiesExpander;
import com.puppycrawl.tools.checkstyle.PropertyResolver;
@@ -53,10 +52,9 @@ public void loadShouldLoadChecks() {
}
@Test
- @SuppressWarnings({ "unchecked", "rawtypes" })
public void loadWithExcludeShouldExcludeChecks() {
Set excludes = Collections
- .singleton("com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck");
+ .singleton("com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck");
Collection checks = load(excludes);
assertThat(checks).hasSize(3);
TreeWalker treeWalker = (TreeWalker) checks.toArray()[2];
@@ -64,13 +62,19 @@ public void loadWithExcludeShouldExcludeChecks() {
assertThat(ordinaryChecks).hasSize(59);
}
+ @Test
+ public void loadWithExcludeHeaderShouldExcludeChecks() {
+ Set excludes = Collections.singleton("io.spring.javaformat.checkstyle.check.SpringHeaderCheck");
+ Object[] checks = load(excludes).stream().toArray();
+ assertThat(checks).hasSize(2);
+ }
+
private Collection load(Set excludes) {
DefaultContext context = new DefaultContext();
- ModuleFactory moduleFactory = new PackageObjectFactory(getClass().getPackage().getName(),
- getClass().getClassLoader());
- moduleFactory = new FilteredModuleFactory(moduleFactory, excludes);
- context.add("moduleFactory", moduleFactory);
- Collection checks = new SpringConfigurationLoader(context, moduleFactory)
+ FilteredModuleFactory filteredModuleFactory = new FilteredModuleFactory(
+ new PackageObjectFactory(getClass().getPackage().getName(), getClass().getClassLoader()), excludes);
+ context.add("moduleFactory", filteredModuleFactory);
+ Collection checks = new SpringConfigurationLoader(context, filteredModuleFactory)
.load(getPropertyResolver());
return checks;
}
@@ -81,6 +85,7 @@ private PropertyResolver getPropertyResolver() {
properties.put("headerFile", "");
properties.put("headerCopyrightPattern", SpringHeaderCheck.DEFAULT_HEADER_COPYRIGHT_PATTERN);
properties.put("projectRootPackage", SpringImportOrderCheck.DEFAULT_PROJECT_ROOT_PACKAGE);
+ properties.put("avoidStaticImportExcludes", "");
return new PropertiesExpander(properties);
}
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/HideUtilityClassConstructorInvalid.txt b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/HideUtilityClassConstructorInvalid.txt
index 84638146..dc14dcd3 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/HideUtilityClassConstructorInvalid.txt
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/HideUtilityClassConstructorInvalid.txt
@@ -1 +1 @@
-+HideUtilityClassConstructorInvalid.java:22:1: hide.utility.class [SpringHideUtilityClassConstructor]
++HideUtilityClassConstructorInvalid.java:22:1: Utility classes should not have a public or default constructor. [SpringHideUtilityClassConstructor]
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/ImportOrderCustomPackageInvalid.txt b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/ImportOrderCustomPackageInvalid.txt
index 5b52d643..37a1d385 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/ImportOrderCustomPackageInvalid.txt
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/ImportOrderCustomPackageInvalid.txt
@@ -1 +1 @@
-+ImportOrderCustomPackageInvalid.java:21:1: import.ordering [SpringImportOrder]
++ImportOrderCustomPackageInvalid.java:21:1: Wrong order for 'java.util.Objects' import. [SpringImportOrder]
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocSoundtrack.java b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocSoundtrack.java
index dd4e5bba..ea598898 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocSoundtrack.java
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocSoundtrack.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2019 the original author or authors.
+ * Copyright 2017-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/pom.xml
index 6e153e23..80077111 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-formatter-eclipse-rewriter
Spring JavaFormat Eclipse Rewriter
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/META-INF/MANIFEST.MF b/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/META-INF/MANIFEST.MF
index ca370c7f..2f91a056 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/META-INF/MANIFEST.MF
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spring Formatter Eclipse Runtime
Bundle-SymbolicName: spring-javaformat-formatter-eclipse-runtime
-Bundle-Version: 0.0.23.qualifier
+Bundle-Version: 0.0.25.qualifier
Require-Bundle: org.eclipse.jdt.core;bundle-version="[1.0.0,10.0.0)",
org.eclipse.jface;bundle-version="[1.0.0,10.0.0)",
org.eclipse.jdt.core.source;bundle-version="[1.0.0,10.0.0)";resolution:=optional,
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/pom.xml
index efa5bdfe..536f87e7 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-formatter-eclipse-runtime
eclipse-plugin
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse/pom.xml
index 3a7af1aa..4c583ce0 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-formatter-eclipse
Spring JavaFormat Eclipse
@@ -17,7 +17,7 @@
io.spring.javaformat
spring-javaformat-formatter-eclipse-runtime
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
true
diff --git a/spring-javaformat/spring-javaformat-formatter-shaded/pom.xml b/spring-javaformat/spring-javaformat-formatter-shaded/pom.xml
index e341677f..f47607ba 100644
--- a/spring-javaformat/spring-javaformat-formatter-shaded/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-shaded/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-formatter-shaded
Spring JavaFormat Formatter Shaded
diff --git a/spring-javaformat/spring-javaformat-formatter-shader/pom.xml b/spring-javaformat/spring-javaformat-formatter-shader/pom.xml
index 103ed272..cf9a1b35 100644
--- a/spring-javaformat/spring-javaformat-formatter-shader/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-shader/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-formatter-shader
Spring JavaFormat Formatter Shader
diff --git a/spring-javaformat/spring-javaformat-formatter/pom.xml b/spring-javaformat/spring-javaformat-formatter/pom.xml
index ef2d2980..b62917de 100644
--- a/spring-javaformat/spring-javaformat-formatter/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.23-SNAPSHOT
+ 0.0.25-SNAPSHOT
spring-javaformat-formatter
Spring JavaFormat Formatter
diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml
index c765c0a0..71649dd3 100644
--- a/src/checkstyle/checkstyle.xml
+++ b/src/checkstyle/checkstyle.xml
@@ -8,9 +8,7 @@
-
-
-
+