Skip to content

Commit 2857b3e

Browse files
committed
Issue #112: upgrade to checkstyle 7.8.2
1 parent 4ff44a9 commit 2857b3e

File tree

4 files changed

+15
-295
lines changed

4 files changed

+15
-295
lines changed

checkstyle-sonar-plugin/src/main/resources/org/sonar/l10n/checkstyle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck.pa
215215
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck.param.applyToPublic=Controls whether to apply the check to public member.
216216
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck.name=Modifier Order
217217
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.coding.ExplicitInitializationCheck.name=Explicit Initialization
218+
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.coding.ExplicitInitializationCheck.param.onlyObjectReferences=Whether only explicit initializations made to null for objects should be checked
218219
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.StaticVariableNameCheck.name=Static Variable Name
219220
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.StaticVariableNameCheck.param.applyToProtected=Controls whether to apply the check to protected member
220221
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.StaticVariableNameCheck.param.applyToPrivate=Controls whether to apply the check to private member
@@ -249,6 +250,8 @@ rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForIterat
249250
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForIteratorPadCheck.param.option=policy on how to pad an empty for iterator
250251
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck.name=Illegal Import
251252
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck.param.illegalPkgs=packages to reject
253+
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck.param.illegalClasses=Class names to reject
254+
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck.param.regexp=Controls whether the packages or class names should be interpreted as regular expressions
252255
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck.name=Comment pattern matcher
253256
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck.param.format=Regular expression pattern to check. Default is TODO:
254257
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.coding.MultipleVariableDeclarationsCheck.name=Multiple Variable Declarations
Original file line numberDiff line numberDiff line change
@@ -1,295 +1,5 @@
11
<div >
22
<div class="section">
3-
<h2><a name="ImportControl"></a>ImportControl<span class="anchor"><a href="http://checkstyle.sourceforge.net/config_imports.html#ImportControl"><img src="images/anchor.png"></a></span></h2>
4-
5-
<div class="section">
6-
<h3><a name="Description"></a>Description</h3>
7-
8-
<p>
9-
Controls what can be imported in each package. Useful for
10-
ensuring that application layering rules are not violated,
11-
especially on large projects.
12-
</p>
13-
14-
15-
<p>
16-
The DTD for a import control XML document is at <a class="externalLink" href="http://checkstyle.sourceforge.net/dtds/import_control_1_2.dtd">
17-
http://checkstyle.sourceforge.net/dtds/import_control_1_2.dtd</a>. It
18-
contains documentation on each of the elements and attributes.
19-
</p>
20-
21-
22-
<p>
23-
The check validates a XML document when it loads the document.
24-
To validate against the above DTD, include the following
25-
document type declaration in your XML document:
26-
</p>
27-
28-
29-
<div>
30-
<pre>&lt;!DOCTYPE import-control PUBLIC
31-
"-//Puppy Crawl//DTD Import Control 1.2//EN"
32-
"http://checkstyle.sourceforge.net/dtds/import_control_1_2.dtd"&gt;
33-
</pre></div>
34-
</div>
35-
36-
37-
<div class="section">
38-
<h3><a name="Properties"></a>Properties</h3>
39-
40-
<table class="bodyTable" border="0">
41-
42-
<tbody><tr class="a">
43-
44-
<th>name</th>
45-
46-
<th>description</th>
47-
48-
<th>type</th>
49-
50-
<th>default value</th>
51-
</tr>
52-
53-
<tr class="b">
54-
55-
<td>file</td>
56-
57-
<td>
58-
The location of the file containing the import control configuration.
59-
It can be a regular file, URL or resource path. It will try loading
60-
the path as a URL first, then as a file, and finally as a resource.
61-
</td>
62-
63-
<td><a href="property_types.html#uri">URI</a></td>
64-
65-
<td><code>null</code></td>
66-
</tr>
67-
68-
<tr class="a">
69-
70-
<td>url</td>
71-
72-
<td>
73-
URL of the file containing the import control configuration.
74-
This property is deprecated. Please use the file property to load configurations
75-
from URLs.
76-
</td>
77-
78-
<td><a href="property_types.html#uri">URI</a></td>
79-
80-
<td><code>null</code></td>
81-
</tr>
82-
83-
<tr class="b">
84-
85-
<td>path</td>
86-
87-
<td>
88-
Regular expression of file paths to which this check should apply. Files that
89-
don't match the pattern will not be checked. The pattern will be matched against
90-
the full absolute file path.
91-
</td>
92-
93-
<td><a href="property_types.html#regexp">Regular Expression</a></td>
94-
95-
<td><code>".*"</code></td>
96-
</tr>
97-
</tbody></table>
98-
</div>
99-
100-
101-
<div class="section">
102-
<h3><a name="Examples"></a>Examples</h3>
103-
104-
<p>
105-
To configure the check using an import control file called
106-
"config/import-control.xml", then have the following:
107-
</p>
108-
109-
110-
<div class="source">
111-
<pre>&lt;module name="ImportControl"&gt;
112-
&lt;property name="file" value="config/import-control.xml"/&gt;
113-
&lt;/module&gt;
114-
</pre></div>
115-
116-
117-
<p>
118-
To configure the check to only check the "src/main" directory
119-
using an import control file called "config/import-control.xml",
120-
then have the following:
121-
</p>
122-
123-
124-
<div class="source">
125-
<pre>&lt;module name="ImportControl"&gt;
126-
&lt;property name="file" value="config/import-control.xml"/&gt;
127-
&lt;property name="path" value="^.*[\\/]src[\\/]main[\\/].*$"/&gt;
128-
&lt;/module&gt;
129-
</pre></div>
130-
131-
132-
<p>
133-
In the example below access to package
134-
<code>com.puppycrawl.tools.checkstyle.checks</code> and its subpackages is
135-
allowed from anywhere in <code>com.puppycrawl.tools.checkstyle</code> except
136-
from the <code>filters</code> subpackage where access to all
137-
<code>check</code>'s subpackages is disallowed. Two <code>java.lang.ref</code>
138-
classes are allowed by virtue of one regular expression instead of listing
139-
them in two separate allow rules (as it is done with the <code>Files</code>
140-
and <code>ClassPath</code> classes).
141-
</p>
142-
143-
144-
<div class="source">
145-
<pre>&lt;import-control pkg="com.puppycrawl.tools.checkstyle"&gt;
146-
&lt;allow pkg="com.puppycrawl.tools.checkstyle.api"/&gt;
147-
&lt;allow pkg="com.puppycrawl.tools.checkstyle.checks"/&gt;
148-
&lt;allow class="com.google.common.io.Files"/&gt;
149-
&lt;allow class="com.google.common.reflect.ClassPath"/&gt;
150-
&lt;subpackage name="filters"&gt;
151-
&lt;allow class="java\.lang\.ref\.(Weak|Soft)Reference"
152-
regex="true"/&gt;
153-
&lt;disallow pkg="com\.puppycrawl\.tools\.checkstyle\.checks\.[^.]+"
154-
regex="true"/&gt;
155-
&lt;disallow pkg="com.puppycrawl.tools.checkstyle.ant"/&gt;
156-
&lt;disallow pkg="com.puppycrawl.tools.checkstyle.doclets"/&gt;
157-
&lt;disallow pkg="com.puppycrawl.tools.checkstyle.gui"/&gt;
158-
&lt;/subpackage&gt;
159-
&lt;/import-control&gt;
160-
</pre></div>
161-
162-
163-
<p>
164-
In the next example regular expressions are used to enforce a layering rule: In all
165-
<code>dao</code> packages it is not allowed to access UI layer code (<code>ui</code>,
166-
<code>awt</code>, and <code>swing</code>). On the other hand it is not allowed to directly
167-
access <code>dao</code> and <code>service</code> layer from <code>ui</code> packages. The
168-
root package is also a regular expression that is used to handle old and new domain name
169-
with the same rules.
170-
</p>
171-
172-
173-
<div class="source">
174-
<pre>&lt;import-control pkg="(de.olddomain|de.newdomain)\..*" regex="true"&gt;
175-
&lt;subpackage pkg="[^.]+\.dao" regex="true"&gt;
176-
&lt;disallow pkg=".*\.ui" regex="true"/&gt;
177-
&lt;disallow pkg=".*\.(awt|swing).\.*" regex="true"/&gt;
178-
&lt;/subpackage&gt;
179-
&lt;subpackage pkg="[^.]+\.ui" regex="true"&gt;
180-
&lt;disallow pkg=".*\.(dao|service)" regex="true"/&gt;
181-
&lt;/subpackage&gt;
182-
&lt;/import-control&gt;
183-
</pre></div>
184-
185-
186-
<p>
187-
For a real-life import control file look at the file called <a class="externalLink" href="https://github.com/checkstyle/checkstyle/blob/master/config/import-control.xml">
188-
import-control.xml</a>
189-
which is part of the Checkstyle distribution.
190-
</p>
191-
192-
193-
<div class="section">
194-
<h4 id="regex-notes">Notes on regular expressions</h4>
195-
196-
<p>
197-
Regular expressions in import rules have to match either Java packages or
198-
classes. The language rules for packages and class names can be described by the
199-
following complicated regular expression that takes into account that Java names may
200-
contain any unicode letter, numbers, underscores, and dollar signs (see section 3.8
201-
in the <a class="externalLink" href="http://docs.oracle.com/javase/specs/">Java specs</a>):
202-
</p>
203-
204-
<ul>
205-
206-
<li>
207-
<code>[\p{Letter}_$][\p{Letter}\p{Number}_$]*</code> or short
208-
<code>[\p{L}_$][\p{L}\p{N}_$]*</code> for a class name or package component.
209-
</li>
210-
211-
<li>
212-
<code>([\p{L}_$][\p{L}\p{N}_$]*\.)*[\p{L}_$][\p{L}\p{N}_$]*</code>
213-
for a fully qualified name.
214-
</li>
215-
</ul>
216-
217-
<p>
218-
But it is not necessary to use these complicated expressions since no validation is
219-
required. Differentiating between package separator '.' and others is
220-
sufficient. Unfortunately '.' has a special meaning in regular expressions so one has
221-
to write <code>\.</code> to match an actual dot.
222-
</p>
223-
224-
<ul>
225-
226-
<li>
227-
Use <code>[^.]+</code> (one or more "not a dot" characters) for a class name or
228-
package component.
229-
</li>
230-
231-
<li>
232-
Use <code>com\.google\.common\.[^.]+</code> to match any subpackage of
233-
<code>com.google.common</code>.
234-
</li>
235-
236-
<li>
237-
When matching concrete packages like <code>com.google.common</code> omitting the
238-
backslash before the dots may improve readability and may be just exact enough:
239-
<code>com.google.common\.[^.]+</code> matches not only subpackages of
240-
<code>com.google.common</code> but e.g. also of <code>com.googleecommon</code> but
241-
you may not care for that.
242-
</li>
243-
244-
<li>
245-
Do not use <code>.*</code> unless you really do not care for what is matched. Often
246-
you want to match only a certain package level instead.
247-
</li>
248-
</ul>
249-
</div></div>
250-
251-
252-
<div class="section">
253-
<h3><a name="Example_of_Usage"></a>Example of Usage</h3>
254-
255-
<ul>
256-
257-
<li>
258-
<a class="externalLink" href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ImportControl">
259-
Checkstyle Style</a>
260-
</li>
261-
</ul>
262-
</div>
263-
264-
265-
<div class="section">
266-
<h3><a name="Error_Messages"></a>Error Messages</h3>
267-
268-
<ul>
269-
270-
<li>
271-
<a class="externalLink" href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fimports+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22import.control.disallowed%22">
272-
import.control.disallowed</a>
273-
</li>
274-
275-
<li>
276-
<a class="externalLink" href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fimports+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22import.control.missing.file%22">
277-
import.control.missing.file</a>
278-
</li>
279-
280-
<li>
281-
<a class="externalLink" href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fimports+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22import.control.unknown.pkg%22">
282-
import.control.unknown.pkg</a>
283-
</li>
284-
</ul>
285-
286-
<p>
287-
All messages can be customized if the default message doesn't suite you.
288-
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
289-
</p>
290-
</div>
291-
292-
293-
3+
see full documentation at <a href="http://checkstyle.sourceforge.net/config_imports.html#ImportControl">ImportControl</a>
2944
</div>
2955
</div>

checkstyle-sonar-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@
526526
<priority>MAJOR</priority>
527527
<name><![CDATA[Explicit Initialization]]></name>
528528
<configKey><![CDATA[Checker/TreeWalker/ExplicitInitialization]]></configKey>
529+
<param key="onlyObjectReferences" type="BOOLEAN">
530+
</param>
529531
<status>READY</status>
530532
</rule>
531533

@@ -634,6 +636,11 @@
634636
<configKey><![CDATA[Checker/TreeWalker/IllegalImport]]></configKey>
635637
<param key="illegalPkgs" type="s{}">
636638
</param>
639+
<param key="illegalClasses" type="s{}">
640+
</param>
641+
<param key="regexp" type="BOOLEAN">
642+
<defaultValue>false</defaultValue>
643+
</param>
637644
<status>READY</status>
638645
</rule>
639646

@@ -967,8 +974,8 @@
967974
<param key="format" type="REGULAR_EXPRESSION">
968975
<defaultValue>^[a-z][a-zA-Z0-9]*$</defaultValue>
969976
</param>
970-
<param key="tokens" type="s[VARIABLE_DEF,PARAMETER_DEF]">
971-
<defaultValue>VARIABLE_DEF,PARAMETER_DEF</defaultValue>
977+
<param key="tokens" type="s[VARIABLE_DEF,PARAMETER_DEF,RESOURCE]">
978+
<defaultValue>VARIABLE_DEF,PARAMETER_DEF,RESOURCE</defaultValue>
972979
</param>
973980
<status>READY</status>
974981
</rule>
@@ -1225,7 +1232,7 @@
12251232
<param key="allowLineBreaks" type="BOOLEAN">
12261233
<defaultValue>true</defaultValue>
12271234
</param>
1228-
<param key="tokens" type="s[ARRAY_INIT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,TYPECAST,ARRAY_DECLARATOR,INDEX_OP,LITERAL_SYNCHRONIZED]">
1235+
<param key="tokens" type="s[ARRAY_INIT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,TYPECAST,ARRAY_DECLARATOR,INDEX_OP,LITERAL_SYNCHRONIZED,METHOD_REF]">
12291236
<defaultValue>ARRAY_INIT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP</defaultValue>
12301237
</param>
12311238
</rule>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</ciManagement>
8686

8787
<properties>
88-
<checkstyle.version>7.7</checkstyle.version>
88+
<checkstyle.version>7.8.2</checkstyle.version>
8989
<sonar.version>5.6.6</sonar.version>
9090
<sonar-java.version>3.7</sonar-java.version>
9191
<java.version>1.8</java.version>

0 commit comments

Comments
 (0)