Skip to content

Commit 331fd42

Browse files
committed
Issue #124: upgrade to checkstyle 8.2
1 parent 725aca3 commit 331fd42

File tree

21 files changed

+54
-36
lines changed

21 files changed

+54
-36
lines changed

checkstyle-all/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
<goal>shade</goal>
5656
</goals>
5757
<configuration>
58+
<filters>
59+
<filter>
60+
<artifact>*:*</artifact>
61+
<excludes>
62+
<exclude>META-INF/*.SF</exclude>
63+
<exclude>META-INF/*.DSA</exclude>
64+
<exclude>META-INF/*.RSA</exclude>
65+
</excludes>
66+
</filter>
67+
</filters>
5868
<shadedArtifactAttached>true</shadedArtifactAttached>
5969
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
6070
<artifactSet>

checkstyle-sonar-plugin/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<groupId>xmlunit</groupId>
9595
<artifactId>xmlunit</artifactId>
9696
<scope>test</scope>
97-
<version>1.4</version>
97+
<version>1.6</version>
9898
</dependency>
9999
<!--
100100
We need following dependency, otherwise we will receive
@@ -308,7 +308,7 @@
308308
</regex>
309309
<regex>
310310
<pattern>org.sonar.plugins.checkstyle.CheckstyleProfileImporter</pattern>
311-
<branchRate>97</branchRate>
311+
<branchRate>96</branchRate>
312312
<lineRate>100</lineRate>
313313
</regex>
314314
<regex>
@@ -376,7 +376,7 @@
376376
<configuration>
377377
<rules>
378378
<requireFilesSize>
379-
<maxsize>10000000</maxsize>
379+
<maxsize>20000000</maxsize>
380380
<minsize>5000000</minsize>
381381
<files>
382382
<file>${project.build.directory}/${project.build.finalName}.jar</file>

checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ private static void appendCheckerModules(Writer writer,
107107
private void appendTreeWalker(Writer writer,
108108
Map<String, List<ActiveRule>> activeRulesByConfigKey) throws IOException {
109109
writer.append("<module name=\"TreeWalker\">");
110-
writer.append("<module name=\"FileContentsHolder\"/> ");
111110
if (isSuppressWarningsEnabled()) {
112111
writer.append("<module name=\"SuppressWarningsHolder\"/> ");
113112
}

checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ else if (!isIgnored(moduleName)) {
148148

149149
@VisibleForTesting
150150
static boolean isIgnored(String configKey) {
151-
return StringUtils.equals(configKey, "FileContentsHolder")
152-
|| StringUtils.equals(configKey, "SuppressWarningsHolder");
151+
return StringUtils.equals(configKey, "SuppressWarningsHolder");
153152
}
154153

155154
@VisibleForTesting

checkstyle-sonar-plugin/src/main/resources/com/sonar/sqale/checkstyle-model.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@
292292
<txt>min</txt>
293293
</prop>
294294
</chc>
295+
<chc>
296+
<rule-repo>checkstyle</rule-repo>
297+
<rule-key>com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationOnSameLineCheck</rule-key>
298+
<prop>
299+
<key>remediationFunction</key>
300+
<txt>CONSTANT_ISSUE</txt>
301+
</prop>
302+
<prop>
303+
<key>offset</key>
304+
<val>2</val>
305+
<txt>min</txt>
306+
</prop>
307+
</chc>
295308
<chc>
296309
<rule-repo>checkstyle</rule-repo>
297310
<rule-key>com.puppycrawl.tools.checkstyle.checks.coding.DeclarationOrderCheck</rule-key>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.MissingOverrideCheck.name=Missing Override
22
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.MissingOverrideCheck.param.javaFiveCompatibility=When this property is true this check will only check classes, interfaces, etc. that do not contain the extends or implements keyword or are not anonymous classes. This means it only checks methods overridden from java.lang.Object Java 5 Compatibility mode severely limits this check. It is recommended to only use it on Java 5 source.
3+
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationOnSameLineCheck.name=Annotation On Same Line
4+
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationOnSameLineCheck.param.tokens=tokens to check
35
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck.name=Equals Avoid Null
46
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck.param.ignoreEqualsIgnoreCase=whether to ignore String.equalsIgnoreCase() invocations. Default is false.
57
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck.name=Javadoc Package
@@ -405,7 +407,6 @@ rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck.
405407
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck.param.format=Regular expression
406408
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.coding.SuperCloneCheck.name=Super Clone
407409
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.name=Left Curly
408-
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.param.maxLineLength=maximum number of characters in a line. Default is 80.
409410
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.param.tokens=blocks to check
410411
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.param.ignoreEnums=If true, Check will ignore enums when left curly brace policy is EOL
411412
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.param.option=policy on placement of a left curly brace ('{'). eol : the brace must always be on the end of the line, nl : he brace must always be on a new line, nlow : ff the brace will fit on the first line of the statement, taking into account maximum line length, then apply eol rule. Otherwise apply the nl rule. nlow is a mnemonic for ''new line on wrap''.
@@ -505,7 +506,6 @@ rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.indentation.CommentsInden
505506
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck.name=Separator Wrap
506507
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck.param.option=policy on how to wrap lines
507508
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck.param.tokens=tokens to check
508-
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.FileContentsHolder.name=File Contents Holder
509509
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.name=Descendant Token
510510
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.param.limitedTokens=set of tokens with limited occurrences as descendants
511511
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.param.maximumDepth=the maximum depth for descendant counts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>The check does verifying that annotations are located on the same line with their targets. Verifying with this check is not good practice, but it is using by some style guides.</p>

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,6 @@
939939
<param key="option" type="s[eol,nl,nlow]">
940940
<defaultValue>eol</defaultValue>
941941
</param>
942-
<param key="maxLineLength" type="INTEGER">
943-
<defaultValue>80</defaultValue>
944-
</param>
945942
<param key="ignoreEnums" type="BOOLEAN">
946943
<defaultValue>true</defaultValue>
947944
</param>
@@ -1579,8 +1576,8 @@
15791576
<priority>MINOR</priority>
15801577
<name><![CDATA[Unnecessary Parentheses]]></name>
15811578
<configKey><![CDATA[Checker/TreeWalker/UnnecessaryParentheses]]></configKey>
1582-
<param key="tokens" type="s[EXPR,IDENT,NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG,STRING_LITERAL,LITERAL_NULL,LITERAL_FALSE,LITERAL_TRUE,ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN]">
1583-
<defaultValue>EXPR,IDENT,NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG,STRING_LITERAL,LITERAL_NULL,LITERAL_FALSE,LITERAL_TRUE,ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN</defaultValue>
1579+
<param key="tokens" type="s[EXPR,IDENT,NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG,STRING_LITERAL,LITERAL_NULL,LITERAL_FALSE,LITERAL_TRUE,ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN,LAMBDA]">
1580+
<defaultValue>EXPR,IDENT,NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG,STRING_LITERAL,LITERAL_NULL,LITERAL_FALSE,LITERAL_TRUE,ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN,LAMBDA</defaultValue>
15841581
</param>
15851582
<status>READY</status>
15861583
</rule>
@@ -1602,6 +1599,16 @@
16021599
<status>READY</status>
16031600
</rule>
16041601

1602+
<rule key="com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationOnSameLineCheck">
1603+
<priority>MINOR</priority>
1604+
<name><![CDATA[Upper Ell]]></name>
1605+
<configKey><![CDATA[Checker/TreeWalker/AnnotationOnSameLine]]></configKey>
1606+
<status>READY</status>
1607+
<param key="tokens" type="s[CLASS_DEF,INTERFACE_DEF,ENUM_DEF,METHOD_DEF,CTOR_DEF,VARIABLE_DEF,PARAMETER_DEF,ANNOTATION_DEF,TYPECAST,LITERAL_THROWS,IMPLEMENTS_CLAUSE,TYPE_ARGUMENT,LITERAL_NEW,DOT,ANNOTATION_FIELD_DEF]">
1608+
<defaultValue>CLASS_DEF,INTERFACE_DEF,ENUM_DEF,METHOD_DEF,CTOR_DEF,VARIABLE_DEF</defaultValue>
1609+
</param>
1610+
</rule>
1611+
16051612
<rule key="com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck">
16061613
<priority>MAJOR</priority>
16071614
<name><![CDATA[Visibility Modifier]]></name>
@@ -2017,12 +2024,6 @@
20172024
</param>
20182025
</rule>
20192026

2020-
<rule key="com.puppycrawl.tools.checkstyle.checks.FileContentsHolder">
2021-
<priority>MINOR</priority>
2022-
<name><![CDATA[File Contents Holder]]></name>
2023-
<configKey><![CDATA[Checker/TreeWalker/FileContentsHolder]]></configKey>
2024-
</rule>
2025-
20262027
<rule key="com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck">
20272028
<priority>MINOR</priority>
20282029
<name><![CDATA[Separator Wrap]]></name>

checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.StringWriter;
2323

2424
import org.apache.commons.lang.StringUtils;
25+
import org.junit.After;
2526
import org.junit.Before;
2627
import org.junit.Test;
2728
import org.sonar.api.config.PropertyDefinitions;
@@ -38,18 +39,25 @@ public class CheckstyleProfileExporterTest {
3839
@Before
3940
public void prepare() {
4041
settings = new Settings(new PropertyDefinitions(new CheckstylePlugin().getExtensions()));
42+
System.setProperty("javax.xml.transform.TransformerFactory",
43+
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
44+
}
45+
46+
@After
47+
public void tearDown() {
48+
System.setProperty("javax.xml.transform.TransformerFactory", "");
4149
}
4250

4351
@Test
44-
public void alwaysSetFileContentsHolderAndSuppressionCommentFilter() {
52+
public void alwaysSetSuppressionCommentFilter() {
4553
final RulesProfile profile = RulesProfile.create("sonar way", "java");
4654

4755
final StringWriter writer = new StringWriter();
4856
new CheckstyleProfileExporter(settings).exportProfile(profile, writer);
4957

5058
CheckstyleTestUtils.assertSimilarXmlWithResource(
5159
"/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/"
52-
+ "alwaysSetFileContentsHolderAndSuppressionCommentFilter.xml",
60+
+ "alwaysSetSuppressionCommentFilter.xml",
5361
sanitizeForTests(writer.toString()));
5462
}
5563

checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ public void importingFiltersIsNotSupported() {
171171

172172
assertNull(profile.getActiveRuleByConfigKey("checkstyle",
173173
"Checker/SuppressionCommentFilter"));
174-
assertNull(profile.getActiveRuleByConfigKey("checkstyle",
175-
"Checker/TreeWalker/FileContentsHolder"));
176174
assertThat(profile.getActiveRules().size()).isEqualTo(2);
177-
// no warning for FileContentsHolder
178175
assertThat(messages.getWarnings().size()).isEqualTo(5);
179176
}
180177

0 commit comments

Comments
 (0)