Skip to content

Commit b1e3dbd

Browse files
committed
Added checkstyle as part of the build
1 parent a8f6cbf commit b1e3dbd

File tree

9 files changed

+249
-64
lines changed

9 files changed

+249
-64
lines changed

.build/apache-copyright.header

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
^\Q/*\E$
2+
^\Q *\E$
3+
^\Q * Copyright \E(20\d\d\-)?20\d\d\Q the original author or authors.\E$
4+
^\Q *\E$
5+
^\Q * Licensed under the Apache License, Version 2.0 (the "License");\E$
6+
^\Q * you may not use this file except in compliance with the License.\E$
7+
^\Q * You may obtain a copy of the License at\E$
8+
^\Q *\E$
9+
^\Q * http://www.apache.org/licenses/LICENSE-2.0\E$
10+
^\Q *\E$
11+
^\Q * Unless required by applicable law or agreed to in writing, software\E$
12+
^\Q * distributed under the License is distributed on an "AS IS" BASIS,\E$
13+
^\Q * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\E$
14+
^\Q * See the License for the specific language governing permissions and\E$
15+
^\Q * limitations under the License.\E$
16+
^\Q *\E$
17+
^\Q *\E$
18+
^\Q */\E$
19+
^.*$

.build/checkstyle.xml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.1//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
5+
6+
<!-- A set of Checkstyle rules that should be applied to non-legacy modules that should adhere to relatively strict
7+
code style rules. -->
8+
<module name="Checker">
9+
10+
<property name="severity" value="error"/>
11+
12+
<!-- Whitespace checks http://checkstyle.sourceforge.net/config_whitespace.html -->
13+
<module name="FileTabCharacter"/>
14+
15+
<!-- Regex checks - http://checkstyle.sourceforge.net/config_regexp.html -->
16+
<module name="RegexpSingleline">
17+
<property name="format" value="System\.(out|err)\.print"/>
18+
<property name="message"
19+
value="System.out.println and System.err.println are not allowed. Using logging instead."/>
20+
</module>
21+
22+
<module name="RegexpSingleline">
23+
<property name="format" value="\.printStackTrace\(\)"/>
24+
<property name="message"
25+
value="Calls to Throwable.printStackTrace() are not allowed. Log the exception instead."/>
26+
</module>
27+
28+
<!--
29+
Along with the FileContentsHolder module, allows for adding comments to source code to suppress checks.
30+
http://checkstyle.sourceforge.net/config.html#Filters
31+
-->
32+
<module name="SuppressionCommentFilter"/>
33+
34+
<module name="TreeWalker">
35+
36+
<!--
37+
Along with the SuppressionCommentFilter module, allows for adding comments to source code to suppress checks.
38+
http://checkstyle.sourceforge.net/config.html#Filters
39+
-->
40+
<module name="FileContentsHolder"/>
41+
42+
<!-- Import checks - http://checkstyle.sourceforge.net/config_imports.html -->
43+
<module name="UnusedImports"/>
44+
45+
<!-- Block checks - http://checkstyle.sourceforge.net/config_blocks.html -->
46+
<module name="LeftCurly">
47+
<property name="option" value="eol"/>
48+
</module>
49+
<module name="RightCurly">
50+
<property name="option" value="same"/>
51+
</module>
52+
<module name="NeedBraces"/>
53+
54+
<!-- Size checks - http://checkstyle.sourceforge.net/config_sizes.html -->
55+
<module name="LineLengthCheck">
56+
<property name="max" value="150"/>
57+
<property name="tabWidth" value="4"/>
58+
<property name="ignorePattern" value="^import"/>
59+
</module>
60+
61+
<!-- Metrics checks - http://checkstyle.sourceforge.net/config_metrics.html -->
62+
<module name="JavaNCSS">
63+
<property name="methodMaximum" value="70"/>
64+
<property name="classMaximum" value="500"/>
65+
</module>
66+
<module name="CyclomaticComplexity">
67+
<property name="max" value="15"/>
68+
</module>
69+
<!--<module name="NPathComplexity">-->
70+
<!--<property name="max" value="50"/>-->
71+
<!--</module>-->
72+
73+
<!-- Coding checks http://checkstyle.sourceforge.net/config_coding.html -->
74+
<module name="EqualsHashCode"/>
75+
<module name="SimplifyBooleanExpression"/>
76+
<module name="SimplifyBooleanReturn"/>
77+
<module name="StringLiteralEquality"/>
78+
<module name="NestedIfDepth">
79+
<property name="max" value="2"/>
80+
</module>
81+
<module name="NestedTryDepth">
82+
<property name="max" value="2"/>
83+
</module>
84+
<module name="NoFinalizer"/>
85+
86+
</module>
87+
88+
<module name="RegexpHeader">
89+
<property name="headerFile" value=".build/apache-copyright.header" />
90+
<property name="fileExtensions" value="java, groovy" />
91+
</module>
92+
</module>

pom.xml

+37-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@
8989
</execution>
9090
</executions>
9191
</plugin>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-checkstyle-plugin</artifactId>
95+
<version>3.0.0</version>
96+
<executions>
97+
<execution>
98+
<id>validate</id>
99+
<phase>validate</phase>
100+
<configuration>
101+
<configLocation>.build/checkstyle.xml</configLocation>
102+
<encoding>UTF-8</encoding>
103+
<consoleOutput>true</consoleOutput>
104+
<failsOnError>true</failsOnError>
105+
<linkXRef>false</linkXRef>
106+
</configuration>
107+
<goals>
108+
<goal>check</goal>
109+
</goals>
110+
</execution>
111+
</executions>
112+
</plugin>
92113
</plugins>
93114
<!-- enable resource filtering to replace variable references in test.properties -->
94115
<testResources>
@@ -98,5 +119,20 @@
98119
</testResource>
99120
</testResources>
100121
</build>
101-
122+
<reporting>
123+
<plugins>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-checkstyle-plugin</artifactId>
127+
<version>3.0.0</version>
128+
<reportSets>
129+
<reportSet>
130+
<reports>
131+
<report>checkstyle</report>
132+
</reports>
133+
</reportSet>
134+
</reportSets>
135+
</plugin>
136+
</plugins>
137+
</reporting>
102138
</project>

src/main/java/springfox/javadoc/configuration/JavadocPluginConfiguration.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
22
*
3-
* Copyright 2018 the original author or authors.
3+
* Copyright 2018-2019 the original author or authors.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6-
* use this file except in compliance with the License. You may obtain a copy of
7-
* the License at
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
88
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14-
* License for the specific language governing permissions and limitations under
15-
* the License.
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
1616
*
1717
*
1818
*/

src/main/java/springfox/javadoc/doclet/SwaggerPropertiesDoclet.java

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
/*
22
*
3-
* Copyright 2018 the original author or authors.
3+
* Copyright 2018-2019 the original author or authors.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6-
* use this file except in compliance with the License. You may obtain a copy of
7-
* the License at
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
88
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14-
* License for the specific language governing permissions and limitations under
15-
* the License.
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
1616
*
1717
*
1818
*/
1919
package springfox.javadoc.doclet;
2020

21+
import com.sun.javadoc.*;
22+
import springfox.javadoc.plugin.JavadocBuilderPlugin;
23+
2124
import java.io.File;
2225
import java.io.FileOutputStream;
2326
import java.io.IOException;
@@ -26,16 +29,6 @@
2629

2730
// the NOSONAR comment is added ignore sonar warning about usage of Sun classes
2831
// because doclets can only be written using Sun classes
29-
import com.sun.javadoc.AnnotationDesc;// NOSONAR
30-
import com.sun.javadoc.ClassDoc;
31-
import com.sun.javadoc.DocErrorReporter;
32-
import com.sun.javadoc.MethodDoc;
33-
import com.sun.javadoc.ParamTag;
34-
import com.sun.javadoc.RootDoc;
35-
import com.sun.javadoc.Tag;
36-
import com.sun.javadoc.ThrowsTag;
37-
38-
import springfox.javadoc.plugin.JavadocBuilderPlugin;
3932

4033
/**
4134
* Generate properties file based on Javadoc.

src/main/java/springfox/javadoc/plugin/JavadocBuilderPlugin.java

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
/*
22
*
3-
* Copyright 2018 the original author or authors.
3+
* Copyright 2018-2019 the original author or authors.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6-
* use this file except in compliance with the License. You may obtain a copy of
7-
* the License at
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
88
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14-
* License for the specific language governing permissions and limitations under
15-
* the License.
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
1616
*
1717
*
1818
*/
1919
package springfox.javadoc.plugin;
2020

21-
import java.lang.annotation.Annotation;
22-
import java.lang.reflect.Method;
23-
import java.util.HashSet;
24-
import java.util.Set;
25-
21+
import com.google.common.annotations.VisibleForTesting;
22+
import com.google.common.base.Optional;
2623
import org.springframework.beans.factory.annotation.Autowired;
2724
import org.springframework.core.Ordered;
2825
import org.springframework.core.annotation.Order;
2926
import org.springframework.core.env.Environment;
3027
import org.springframework.stereotype.Component;
3128
import org.springframework.util.StringUtils;
32-
33-
import com.google.common.annotations.VisibleForTesting;
34-
import com.google.common.base.Optional;
35-
3629
import springfox.documentation.builders.ResponseMessageBuilder;
3730
import springfox.documentation.schema.ModelRef;
3831
import springfox.documentation.schema.ModelReference;
@@ -45,6 +38,11 @@
4538
import springfox.documentation.spi.service.contexts.ParameterContext;
4639
import springfox.javadoc.doclet.SwaggerPropertiesDoclet;
4740

41+
import java.lang.annotation.Annotation;
42+
import java.lang.reflect.Method;
43+
import java.util.HashSet;
44+
import java.util.Set;
45+
4846
/**
4947
* Plugin to generate the @ApiParam and @ApiOperation values from the properties
5048
* file generated by the {@link SwaggerPropertiesDoclet}.

src/test/java/springfox/javadoc/doclet/SwaggerPropertiesDocletTest.java

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1+
/*
2+
*
3+
* Copyright 2018-2019 the original author or authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*
18+
*/
119
package springfox.javadoc.doclet;
220

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
5-
import static org.junit.Assert.assertNotNull;
6-
import static org.junit.Assert.assertTrue;
7-
8-
import java.io.BufferedReader;
9-
import java.io.FileInputStream;
10-
import java.io.IOException;
11-
import java.io.InputStream;
12-
import java.io.InputStreamReader;
13-
import java.util.Properties;
14-
21+
import com.sun.javadoc.DocErrorReporter;
22+
import com.sun.javadoc.SourcePosition;
1523
import org.junit.BeforeClass;
1624
import org.junit.Test;
1725

18-
import com.sun.javadoc.DocErrorReporter;
19-
import com.sun.javadoc.SourcePosition;
26+
import java.io.*;
27+
import java.util.Properties;
28+
29+
import static org.junit.Assert.*;
2030

2131
public class SwaggerPropertiesDocletTest {
2232

src/test/java/springfox/javadoc/example/TestController.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
*
3+
* Copyright 2018-2019 the original author or authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*
18+
*/
119
package springfox.javadoc.example;
220

321
import org.springframework.web.bind.annotation.GetMapping;

0 commit comments

Comments
 (0)