Skip to content

Commit

Permalink
Add JavadocPackageCheck to the default Spring checks
Browse files Browse the repository at this point in the history
Closes gh-328
  • Loading branch information
wilkinsona committed May 24, 2022
1 parent e8bc0a1 commit d496c18
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package simple;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<property name="headerCopyrightPattern" value="${headerCopyrightPattern}" />
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck" />
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck" />

<!-- TreeWalker Checks -->
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2022 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.
Expand All @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -112,8 +113,14 @@ private void printDebugInfo(File file) throws CheckstyleException {
}

public static Collection<Parameter> paramaters() throws IOException {
return Arrays.stream(SOURCES_DIR.list((dir, name) -> !name.startsWith("."))).sorted().map(Parameter::new)
.collect(Collectors.toList());
ArrayList<Parameter> parameters = Arrays.stream(SOURCES_DIR.listFiles(SpringChecksTests::sourceFile)).sorted()
.map(Parameter::new).collect(Collectors.toCollection(ArrayList::new));
parameters.add(new Parameter(new File(SOURCES_DIR, "nopackageinfo/NoPackageInfo.java")));
return parameters;
}

private static boolean sourceFile(File file) {
return file.isFile() && !file.getName().startsWith(".") && !file.getName().equals("package-info.java");
}

private static class Parameter {
Expand All @@ -126,7 +133,8 @@ private static class Parameter {

private final File configFile;

Parameter(String sourceName) {
Parameter(File sourceFile) {
String sourceName = sourceFile.getAbsolutePath().substring(SOURCES_DIR.getAbsolutePath().length() + 1);
this.name = sourceName.replace(".java", "");
this.sourceFile = new File(SOURCES_DIR, sourceName);
File configFile = new File(CONFIGS_DIR, this.name + ".xml");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2022 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.
Expand Down Expand Up @@ -45,8 +45,8 @@ public class SpringConfigurationLoaderTests {
@Test
public void loadShouldLoadChecks() {
Collection<FileSetCheck> checks = load(null);
assertThat(checks).hasSize(3);
TreeWalker treeWalker = (TreeWalker) checks.toArray()[2];
assertThat(checks).hasSize(4);
TreeWalker treeWalker = (TreeWalker) checks.toArray()[3];
Set<?> ordinaryChecks = (Set<?>) Extractors.byName("ordinaryChecks").extract(treeWalker);
assertThat(ordinaryChecks).hasSize(60);
}
Expand All @@ -56,8 +56,8 @@ public void loadWithExcludeShouldExcludeChecks() {
Set<String> excludes = Collections
.singleton("com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck");
Collection<FileSetCheck> checks = load(excludes);
assertThat(checks).hasSize(3);
TreeWalker treeWalker = (TreeWalker) checks.toArray()[2];
assertThat(checks).hasSize(4);
TreeWalker treeWalker = (TreeWalker) checks.toArray()[3];
Set<?> ordinaryChecks = (Set<?>) Extractors.byName("ordinaryChecks").extract(treeWalker);
assertThat(ordinaryChecks).hasSize(59);
}
Expand All @@ -66,7 +66,7 @@ public void loadWithExcludeShouldExcludeChecks() {
public void loadWithExcludeHeaderShouldExcludeChecks() {
Set<String> excludes = Collections.singleton("io.spring.javaformat.checkstyle.check.SpringHeaderCheck");
Object[] checks = load(excludes).stream().toArray();
assertThat(checks).hasSize(2);
assertThat(checks).hasSize(3);
}

private Collection<FileSetCheck> load(Set<String> excludes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+Missing package-info.java file
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017-2022 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 nopackageinfo;

/**
* A class in a package with no {@code package-info.java} file.
*
* @author Andy Wilkinson
*/
class NoPackageInfo {

}
Empty file.

0 comments on commit d496c18

Please sign in to comment.