Skip to content

Commit d496c18

Browse files
committed
Add JavadocPackageCheck to the default Spring checks
Closes gh-328
1 parent e8bc0a1 commit d496c18

File tree

7 files changed

+47
-10
lines changed

7 files changed

+47
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package simple;

spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<property name="headerCopyrightPattern" value="${headerCopyrightPattern}" />
1313
</module>
1414
<module name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck" />
15+
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck" />
1516

1617
<!-- TreeWalker Checks -->
1718
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">

spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringChecksTests.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2022 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.
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323
import java.nio.file.Files;
24+
import java.util.ArrayList;
2425
import java.util.Arrays;
2526
import java.util.Collection;
2627
import java.util.List;
@@ -112,8 +113,14 @@ private void printDebugInfo(File file) throws CheckstyleException {
112113
}
113114

114115
public static Collection<Parameter> paramaters() throws IOException {
115-
return Arrays.stream(SOURCES_DIR.list((dir, name) -> !name.startsWith("."))).sorted().map(Parameter::new)
116-
.collect(Collectors.toList());
116+
ArrayList<Parameter> parameters = Arrays.stream(SOURCES_DIR.listFiles(SpringChecksTests::sourceFile)).sorted()
117+
.map(Parameter::new).collect(Collectors.toCollection(ArrayList::new));
118+
parameters.add(new Parameter(new File(SOURCES_DIR, "nopackageinfo/NoPackageInfo.java")));
119+
return parameters;
120+
}
121+
122+
private static boolean sourceFile(File file) {
123+
return file.isFile() && !file.getName().startsWith(".") && !file.getName().equals("package-info.java");
117124
}
118125

119126
private static class Parameter {
@@ -126,7 +133,8 @@ private static class Parameter {
126133

127134
private final File configFile;
128135

129-
Parameter(String sourceName) {
136+
Parameter(File sourceFile) {
137+
String sourceName = sourceFile.getAbsolutePath().substring(SOURCES_DIR.getAbsolutePath().length() + 1);
130138
this.name = sourceName.replace(".java", "");
131139
this.sourceFile = new File(SOURCES_DIR, sourceName);
132140
File configFile = new File(CONFIGS_DIR, this.name + ".xml");

spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2022 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.
@@ -45,8 +45,8 @@ public class SpringConfigurationLoaderTests {
4545
@Test
4646
public void loadShouldLoadChecks() {
4747
Collection<FileSetCheck> checks = load(null);
48-
assertThat(checks).hasSize(3);
49-
TreeWalker treeWalker = (TreeWalker) checks.toArray()[2];
48+
assertThat(checks).hasSize(4);
49+
TreeWalker treeWalker = (TreeWalker) checks.toArray()[3];
5050
Set<?> ordinaryChecks = (Set<?>) Extractors.byName("ordinaryChecks").extract(treeWalker);
5151
assertThat(ordinaryChecks).hasSize(60);
5252
}
@@ -56,8 +56,8 @@ public void loadWithExcludeShouldExcludeChecks() {
5656
Set<String> excludes = Collections
5757
.singleton("com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck");
5858
Collection<FileSetCheck> checks = load(excludes);
59-
assertThat(checks).hasSize(3);
60-
TreeWalker treeWalker = (TreeWalker) checks.toArray()[2];
59+
assertThat(checks).hasSize(4);
60+
TreeWalker treeWalker = (TreeWalker) checks.toArray()[3];
6161
Set<?> ordinaryChecks = (Set<?>) Extractors.byName("ordinaryChecks").extract(treeWalker);
6262
assertThat(ordinaryChecks).hasSize(59);
6363
}
@@ -66,7 +66,7 @@ public void loadWithExcludeShouldExcludeChecks() {
6666
public void loadWithExcludeHeaderShouldExcludeChecks() {
6767
Set<String> excludes = Collections.singleton("io.spring.javaformat.checkstyle.check.SpringHeaderCheck");
6868
Object[] checks = load(excludes).stream().toArray();
69-
assertThat(checks).hasSize(2);
69+
assertThat(checks).hasSize(3);
7070
}
7171

7272
private Collection<FileSetCheck> load(Set<String> excludes) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+Missing package-info.java file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2017-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package nopackageinfo;
18+
19+
/**
20+
* A class in a package with no {@code package-info.java} file.
21+
*
22+
* @author Andy Wilkinson
23+
*/
24+
class NoPackageInfo {
25+
26+
}

spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/package-info.java

Whitespace-only changes.

0 commit comments

Comments
 (0)