diff --git a/checkstyle-sonar-plugin/config/pmd.xml b/checkstyle-sonar-plugin/config/pmd.xml
index 00c8d18a..fa8049d2 100644
--- a/checkstyle-sonar-plugin/config/pmd.xml
+++ b/checkstyle-sonar-plugin/config/pmd.xml
@@ -21,10 +21,14 @@
-
+
+
+ gnature
+
+
@@ -145,11 +149,28 @@
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -204,18 +225,16 @@
-
+
+
+
-
-
-
-
-
-
+
+
+
diff --git a/checkstyle-sonar-plugin/pom.xml b/checkstyle-sonar-plugin/pom.xml
index a518b398..3345df73 100644
--- a/checkstyle-sonar-plugin/pom.xml
+++ b/checkstyle-sonar-plugin/pom.xml
@@ -207,7 +207,7 @@
false
true
true
-
+ true
config/pmd.xml
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleAuditListenerTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleAuditListenerTest.java
index 909184d2..e018926a 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleAuditListenerTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleAuditListenerTest.java
@@ -79,7 +79,7 @@ public void testUtilityMethods() {
@Test
- public void add_error_test() throws Exception {
+ public void addErrorTest() {
Rule rule = setupRule("repo", "key");
Issuable issuable = setupIssuable();
@@ -101,14 +101,14 @@ public void add_error_test() throws Exception {
}
@Test
- public void add_error_on_unknown_rule() throws Exception {
+ public void addErrorOnUnknownRule() {
Issuable issuable = setupIssuable();
addErrorToListener();
verifyZeroInteractions(issuable);
}
@Test
- public void add_error_on_unknown_file() throws Exception {
+ public void addErrorOnUnknownFile() {
Rule rule = setupRule("repo", "key");
addErrorToListener();
verifyZeroInteractions(rule);
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
index 333513b1..67c91272 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
@@ -121,7 +121,7 @@ public void exportProfile(RulesProfile profile, Writer writer) {
try {
writer.write("");
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new IllegalStateException(e);
}
}
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConstantsTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConstantsTest.java
index c68fd9d0..50ba685e 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConstantsTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConstantsTest.java
@@ -28,7 +28,7 @@
public class CheckstyleConstantsTest {
@Test
- public void private_constructor() throws Exception {
+ public void privateConstructor() throws ReflectiveOperationException {
Constructor constructor = CheckstyleConstants.class.getDeclaredConstructor();
assertThat(constructor.isAccessible()).isFalse();
constructor.setAccessible(true);
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
index e2abda6f..415f965f 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
@@ -35,7 +35,9 @@
import org.sonar.plugins.java.api.JavaResourceLocator;
import java.io.File;
+import java.io.IOException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Locale;
@@ -56,7 +58,7 @@ public class CheckstyleExecutorTest {
public ExpectedException thrown = ExpectedException.none();
@Test
- public void execute() throws Exception {
+ public void execute() throws CheckstyleException {
CheckstyleConfiguration conf = mockConf();
CheckstyleAuditListener listener = mockListener();
CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener, createJavaResourceLocator());
@@ -82,7 +84,7 @@ public void execute() throws Exception {
}
@Test
- public void execute_exception() throws Exception {
+ public void executeException() throws CheckstyleException {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Can not execute Checkstyle");
CheckstyleConfiguration conf = mockConf();
@@ -91,7 +93,7 @@ public void execute_exception() throws Exception {
}
@Test
- public void getURL_exception() throws Exception {
+ public void getURLException() throws URISyntaxException {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Fail to create the project classloader. Classpath element is invalid: htp://aa");
CheckstyleExecutor executor = new CheckstyleExecutor(null, null, createJavaResourceLocator());
@@ -105,7 +107,7 @@ private static JavaResourceLocator createJavaResourceLocator() {
}
@Test
- public void canGenerateXMLReport_in_english() throws Exception {
+ public void canGenerateXMLReportInEnglish() throws CheckstyleException, IOException {
Locale initialLocale = Locale.getDefault();
Locale.setDefault(Locale.FRENCH);
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
index 56cf70f2..26ebd8f1 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
@@ -85,7 +85,7 @@ public void importParameters() {
}
@Test
- public void properties_should_be_inherited() {
+ public void propertiesShouldBeInherited() {
Reader reader = new StringReader(CheckstyleTestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/inheritance_of_properties.xml"));
RulesProfile profile = importer.importProfile(reader, messages);
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinitionTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinitionTest.java
index e7cff0c1..ac3b6033 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinitionTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRulesDefinitionTest.java
@@ -31,7 +31,7 @@
public class CheckstyleRulesDefinitionTest {
- List NO_SQALE = ImmutableList.of(
+ private final List NO_SQALE = ImmutableList.of(
"com.puppycrawl.tools.checkstyle.checks.TranslationCheck",
"com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck",
"com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck",
@@ -72,20 +72,20 @@ public void test() {
.isNotNull();
}
- if (!NO_SQALE.contains(rule.key())) {
+ if (NO_SQALE.contains(rule.key())) {
assertThat(rule.debtRemediationFunction())
- .overridingErrorMessage("Sqale remediation function is not set for rule '" + rule.key())
- .isNotNull();
+ .overridingErrorMessage("Sqale remediation function is set for rule '" + rule.key())
+ .isNull();
assertThat(rule.debtSubCharacteristic())
- .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key())
- .isNotNull();
+ .overridingErrorMessage("Sqale characteristic is set for rule '" + rule.key())
+ .isNull();
} else {
assertThat(rule.debtRemediationFunction())
- .overridingErrorMessage("Sqale remediation function is set for rule '" + rule.key())
- .isNull();
+ .overridingErrorMessage("Sqale remediation function is not set for rule '" + rule.key())
+ .isNotNull();
assertThat(rule.debtSubCharacteristic())
- .overridingErrorMessage("Sqale characteristic is set for rule '" + rule.key())
- .isNull();
+ .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key())
+ .isNotNull();
}
}
}
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSensorTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSensorTest.java
index e2810da0..3a03cfef 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSensorTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSensorTest.java
@@ -43,19 +43,19 @@ public class CheckstyleSensorTest {
private Project project = new Project("projectKey");
@Test
- public void shouldExecuteOnProject_without_java_file_and_with_rule() throws Exception {
+ public void shouldExecuteOnProjectWithoutJavaFileAndWithRule() {
addOneActiveRule();
assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
}
@Test
- public void shouldExecuteOnProject_with_java_file_and_without_rule() throws Exception {
+ public void shouldExecuteOnProjectWithJavaFileAndWithoutRule() {
addOneJavaFile();
assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
}
@Test
- public void shouldExecuteOnProject_with_java_files_and_rules() throws Exception {
+ public void shouldExecuteOnProjectWithJavaFilesAndRules() {
addOneJavaFile();
addOneActiveRule();
assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtilsTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtilsTest.java
index 77e5ae96..d2e81f81 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtilsTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtilsTest.java
@@ -47,7 +47,7 @@ public void testFromSeverity() {
}
@Test
- public void private_constructor() throws Exception {
+ public void privateConstructor() throws ReflectiveOperationException {
Constructor constructor = CheckstyleSeverityUtils.class.getDeclaredConstructor();
assertThat(constructor.isAccessible()).isFalse();
constructor.setAccessible(true);
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleTestUtils.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleTestUtils.java
index 8291c15a..e9e65504 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleTestUtils.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleTestUtils.java
@@ -30,7 +30,11 @@
import static org.junit.Assert.assertTrue;
-public class CheckstyleTestUtils {
+public final class CheckstyleTestUtils {
+
+ private CheckstyleTestUtils() {
+ // no code
+ }
public static String getResourceContent(String path) {
try {
diff --git a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/ChecksTest.java b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/ChecksTest.java
index d1feb922..f37032be 100644
--- a/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/ChecksTest.java
+++ b/checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/ChecksTest.java
@@ -25,6 +25,7 @@
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashSet;
@@ -33,6 +34,8 @@
import java.util.Set;
import java.util.TreeSet;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.apache.commons.beanutils.PropertyUtils;
import org.junit.Assert;
import org.junit.Test;
@@ -78,7 +81,7 @@ public void verifyTestConfigurationFiles() throws Exception {
validateSonarProperties(new HashSet<>(modules));
}
- private static void validateSonarRules(Set> modules) throws Exception {
+ private static void validateSonarRules(Set> modules) throws ParserConfigurationException, IOException {
final File rulesFile = new File(RULES_PATH);
Assert.assertTrue("'rules.xml' must exist", rulesFile.exists());
@@ -91,7 +94,7 @@ private static void validateSonarRules(Set> modules) throws Exception {
}
private static void validateSonarRules(Document document, Set> modules)
- throws Exception {
+ {
final NodeList rules = document.getElementsByTagName("rule");
for (int position = 0; position < rules.getLength(); position++) {
@@ -104,8 +107,9 @@ private static void validateSonarRules(Document document, Set> modules)
Assert.assertNotNull("Unknown class found in sonar rules: " + key, module);
- if (CheckUtil.isFilterModule(module))
+ if (CheckUtil.isFilterModule(module)) {
Assert.fail("Module should not be in sonar rules: " + module.getCanonicalName());
+ }
modules.remove(module);
@@ -136,13 +140,14 @@ private static void validateSonarRules(Document document, Set> modules)
}
for (Class> module : modules) {
- if (!CheckUtil.isFilterModule(module) && module != TreeWalker.class)
+ if (!CheckUtil.isFilterModule(module) && module != TreeWalker.class) {
Assert.fail("Module not found in sonar rules: " + module.getCanonicalName());
+ }
}
}
private static void validateSonarRuleProperties(Class> module, Set parameters)
- throws Exception {
+ {
final String moduleName = module.getName();
final Set properties = getFinalProperties(module);
@@ -168,7 +173,7 @@ private static void validateSonarRuleProperties(Class> module, Set param
}
}
- private static void validateSonarProperties(Set> modules) throws Exception {
+ private static void validateSonarProperties(Set> modules) throws IOException {
final File propertiesFile = new File(MODULE_PROPERTIES_PATH);
Assert.assertTrue("'checkstyle.properties' must exist", propertiesFile.exists());
@@ -180,7 +185,7 @@ private static void validateSonarProperties(Set> modules) throws Except
}
private static void validateSonarProperties(Properties properties, Set> modules)
- throws Exception {
+ {
Class> lastModule = null;
Set moduleProperties = null;
@@ -212,13 +217,15 @@ private static void validateSonarProperties(Properties properties, Set>
Assert.assertNotNull("Unknown class found in sonar properties: " + moduleName, module);
- if (CheckUtil.isFilterModule(module))
+ if (CheckUtil.isFilterModule(module)) {
Assert.fail("Module should not be in sonar properties: "
+ module.getCanonicalName());
+ }
if (lastModule != module) {
- if (lastModule != null)
+ if (lastModule != null) {
modules.remove(lastModule);
+ }
if (moduleProperties != null) {
for (String property : moduleProperties) {
Assert.fail(lastModule.getCanonicalName()
@@ -230,8 +237,9 @@ private static void validateSonarProperties(Properties properties, Set>
}
lastModule = module;
- if (!keyName.endsWith(".name"))
+ if (!keyName.endsWith(".name")) {
validateSonarPropertyProperties(module, moduleProperties, keyName);
+ }
}
if (lastModule != null) {
@@ -239,8 +247,9 @@ private static void validateSonarProperties(Properties properties, Set>
}
for (Class> module : modules) {
- if (!CheckUtil.isFilterModule(module) && module != TreeWalker.class)
+ if (!CheckUtil.isFilterModule(module) && module != TreeWalker.class) {
Assert.fail("Module not found in sonar properties: " + module.getCanonicalName());
+ }
}
}
@@ -266,7 +275,7 @@ private static Class> findModule(Set> modules, String classPath) {
return result;
}
- private static Set getFinalProperties(Class> clss) throws Exception {
+ private static Set getFinalProperties(Class> clss) {
final Set properties = getProperties(clss);
if (AbstractJavadocCheck.class.isAssignableFrom(clss)) {
@@ -288,7 +297,12 @@ else if (AbstractFileSetCheck.class.isAssignableFrom(clss)) {
.forEach(properties::remove);
if (AbstractCheck.class.isAssignableFrom(clss)) {
- final AbstractCheck check = (AbstractCheck) clss.newInstance();
+ final AbstractCheck check;
+ try {
+ check = (AbstractCheck) clss.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new IllegalStateException(e);
+ }
final int[] acceptableTokens = check.getAcceptableTokens();
Arrays.sort(acceptableTokens);