aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-07 23:23:23 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-07 23:23:23 +0000
commit3cc63963cfd20176c605c27f023fb6e70db69b80 (patch)
treeeed6fd559c6877052a4ef3ce2c0ebb845c41ea66 /plugins
parent0b9d0acd74b08a9076cd982684f0be8285c94251 (diff)
downloadsonarqube-3cc63963cfd20176c605c27f023fb6e70db69b80.tar.gz
sonarqube-3cc63963cfd20176c605c27f023fb6e70db69b80.zip
SONAR-1549 The Sonar profile creation form doesn't allow to import checkstyle,pmd and Findbugs conf files when several langages are defined
SONAR-440 add warnings to checkstyle when importing configuration
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java33
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sun-conventions.xml10
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java13
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/importingFiltersIsNotSupported.xml9
4 files changed, 48 insertions, 17 deletions
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java
index c9561aea69e..e397e5bbdeb 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java
@@ -64,7 +64,7 @@ public class CheckstyleProfileImporter extends ProfileImporter {
}
}
} catch (XMLStreamException e) {
- messages.addError("unvalidXml", "XML is not valid: " + e.getMessage());
+ messages.addError("checkstyle.import.unvalidXml", "XML is not valid: " + e.getMessage());
}
return profile;
}
@@ -80,23 +80,42 @@ public class CheckstyleProfileImporter extends ProfileImporter {
}
private void processModule(ProfilePrototype profile, String path, SMInputCursor moduleCursor, ValidationMessages messages) throws XMLStreamException {
- String configKey = path + moduleCursor.getAttrValue("name");
- ProfilePrototype.RulePrototype rule = ProfilePrototype.RulePrototype.createByConfigKey(CheckstyleConstants.REPOSITORY_KEY, configKey);
+ String configKey = moduleCursor.getAttrValue("name");
+ if (isFilter(configKey)) {
+ messages.addWarning("checkstyle.import.filtersNotSupported", "Checkstyle filters are not imported: " + configKey);
+ } else if (isIgnored(configKey)) {
+
+ } else {
+ ProfilePrototype.RulePrototype rule = ProfilePrototype.RulePrototype.createByConfigKey(CheckstyleConstants.REPOSITORY_KEY, path + configKey);
+ processProperties(moduleCursor, messages, rule);
+ profile.activateRule(rule);
+ }
+ }
+
+ static boolean isIgnored(String configKey) {
+ return StringUtils.equals(configKey, "FileContentsHolder");
+ }
+
+ static boolean isFilter(String configKey) {
+ return StringUtils.equals(configKey, "SuppressionCommentFilter") ||
+ StringUtils.equals(configKey, "SeverityMatchFilter") ||
+ StringUtils.equals(configKey, "SuppressionFilter") ||
+ StringUtils.equals(configKey, "SuppressWithNearbyCommentFilter");
+ }
+
+ private void processProperties(SMInputCursor moduleCursor, ValidationMessages messages, ProfilePrototype.RulePrototype rule) throws XMLStreamException {
SMInputCursor propertyCursor = moduleCursor.childElementCursor("property");
while (propertyCursor.getNext() != null) {
processProperty(rule, propertyCursor, messages);
}
-
- profile.activateRule(rule);
-
}
private void processProperty(ProfilePrototype.RulePrototype rule, SMInputCursor propertyCursor, ValidationMessages messages) throws XMLStreamException {
String key = propertyCursor.getAttrValue("name");
String value = propertyCursor.getAttrValue("value");
if (StringUtils.equals("id", key)) {
- messages.addWarning("checkstyle.idPropertyNotSupported", "The property 'id' is not supported.");
+ messages.addWarning("checkstyle.import.idPropertyNotSupported", "The checkstyle property 'id' is not supported in the rule: " + rule.getConfigKey());
} else if (StringUtils.equals("severity", key)) {
rule.setPriority(CheckstyleSeverityUtils.fromSeverity(value));
diff --git a/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sun-conventions.xml b/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sun-conventions.xml
index bbeff27d91c..d6fe70f3ff5 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sun-conventions.xml
+++ b/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sun-conventions.xml
@@ -12,16 +12,6 @@
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
- <key>com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck</key>
- <parameters>
- <parameter>
- <key>tokens</key>
- <value>COMMA,SEMI,TYPECAST</value>
- </parameter>
- </parameters>
- </rule>
- <rule>
- <repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck</key>
<parameters>
<parameter>
diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
index 63d9c2d40d9..1e53bba97ab 100644
--- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
+++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
@@ -32,6 +32,7 @@ import java.io.StringReader;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
public class CheckstyleProfileImporterTest {
@@ -102,4 +103,16 @@ public class CheckstyleProfileImporterTest {
importer.importProfile(reader, messages);
assertThat(messages.getErrors().size(), is(1));
}
+
+ @Test
+ public void importingFiltersIsNotSupported() {
+ Reader reader = new StringReader(TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/importingFiltersIsNotSupported.xml"));
+ ProfilePrototype profile = importer.importProfile(reader, messages);
+
+ assertNull(profile.getRuleByConfigKey("checkstyle", "Checker/SuppressionCommentFilter"));
+ assertNull(profile.getRuleByConfigKey("checkstyle", "Checker/TreeWalker/FileContentsHolder"));
+ assertThat(profile.getRules().size(), is(2));
+ assertThat(messages.getWarnings().size(), is(1)); // no warning for FileContentsHolder
+ }
+
}
diff --git a/plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/importingFiltersIsNotSupported.xml b/plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/importingFiltersIsNotSupported.xml
new file mode 100644
index 00000000000..806ec61fae0
--- /dev/null
+++ b/plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest/importingFiltersIsNotSupported.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module name="Checker">
+ <module name="SuppressionCommentFilter"/>
+ <module name="NewlineAtEndOfFile"/>
+ <module name="TreeWalker">
+ <module name="FileContentsHolder"/>
+ <module name="InterfaceIsType"/>
+ </module>
+</module> \ No newline at end of file