Skip to content

Commit eeffb0d

Browse files
authored
Merge pull request BruceEckel#21 from bmuschko/static-code-analysis
Static code analysis
2 parents 3b71a73 + 5960d4d commit eeffb0d

6 files changed

Lines changed: 219 additions & 30 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ and run the Java examples in the book.
77

88
To compile everything, the command is:
99

10-
`gradlew build`
10+
`gradlew classes`
1111

1212
To run everything (including compiling if necessary), the command is:
1313

1414
`gradlew run`
1515

1616
To compile only a single chapter (including dependencies), use for example:
1717

18-
`gradlew :strings:build`
18+
`gradlew :strings:classes`
1919

2020
To run only a single chapter, say:
2121

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ subprojects {
1616
apply from: "$rootProject.projectDir/gradle/java.gradle"
1717
apply from: "$rootProject.projectDir/gradle/junit-jupiter.gradle"
1818
apply from: "$rootProject.projectDir/gradle/jmh.gradle"
19-
apply from: "$rootProject.projectDir/gradle/code-analysis.gradle"
19+
apply from: "$rootProject.projectDir/gradle/checkstyle.gradle"
20+
apply from: "$rootProject.projectDir/gradle/findbugs.gradle"
2021
apply plugin: 'com.mindviewinc.tagging'
2122
}
2223

gradle/checkstyle.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apply plugin: 'checkstyle'
2+
3+
checkstyle {
4+
ignoreFailures = true
5+
configFile = new File(rootProject.projectDir, 'sun_checks.xml')
6+
}
7+
8+
tasks.withType(Checkstyle) {
9+
reports {
10+
xml.enabled = false
11+
html.enabled = true
12+
}
13+
}
14+
15+
task checkstyle {
16+
group = 'Verification'
17+
description = 'Runs Checkstyle analysis for all classes.'
18+
dependsOn tasks.withType(Checkstyle)
19+
}

gradle/code-analysis.gradle

Lines changed: 0 additions & 27 deletions
This file was deleted.

gradle/findbugs.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apply plugin: 'findbugs'
2+
3+
findbugs {
4+
ignoreFailures = true
5+
}
6+
7+
tasks.withType(FindBugs) {
8+
reports {
9+
xml.enabled = false
10+
html.enabled = true
11+
}
12+
}
13+
14+
task findbugs {
15+
group = 'Verification'
16+
description = 'Runs FindBugs analysis for all classes.'
17+
dependsOn tasks.withType(FindBugs)
18+
}

sun_checks.xml

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5+
6+
<!--
7+
8+
Checkstyle configuration that checks the sun coding conventions from:
9+
10+
- the Java Language Specification at
11+
http://java.sun.com/docs/books/jls/second_edition/html/index.html
12+
13+
- the Sun Code Conventions at http://java.sun.com/docs/codeconv/
14+
15+
- the Javadoc guidelines at
16+
http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
17+
18+
- the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
19+
20+
- some best practices
21+
22+
Checkstyle is very configurable. Be sure to read the documentation at
23+
http://checkstyle.sf.net (or in your downloaded distribution).
24+
25+
Most Checks are configurable, be sure to consult the documentation.
26+
27+
To completely disable a check, just comment it out or delete it from the file.
28+
29+
Finally, it is worth reading the documentation.
30+
31+
-->
32+
33+
<module name="Checker">
34+
<!--
35+
If you set the basedir property below, then all reported file
36+
names will be relative to the specified directory. See
37+
http://checkstyle.sourceforge.net/5.x/config.html#Checker
38+
39+
<property name="basedir" value="${basedir}"/>
40+
-->
41+
42+
<!-- Checks that a package-info.java file exists for each package. -->
43+
<!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
44+
<module name="JavadocPackage"/>
45+
46+
<!-- Checks whether files end with a new line. -->
47+
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
48+
<module name="NewlineAtEndOfFile"/>
49+
50+
<!-- Checks that property files contain the same keys. -->
51+
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
52+
<module name="Translation"/>
53+
54+
<!-- Checks for Size Violations. -->
55+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
56+
<module name="FileLength"/>
57+
58+
<!-- Checks for whitespace -->
59+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
60+
<module name="FileTabCharacter"/>
61+
62+
<!-- Miscellaneous other checks. -->
63+
<!-- See http://checkstyle.sf.net/config_misc.html -->
64+
<module name="RegexpSingleline">
65+
<property name="format" value="\s+$"/>
66+
<property name="minimum" value="0"/>
67+
<property name="maximum" value="0"/>
68+
<property name="message" value="Line has trailing spaces."/>
69+
</module>
70+
71+
<!-- Checks for Headers -->
72+
<!-- See http://checkstyle.sf.net/config_header.html -->
73+
<!-- <module name="Header"> -->
74+
<!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
75+
<!-- <property name="fileExtensions" value="java"/> -->
76+
<!-- </module> -->
77+
78+
<module name="TreeWalker">
79+
80+
<!-- Checks for Javadoc comments. -->
81+
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
82+
<module name="JavadocMethod"/>
83+
<module name="JavadocType"/>
84+
<module name="JavadocVariable"/>
85+
<module name="JavadocStyle"/>
86+
87+
88+
<!-- Checks for Naming Conventions. -->
89+
<!-- See http://checkstyle.sf.net/config_naming.html -->
90+
<module name="ConstantName"/>
91+
<module name="LocalFinalVariableName"/>
92+
<module name="LocalVariableName"/>
93+
<module name="MemberName"/>
94+
<module name="MethodName"/>
95+
<module name="PackageName"/>
96+
<module name="ParameterName"/>
97+
<module name="StaticVariableName"/>
98+
<module name="TypeName"/>
99+
100+
101+
<!-- Checks for imports -->
102+
<!-- See http://checkstyle.sf.net/config_import.html -->
103+
<module name="AvoidStarImport"/>
104+
<module name="IllegalImport"/>
105+
<!-- defaults to sun.* packages -->
106+
<module name="RedundantImport"/>
107+
<module name="UnusedImports"/>
108+
109+
110+
<!-- Checks for Size Violations. -->
111+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
112+
<module name="LineLength"/>
113+
<module name="MethodLength"/>
114+
<module name="ParameterNumber"/>
115+
116+
117+
<!-- Checks for whitespace -->
118+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
119+
<module name="EmptyForIteratorPad"/>
120+
<module name="GenericWhitespace"/>
121+
<module name="MethodParamPad"/>
122+
<module name="NoWhitespaceAfter"/>
123+
<module name="NoWhitespaceBefore"/>
124+
<module name="OperatorWrap"/>
125+
<module name="ParenPad"/>
126+
<module name="TypecastParenPad"/>
127+
<module name="WhitespaceAfter"/>
128+
<module name="WhitespaceAround"/>
129+
130+
131+
<!-- Modifier Checks -->
132+
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
133+
<module name="ModifierOrder"/>
134+
<module name="RedundantModifier"/>
135+
136+
137+
<!-- Checks for blocks. You know, those {}'s -->
138+
<!-- See http://checkstyle.sf.net/config_blocks.html -->
139+
<module name="AvoidNestedBlocks"/>
140+
<module name="EmptyBlock"/>
141+
<module name="LeftCurly"/>
142+
<module name="NeedBraces"/>
143+
<module name="RightCurly"/>
144+
145+
146+
<!-- Checks for common coding problems -->
147+
<!-- See http://checkstyle.sf.net/config_coding.html -->
148+
<module name="AvoidInlineConditionals"/>
149+
<module name="EmptyStatement"/>
150+
<module name="EqualsHashCode"/>
151+
<module name="HiddenField"/>
152+
<module name="IllegalInstantiation"/>
153+
<module name="InnerAssignment"/>
154+
<module name="MagicNumber"/>
155+
<module name="MissingSwitchDefault"/>
156+
<module name="RedundantThrows"/>
157+
<module name="SimplifyBooleanExpression"/>
158+
<module name="SimplifyBooleanReturn"/>
159+
160+
<!-- Checks for class design -->
161+
<!-- See http://checkstyle.sf.net/config_design.html -->
162+
<module name="DesignForExtension"/>
163+
<module name="FinalClass"/>
164+
<module name="HideUtilityClassConstructor"/>
165+
<module name="InterfaceIsType"/>
166+
<module name="VisibilityModifier"/>
167+
168+
169+
<!-- Miscellaneous other checks. -->
170+
<!-- See http://checkstyle.sf.net/config_misc.html -->
171+
<module name="ArrayTypeStyle"/>
172+
<module name="FinalParameters"/>
173+
<module name="TodoComment"/>
174+
<module name="UpperEll"/>
175+
176+
</module>
177+
178+
</module>

0 commit comments

Comments
 (0)