CheckStyleReporter
.
43 | *
44 | * @param healthy
45 | * Report health as 100% when the number of warnings is less than
46 | * this value
47 | * @param unHealthy
48 | * Report health as 0% when the number of warnings is greater
49 | * than this value
50 | * @param thresholdLimit
51 | * determines which warning priorities should be considered when
52 | * evaluating the build stability and health
53 | * @param useDeltaValues
54 | * determines whether the absolute annotations delta or the
55 | * actual annotations set difference should be used to evaluate
56 | * the build stability
57 | * @param unstableTotalAll
58 | * annotation threshold
59 | * @param unstableTotalHigh
60 | * annotation threshold
61 | * @param unstableTotalNormal
62 | * annotation threshold
63 | * @param unstableTotalLow
64 | * annotation threshold
65 | * @param unstableNewAll
66 | * annotation threshold
67 | * @param unstableNewHigh
68 | * annotation threshold
69 | * @param unstableNewNormal
70 | * annotation threshold
71 | * @param unstableNewLow
72 | * annotation threshold
73 | * @param failedTotalAll
74 | * annotation threshold
75 | * @param failedTotalHigh
76 | * annotation threshold
77 | * @param failedTotalNormal
78 | * annotation threshold
79 | * @param failedTotalLow
80 | * annotation threshold
81 | * @param failedNewAll
82 | * annotation threshold
83 | * @param failedNewHigh
84 | * annotation threshold
85 | * @param failedNewNormal
86 | * annotation threshold
87 | * @param failedNewLow
88 | * annotation threshold
89 | * @param canRunOnFailed
90 | * determines whether the plug-in can run for failed builds, too
91 | * @param usePreviousBuildAsReference
92 | * determines whether to always use the previous build as the reference build
93 | * @param useStableBuildAsReference
94 | * determines whether only stable builds should be used as reference builds or not
95 | * @param canComputeNew
96 | * determines whether new warnings should be computed (with
97 | * respect to baseline)
98 | */
99 | // CHECKSTYLE:OFF
100 | @SuppressWarnings("PMD.ExcessiveParameterList")
101 | @DataBoundConstructor
102 | public CheckStyleReporter(final String healthy, final String unHealthy, final String thresholdLimit, final boolean useDeltaValues,
103 | final String unstableTotalAll, final String unstableTotalHigh, final String unstableTotalNormal, final String unstableTotalLow,
104 | final String unstableNewAll, final String unstableNewHigh, final String unstableNewNormal, final String unstableNewLow,
105 | final String failedTotalAll, final String failedTotalHigh, final String failedTotalNormal, final String failedTotalLow,
106 | final String failedNewAll, final String failedNewHigh, final String failedNewNormal, final String failedNewLow,
107 | final boolean canRunOnFailed, final boolean usePreviousBuildAsReference,
108 | final boolean useStableBuildAsReference, final boolean canComputeNew) {
109 | super(healthy, unHealthy, thresholdLimit, useDeltaValues,
110 | unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
111 | unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
112 | failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
113 | failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
114 | canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference, canComputeNew, PLUGIN_NAME);
115 | }
116 | // CHECKSTYLE:ON
117 |
118 | @Override
119 | protected boolean acceptGoal(final String goal) {
120 | return "checkstyle".equals(goal) || "check".equals(goal) || "site".equals(goal);
121 | }
122 |
123 | @Override
124 | public ParserResult perform(final MavenBuildProxy build, final MavenProject pom,
125 | final MojoInfo mojo, final PluginLogger logger) throws InterruptedException, IOException {
126 | FilesParser checkstyleCollector = new FilesParser(PLUGIN_NAME,
127 | new CheckStyleParser(getDefaultEncoding()), getModuleName(pom));
128 |
129 | return getFileName(mojo, pom).act(checkstyleCollector);
130 | }
131 |
132 | private FilePath getFileName(final MojoInfo mojo, final MavenProject pom) {
133 | try {
134 | String configurationValue = mojo.getConfigurationValue("outputFile", String.class);
135 | if (StringUtils.isNotBlank(configurationValue)) {
136 | return new FilePath((VirtualChannel)null, configurationValue);
137 | }
138 | }
139 | catch (ComponentConfigurationException exception) {
140 | // ignore and use fall back value
141 | }
142 | return getTargetPath(pom).child(CHECKSTYLE_XML_FILE);
143 | }
144 |
145 | @Override
146 | protected CheckStyleResult createResult(final MavenBuild build, final ParserResult project) {
147 | return new CheckStyleReporterResult(build, getDefaultEncoding(), project,
148 | usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
149 | }
150 |
151 | @Override
152 | protected MavenAggregatedReport createMavenAggregatedReport(final MavenBuild build, final CheckStyleResult result) {
153 | return new CheckStyleMavenResultAction(build, this, getDefaultEncoding(), result);
154 | }
155 |
156 | @Override
157 | public ListCheckStyleReporterDescriptor
.
16 | */
17 | public CheckStyleReporterDescriptor() {
18 | super(CheckStyleReporter.class, new CheckStyleDescriptor());
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/checkstyle/CheckStyleReporterResult.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.checkstyle;
2 |
3 | import hudson.model.Run;
4 | import hudson.plugins.analysis.core.BuildResult;
5 | import hudson.plugins.analysis.core.ParserResult;
6 | import hudson.plugins.analysis.core.ResultAction;
7 |
8 | /**
9 | * Represents the aggregated results of the Checkstyle analysis in m2 jobs.
10 | *
11 | * @author Ulli Hafner
12 | */
13 | public class CheckStyleReporterResult extends CheckStyleResult {
14 | private static final long serialVersionUID = 6414012312137436141L;
15 |
16 | /**
17 | * Creates a new instance of {@link CheckStyleReporterResult}.
18 | *
19 | * @param build
20 | * the current build as owner of this action
21 | * @param defaultEncoding
22 | * the default encoding to be used when reading and parsing files
23 | * @param result
24 | * the parsed result with all annotations
25 | * @param usePreviousBuildAsReference
26 | * determines whether to use the previous build as the reference
27 | * build
28 | * @param useStableBuildAsReference
29 | * determines whether only stable builds should be used as
30 | * reference builds or not
31 | */
32 | public CheckStyleReporterResult(final Run, ?> build, final String defaultEncoding, final ParserResult result,
33 | final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
34 | super(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
35 | CheckStyleMavenResultAction.class);
36 | }
37 |
38 | @Override
39 | protected Class extends ResultAction extends BuildResult>> getResultActionType() {
40 | return CheckStyleMavenResultAction.class;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/checkstyle/CheckStyleResult.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.checkstyle;
2 |
3 | import com.thoughtworks.xstream.XStream;
4 |
5 | import hudson.model.Run;
6 | import hudson.plugins.analysis.core.BuildHistory;
7 | import hudson.plugins.analysis.core.BuildResult;
8 | import hudson.plugins.analysis.core.ParserResult;
9 | import hudson.plugins.analysis.core.ResultAction;
10 | import hudson.plugins.checkstyle.parser.Warning;
11 |
12 | /**
13 | * Represents the results of the Checkstyle analysis. One instance of this class
14 | * is persisted for each build via an XML file.
15 | *
16 | * @author Ulli Hafner
17 | */
18 | public class CheckStyleResult extends BuildResult {
19 | private static final long serialVersionUID = 2768250056765266658L;
20 |
21 | /**
22 | * Creates a new instance of {@link CheckStyleResult}.
23 | *
24 | * @param build
25 | * the current build as owner of this action
26 | * @param defaultEncoding
27 | * the default encoding to be used when reading and parsing files
28 | * @param result
29 | * the parsed result with all annotations
30 | * @param usePreviousBuildAsReference
31 | * determines whether to use the previous build as the reference
32 | * build
33 | * @param useStableBuildAsReference
34 | * determines whether only stable builds should be used as
35 | * reference builds or not
36 | */
37 | public CheckStyleResult(final Run, ?> build, final String defaultEncoding, final ParserResult result,
38 | final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
39 | this(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
40 | CheckStyleResultAction.class);
41 | }
42 |
43 | /**
44 | * Creates a new instance of {@link CheckStyleResult}.
45 | *
46 | * @param build
47 | * the current build as owner of this action
48 | * @param defaultEncoding
49 | * the default encoding to be used when reading and parsing files
50 | * @param result
51 | * the parsed result with all annotations
52 | * @param useStableBuildAsReference
53 | * determines whether only stable builds should be used as
54 | * reference builds or not
55 | * @param actionType
56 | * the type of the result action
57 | */
58 | protected CheckStyleResult(final Run, ?> build, final String defaultEncoding, final ParserResult result,
59 | final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
60 | final Class extends ResultActionsummary.jelly
file.
16 | * 17 | * Moreover, this class renders the Checkstyle result trend. 18 | *
19 | * 20 | * @author Ulli Hafner 21 | */ 22 | public class CheckStyleResultAction extends AbstractResultActionCheckStyleResultAction
.
25 | *
26 | * @param owner
27 | * the associated run of this action
28 | * @param healthDescriptor
29 | * health descriptor
30 | * @param result
31 | * the result in this build
32 | */
33 | public CheckStyleResultAction(final Run, ?> owner, final HealthDescriptor healthDescriptor,
34 | final CheckStyleResult result) {
35 | super(owner, new CheckStyleHealthDescriptor(healthDescriptor), result);
36 | }
37 |
38 | @Override
39 | public String getDisplayName() {
40 | return Messages.Checkstyle_ProjectAction_Name();
41 | }
42 |
43 | @Override
44 | protected PluginDescriptor getDescriptor() {
45 | return new CheckStyleDescriptor();
46 | }
47 |
48 | @Override
49 | public Collection extends Action> getProjectActions() {
50 | return asSet(new CheckStyleProjectAction(getJob()));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/checkstyle/MavenCheckStyleResultAction.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.checkstyle;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
7 |
8 | import hudson.maven.AggregatableAction;
9 | import hudson.maven.MavenAggregatedReport;
10 | import hudson.maven.MavenBuild;
11 | import hudson.maven.MavenModule;
12 | import hudson.maven.MavenModuleSet;
13 | import hudson.maven.MavenModuleSetBuild;
14 | import hudson.model.AbstractBuild;
15 | import hudson.model.Action;
16 | import hudson.plugins.analysis.core.HealthDescriptor;
17 | import hudson.plugins.analysis.core.ParserResult;
18 |
19 | /**
20 | * A {@link CheckStyleResultAction} for native maven jobs. This action
21 | * additionally provides result aggregation for sub-modules and for the main
22 | * project.
23 | *
24 | * @author Ulli Hafner
25 | * @deprecated not used anymore
26 | */
27 | @SuppressWarnings("deprecation")
28 | @Deprecated
29 | public class MavenCheckStyleResultAction extends CheckStyleResultAction implements AggregatableAction, MavenAggregatedReport {
30 | /** The default encoding to be used when reading and parsing files. */
31 | private final String defaultEncoding;
32 |
33 | /**
34 | * Creates a new instance of MavenCheckStyleResultAction
.
35 | *
36 | * @param owner
37 | * the associated build of this action
38 | * @param healthDescriptor
39 | * health descriptor to use
40 | * @param defaultEncoding
41 | * the default encoding to be used when reading and parsing files
42 | */
43 | public MavenCheckStyleResultAction(final AbstractBuild, ?> owner, final HealthDescriptor healthDescriptor,
44 | final String defaultEncoding) {
45 | super(owner, healthDescriptor, new CheckStyleResult(owner, defaultEncoding, new ParserResult(), false, false));
46 | this.defaultEncoding = defaultEncoding;
47 | }
48 |
49 | /**
50 | * Creates a new instance of MavenCheckStyleResultAction
.
51 | *
52 | * @param owner
53 | * the associated build of this action
54 | * @param healthDescriptor
55 | * health descriptor to use
56 | * @param result
57 | * the result in this build
58 | * @param defaultEncoding
59 | * the default encoding to be used when reading and parsing files
60 | */
61 | public MavenCheckStyleResultAction(final AbstractBuild, ?> owner, final HealthDescriptor healthDescriptor,
62 | final String defaultEncoding, final CheckStyleResult result) {
63 | super(owner, healthDescriptor, result);
64 | this.defaultEncoding = defaultEncoding;
65 | }
66 |
67 | @Override
68 | public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Maptrue
if this warning is valid or false
129 | * if the warning can't be processed by the checkstyle plug-in.
130 | *
131 | * @param file the file to check
132 | * @return true
if this warning is valid
133 | */
134 | private boolean isValidWarning(final hudson.plugins.checkstyle.parser.File file) {
135 | return !file.getName().endsWith("package.html");
136 | }
137 | }
138 |
139 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/checkstyle/parser/Error.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.checkstyle.parser;
2 |
3 | /**
4 | * Java Bean class for a violation of the Checkstyle format.
5 | *
6 | * @author Ulli Hafner
7 | */
8 | // CHECKSTYLE:OFF
9 | @SuppressWarnings("javadoc")
10 | public class Error {
11 | private String source;
12 | private String severity;
13 | private String message;
14 | private int line;
15 | private int column;
16 |
17 | public int getColumn() {
18 | return column;
19 | }
20 |
21 | public void setColumn(final int column) {
22 | this.column = column;
23 | }
24 |
25 | public String getSource() {
26 | return source;
27 | }
28 |
29 | public void setSource(final String source) {
30 | this.source = source;
31 | }
32 |
33 | public String getSeverity() {
34 | return severity;
35 | }
36 |
37 | public void setSeverity(final String severity) {
38 | this.severity = severity;
39 | }
40 |
41 | public String getMessage() {
42 | return message;
43 | }
44 |
45 | public void setMessage(final String message) {
46 | this.message = message;
47 | }
48 |
49 | public int getLine() {
50 | return line;
51 | }
52 |
53 | public void setLine(final int line) {
54 | this.line = line;
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/checkstyle/parser/File.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.checkstyle.parser;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 | import java.util.Collections;
6 | import java.util.List;
7 |
8 | /**
9 | * Java Bean class for a file of the Checkstyle format.
10 | *
11 | * @author Ulli Hafner
12 | */
13 | public class File {
14 | /** Name of the file. */
15 | private String name;
16 | /** All errors of this file. */
17 | private final List14 | * Note: this class has a natural ordering that is inconsistent with equals. 15 | *
16 | * 17 | * @author Ulli Hafner 18 | */ 19 | public class Warning extends AbstractAnnotation { 20 | /** Unique identifier of this class. */ 21 | private static final long serialVersionUID = 5171661552905752370L; 22 | /** Origin of the annotation. */ 23 | public static final String ORIGIN = "checkstyle"; 24 | 25 | /** 26 | * Creates a new instance of {@link Warning}. 27 | * 28 | * @param priority 29 | * the priority 30 | * @param message 31 | * the message of the warning 32 | * @param category 33 | * the warning category 34 | * @param type 35 | * the identifier of the warning type 36 | * @param start 37 | * the first line of the line range 38 | * @param end 39 | * the last line of the line range 40 | */ 41 | public Warning(final Priority priority, final String message, final String category, final String type, 42 | final int start, final int end) { 43 | super(priority, message, start, end, category, type); 44 | setOrigin(ORIGIN); 45 | } 46 | 47 | /** 48 | * Creates a new instance of {@link Warning}. 49 | * 50 | * @param priority 51 | * the priority 52 | * @param message 53 | * the message of the warning 54 | * @param category 55 | * the warning category 56 | * @param type 57 | * the identifier of the warning type 58 | * @param lineNumber 59 | * the line number of the warning in the corresponding file 60 | */ 61 | public Warning(final Priority priority, final String message, final String category, final String type, final int lineNumber) { 62 | this(priority, message, category, type, lineNumber, lineNumber); 63 | } 64 | 65 | @Override 66 | public String getToolTip() { 67 | return CheckStyleRules.getInstance().getDescription(getType()); 68 | } 69 | 70 | /** Not used anymore. @deprecated */ 71 | @SuppressWarnings("all") 72 | @SuppressFBWarnings("") 73 | @Deprecated 74 | private final transient String tooltip = StringUtils.EMPTY; // backward compatibility NOPMD 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/main/java/hudson/plugins/checkstyle/rules/CheckStyleRules.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.checkstyle.rules; 2 | 3 | import javax.xml.parsers.ParserConfigurationException; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.Collections; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.logging.Level; 13 | import java.util.logging.Logger; 14 | 15 | import org.apache.commons.lang.StringUtils; 16 | import org.xml.sax.SAXException; 17 | 18 | import hudson.plugins.analysis.util.SecureDigester; 19 | 20 | /** 21 | * Reads the meta data of the Checkstyle rules from the DocBook files of the Checkstyle distribution. 22 | * 23 | * @author Ulli Hafner 24 | */ 25 | public final class CheckStyleRules { 26 | /** Mapping of rule names to rules. */ 27 | private final Map
27 | File filter BeforeExecutionExclusionFileFilter
decides which files should be
28 | excluded from being processed by the utility.
29 |
31 | By default Checkstyle includes all files and sub-directories in a directory to be
32 | processed and checked for violations. Users could have files that are in these
33 | sub-directories that shouldn't be processed with their checkstyle configuration for
34 | various reasons, one of which is a valid Java file that won't pass Checkstyle's parser.
35 | When Checkstyle tries to parse a Java file and fails, it will throw an
36 | Exception
and halt parsing any more files for violations. An example of a
37 | valid Java file Checkstyle can't parse is JDK 9's module-info.java
.
38 | This file filter will exclude these problem files from being parsed,
39 | allowing the rest of the files to run normal and be validated.
40 |
42 | Note: When a file is excluded from the utility, it is excluded from all Checks and 43 | no testing for violations will be performed on them. 44 |
45 |name | 50 |description | 51 |type | 52 |default value | 53 |
---|---|---|---|
fileNamePattern | 56 |Regular expression to match the file name against. | 57 |Regular Expression | 58 |null |
59 |
64 | To configure the filter to exclude all 'module-info.java' files: 65 |
66 |com.puppycrawl.tools.checkstyle.filefilters
82 |
27 | Checks that a source file begins with a specified header. Property
28 | headerFile
specifies a file that contains
29 | the required header. Alternatively, the header specification can be
30 | set directly in the header
property
31 | without the need for an external file.
32 |
35 | Property ignoreLines
specifies the line
36 | numbers to ignore when matching lines in a header file. This
37 | property is very useful for supporting headers that contain
38 | copyright dates. For example, consider the following header:
39 |
50 | Since the year information will change over time, you can tell
51 | Checkstyle to ignore line 4 by setting property ignoreLines
to 4
.
52 |
name | 59 |description | 60 |type | 61 |default value | 62 |
---|---|---|---|
headerFile | 65 |name of the file containing the required header | 66 |URI | 67 |null |
68 |
charset | 71 |character encoding to use when reading the headerFile | 72 |string | 73 |the charset property of the parent 74 | Checker module | 75 |
header | 78 |
79 | the required header specified inline. Individual header lines
80 | must be separated by the string "\n" (even on platforms with a
81 | different line separator), see examples below.
82 | |
83 | string | 84 |null |
85 |
ignoreLines | 88 |line numbers to ignore | 89 |Integer Set | 90 |{} |
91 |
fileExtensions | 94 |file type extension of files to process | 95 |String Set | 96 |{} |
97 |
103 | In default configuration the check does not rise any violations. Default values of properties are used. 104 |
105 | 106 |
111 | To configure the check to use header file "config/java.header"
and ignore lines 2
, 3
, and 4
and only process Java files:
112 |
123 | To configure the check to verify that each file starts with the 124 | header 125 |
126 |132 | without the need for an external header file: 133 |
134 |163 | All messages can be customized if the default message doesn't suite you. 164 | Please see the documentation to learn how to. 165 |
166 |com.puppycrawl.tools.checkstyle.checks.header
170 |174 | Checker 175 |
176 |182 | Checks the header of a source file against a header that contains a 183 | regular 185 | expression for each line of the source header. 186 |
187 | 188 |189 | Rationale: In some projects checking against a 190 | fixed header is not sufficient, e.g. the header might require a 191 | copyright line where the year information is not static. 192 |
193 | 194 |195 | For example, consider the following header: 196 |
197 |215 | Lines 1 and 6 demonstrate a more compact notation for 71 '/' 216 | characters. Line 4 enforces that the copyright notice includes a 217 | four digit year. Line 5 is an example how to enforce revision 218 | control keywords in a file header. Lines 12-14 is a template for 219 | javadoc (line 13 is so complicated to remove conflict with and of 220 | javadoc comment). 221 |
222 | 223 |224 | Different programming languages have different comment syntax 225 | rules, but all of them start a comment with a non-word 226 | character. Hence you can often use the non-word character 227 | class to abstract away the concrete comment syntax and allow 228 | checking the header for different languages with a single 229 | header definition. For example, consider the following header 230 | specification (note that this is not the full Apache license 231 | header): 232 |
233 |243 | Lines 1 and 2 leave room for technical header lines, e.g. the 244 | "#!/bin/sh" line in Unix shell scripts, or the XML file header 245 | of XML files. Set the multiline property to "1, 2" so these 246 | lines can be ignored for file types where they do no apply. 247 | Lines 3 through 6 define the actual header content. Note how 248 | lines 2, 4 and 5 use escapes for characters that have special 249 | regexp semantics. 250 |
251 |name | 257 |description | 258 |type | 259 |default value | 260 |
---|---|---|---|
headerFile | 263 |name of the file containing the required header | 264 |URI | 265 |null |
266 |
charset | 269 |character encoding to use when reading the headerFile | 270 |string | 271 |the charset property of the parent 272 | Checker module | 273 |
header | 276 |
277 | the required header specified inline. Individual header lines
278 | must be separated by the string "\n" (even on platforms with a
279 | different line separator), and regular expressions must not span
280 | multiple lines.
281 | |
282 | string | 283 |null |
284 |
multiLines | 287 |line numbers to repeat (zero or more times) | 288 |Integer Set | 289 |{} |
290 |
fileExtensions | 293 |file type extension of files to process | 294 |String Set | 295 |{} |
296 |
302 | In default configuration the check does not rise any violations. Default values of properties are used. 303 |
304 |
309 | To configure the check to use header file "config/java.header"
and 10
and 13
muli-lines:
310 |
319 | To configure the check to verify that each file starts with the 320 | header 321 |
322 |328 | without the need for an external header file: 329 |
330 |
339 | Note: ignoreLines
property has been
340 | removed from this check to simplify it. To make some line optional
341 | use "^.*$" regexp for this line.
342 |
366 | All messages can be customized if the default message doesn't suite you. 367 | Please see the documentation to learn how to. 368 |
369 |373 | com.puppycrawl.tools.checkstyle.checks.header 374 |
375 |379 | Checker 380 |
381 |27 | Checks that the order of modifiers conforms to the suggestions in 28 | the Java 30 | Language specification, sections 8.1.1, 8.3.1, 8.4.3 and 32 | 9.4. The correct order is: 33 |
34 | 35 |public
38 | protected
41 | private
44 | abstract
47 | default
50 | static
53 | final
56 | transient
59 | volatile
62 | synchronized
65 | native
68 | strictfp
71 | 75 | ATTENTION: We skip 76 | type annotations from validation. 77 |
78 | 79 |To configure the check:
83 |117 | All messages can be customized if the default message doesn't suite you. 118 | Please see the documentation to learn how to. 119 |
120 |com.puppycrawl.tools.checkstyle.checks.modifier
124 |128 | TreeWalker 129 |
130 |137 | Checks for redundant modifiers in: 138 |
139 |interface
declarations that are declared
144 | as static
.
145 | enum
definitions that are declared
149 | as static
.
150 |
153 | Rationale: The Java Language Specification strongly
154 | discourages the usage of public
and abstract
for method
155 | declarations in interface definitions as a matter of style.
156 |
159 | Interfaces by definition are abstract so the abstract
160 | modifier on the interface is redundant.
161 |
164 | Classes inside of interfaces by definition are public and static,
165 | so the public
and static
modifiers
166 | on the inner classes are redundant. On the other hand, classes
167 | inside of interfaces can be abstract or non abstract.
168 | So, abstract
modifier is allowed.
169 |
172 | Fields in interfaces and annotations are automatically 173 | public, static and final, so these modifiers are redundant as 174 | well. 175 |
176 | 177 |178 | As annotations are a form of interface, their fields are also 179 | automatically public, static and final just as their 180 | annotation fields are automatically public and abstract. 181 |
182 | 183 |
184 | Enums by definition are static implicit subclasses of java.lang.Enum<E>.
185 | So, the static
modifier on the enums is redundant. In addition,
186 | if enum is inside of interface, public
modifier is also redundant.
187 |
190 | Enums can also contain abstract methods and methods which can be overridden by the declared 191 | enumeration fields. 192 | See the following example: 193 |
194 | 195 |209 | Since these methods can be overridden in these situations, the final methods are not 210 | marked as redundant even though they can't be extended by other classes/enums. 211 |
212 | 213 |
214 | Nested enum
types are always static by default.
215 |
218 | Final classes by definition cannot be extended so the final
219 | modifier on the method of a final class is redundant.
220 |
223 | Public modifier for constructors in non-public non-protected classes 224 | is always obsolete: 225 |
226 | 227 |There is no violation in the following example, 238 | because removing public modifier from ProtectedInnerClass 239 | constructor will make this code not compiling: 240 |
241 | 242 |name | 262 |description | 263 |type | 264 |default value | 265 |
---|---|---|---|
tokens | 268 |tokens to check | 269 |270 | subset of tokens 271 | METHOD_DEF, 272 | VARIABLE_DEF, 273 | ANNOTATION_FIELD_DEF, 274 | INTERFACE_DEF, 275 | CTOR_DEF, 276 | CLASS_DEF, 277 | ENUM_DEF, 278 | RESOURCE. 279 | | 280 |281 | METHOD_DEF, 282 | VARIABLE_DEF, 283 | ANNOTATION_FIELD_DEF, 284 | INTERFACE_DEF, 285 | CTOR_DEF, 286 | CLASS_DEF, 287 | ENUM_DEF, 288 | RESOURCE. 289 | | 290 |
To configure the check:
296 |301 | To configure the check to check only methods and not variables: 302 |
303 |331 | All messages can be customized if the default message doesn't suite you. 332 | Please see the documentation to learn how to. 333 |
334 |com.puppycrawl.tools.checkstyle.checks.modifier
338 |342 | TreeWalker 343 |
344 |
26 | The property checkstyle.cache.file
27 | specifies the name of a file that can be used to cache details
28 | of files that pass Checkstyle. This can significantly
29 | increase the speed of checkstyle on successive runs. The
30 | property type is string
31 | and defaults to an empty string (which means no caching is done).
32 |
37 | Checkstyle supports a mechanism for localising the output
38 | messages. If your language is not supported, please consider
39 | translating the messages in the messages.properties
file. Please let us
40 | know if you translate the file.
41 |
44 | The property checkstyle.locale.language
specifies the
45 | language to use in localising the output messages. The property
46 | type is string and
47 | defaults to the default system locale language.
48 |
51 | The property checkstyle.locale.country
52 | specifies the country to use in localising the output
53 | messages. The property type is string and defaults to the
55 | default system locale country.
56 |
61 | The property checkstyle.basedir
62 | specifies a base directory which files are then reported
63 | relative to. For example, if a base directory is specified as
64 | c:\projects\checkstyle
, then an error
65 | in the file c:\projects\checkstyle\src\dir\subdir\File.java
66 | will be reported as src\dir\subdir\File.java
. The property type
67 | is string and defaults
68 | to an empty string.
69 |
Jenkins understands Checkstyle
3 | analysis report XML format. When this option is configured and your
4 | build runs the maven goal checkstyle:checkstyle
then Jenkins
5 | provides useful information about analysis results, such as historical
6 | result trend, module and package statistics, web UI for viewing analysis
7 | reports and warnings, and so on.
This plug-in is not invoked for failed builds, it is only called for 9 | stable or unstable builds (i.e., a build with failed tests).
10 |Jenkins kann Checkstyle
3 | Reports einlesen und darstellen. Wenn dies aktiviert wird und der Build
4 | das Maven Goal checkstyle:checkstyle
ausführt, dann
5 | analysiert Jenkins nach jedem Build die erzeugten Checkstyle Dateien und
6 | stellt deren Informationen in verschiedenen Ansichten dar: Trend
7 | Anzeige, Projekt Statistik und Package Statistik. Zudem zeigt Jenkins die
8 | jeweiligen Warnungen direkt in der betroffen Datei an.
Das Plug-in wird nicht aufgerufen, wenn der Build fehlgeschlagen 10 | ist, sondern nur für stabile bzw. instabile Builds (mit fehlgeschlagenen Tests).
11 |Jenkinsは、CheckstyleのXML形式で生成された分析レポートを認識します。
3 | この機能を有効にし、ビルド実行時に、checkstyle:checkstyle
ゴールが実行されれば、
4 | 有用な情報が提供されるようになります。
5 | 検出数の推移、モジュール・パッケージごとの統計、web UIで分析結果のレポートや警告等を提供します。
このプラグインはビルドを失敗にすることはありません。 8 | 成功か不安定(つまりテスト失敗のビルド)かを判定するだけです。
9 | 10 | -------------------------------------------------------------------------------- /src/main/webapp/help.html: -------------------------------------------------------------------------------- 1 |Jenkins understands Checkstyle 3 | analysis report XML format. When this option is configured Jenkins shows 4 | the Checkstyle analysis results in different views: historical result 5 | trend, module and package statistics, web UI for viewing analysis 6 | reports and warnings, and so on.
7 |You need to set up your build to run Checkstyle in order to use 8 | this feature - this Jenkins plug-in does not perform the actual analysis! 9 | This plug-in is not invoked for failed builds, it is only called for 10 | stable or unstable builds (i.e., a build with failed tests).
11 |Jenkins kann Checkstyle 3 | Reports einlesen und darstellen. Wenn dieses Plug-in aktiviert wird, 4 | analysiert Jenkins nach jedem Build die erzeugten Checkstyle Dateien und 5 | stellt deren Informationen in verschiedenen Ansichten dar: Trend 6 | Anzeige, Projekt und Package Statistiken, usw. Zudem zeigt Jenkins die 7 | jeweiligen Warnungen direkt in der betroffen Datei an.
8 |Damit das Plug-in korrekt funktioniert, muss im Build 9 | Checkstyle gestartet werden - das Jenkins Plug-in selbst macht dies 10 | nicht! Das Plug-in wird nicht aufgerufen, wenn der Build fehlgeschlagen 11 | ist, sondern nur für stabile bzw. instabile Builds (mit fehlgeschlagenen 12 | Tests).
13 |Jenkinsは、CheckstyleのXML形式で生成された分析レポートを認識します。 3 | このオプションが設定されると、Checkstyleの分析結果を、 4 | 検出数の推移、モジュール・パッケージごとの統計、web UIでの分析レポートや警告等の様々な形式で提供します。
5 |この機能を使うためにはビルド実行時に、Checkstyleが実行されるようビルドを設定する必要があります。 6 | このプラグインが実際の分析を行う訳ではありません。 7 | また、このプラグインはビルドを失敗にすることはありません。 8 | 成功か不安定(つまりテスト失敗のビルド)かを判定するだけです。
9 |Checks for empty blocks.
", reader.getRule("EmptyBlock").getDescription()); 25 | assertNotSame("No description for AnnotationUseStyle found.", Rule.UNDEFINED_DESCRIPTION, reader.getRule("AnnotationUseStyle").getDescription()); 26 | assertNotSame("No description for AnnotationUseStyle found.", Rule.UNDEFINED_DESCRIPTION, reader.getDescription("AnnotationUseStyle")); 27 | assertSame("No default text available for undefined rule.", Rule.UNDEFINED_DESCRIPTION, reader.getRule("Undefined").getDescription()); 28 | 29 | for (Rule rule : reader.getRules()) { 30 | assertNotEquals("Rule " + rule.getName() + " has no description.", Rule.UNDEFINED_DESCRIPTION, rule.getDescription()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/resources/hudson/plugins/checkstyle/parser/checkstyle-result-build1.xml: -------------------------------------------------------------------------------- 1 | 2 |