aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-pmd-plugin
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-06 16:23:59 +0000
committerGodin <mandrikov@gmail.com>2010-12-06 16:23:59 +0000
commit826316807d7bb114d8b6399986e276cfc77c6514 (patch)
tree5a8de056d5377c766973cb5c4ba2a5c12fbe8fd7 /plugins/sonar-pmd-plugin
parent2728a4dacdd779e797ef4ef0f26d17db7c0adb0a (diff)
downloadsonarqube-826316807d7bb114d8b6399986e276cfc77c6514.tar.gz
sonarqube-826316807d7bb114d8b6399986e276cfc77c6514.zip
SONAR-2031: Remove the feature "reuse configuration" of the plugins Checkstyle and PMD
Diffstat (limited to 'plugins/sonar-pmd-plugin')
-rw-r--r--plugins/sonar-pmd-plugin/pom.xml6
-rw-r--r--plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdConfiguration.java35
-rw-r--r--plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java6
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdConfigurationTest.java34
4 files changed, 20 insertions, 61 deletions
diff --git a/plugins/sonar-pmd-plugin/pom.xml b/plugins/sonar-pmd-plugin/pom.xml
index 792b9e69b87..929925c7c66 100644
--- a/plugins/sonar-pmd-plugin/pom.xml
+++ b/plugins/sonar-pmd-plugin/pom.xml
@@ -46,12 +46,14 @@
</dependency>
<!-- TODO http://jira.codehaus.org/browse/SONAR-2011
- We need following dependency, otherwise we will receive compilation error
+ We need following dependency, otherwise we will receive
+ java.lang.NoClassDefFoundError: org/apache/maven/project/MavenProject
+ during call mock(org.sonar.api.resources.Project.class)
-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
- <scope>provided</scope>
+ <scope>test</scope>
</dependency>
<dependency>
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdConfiguration.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdConfiguration.java
index a03b8dd077e..4bace7566ea 100644
--- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdConfiguration.java
+++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdConfiguration.java
@@ -19,25 +19,18 @@
*/
package org.sonar.plugins.pmd;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.resources.Project;
+
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.maven.MavenPlugin;
-import org.sonar.api.batch.maven.MavenUtils;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Project;
-
public class PmdConfiguration implements BatchExtension {
- private static Logger LOG = LoggerFactory.getLogger(PmdConfiguration.class);
-
private PmdProfileExporter pmdProfileExporter;
private RulesProfile rulesProfile;
private Project project;
@@ -49,29 +42,9 @@ public class PmdConfiguration implements BatchExtension {
}
public List<String> getRulesets() {
- if (project.getReuseExistingRulesConfig()) {
- LOG.warn("Reusing existing PMD configuration is deprecated as it's unstable and can not provide meaningful results. This feature will be removed soon.");
- return getDeclaredRulesets();
- }
return Arrays.asList(saveXmlFile().getAbsolutePath());
}
- private List<String> getDeclaredRulesets() {
- List<String> rulesets = null;
- MavenPlugin mavenPlugin = MavenPlugin.getPlugin(project.getPom(), MavenUtils.GROUP_ID_APACHE_MAVEN, "maven-pmd-plugin");
- if (mavenPlugin != null) {
- String[] params = mavenPlugin.getParameters("rulesets/ruleset");
- if (params != null) {
- rulesets = Arrays.asList(params);
- }
- }
- if (rulesets == null || rulesets.isEmpty()) {
- throw new RuntimeException("The PMD configuration to reuse can not be found. Check the property "
- + CoreProperties.REUSE_RULES_CONFIGURATION_PROPERTY + " or add the property rulesets/ruleset to the Maven PMD plugin");
- }
- return rulesets;
- }
-
private File saveXmlFile() {
try {
StringWriter pmdConfiguration = new StringWriter();
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java
index b6b99babeb6..91d14497bbe 100644
--- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java
+++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java
@@ -25,6 +25,7 @@ import org.sonar.api.batch.SensorContext;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.rules.RulesManager;
+import org.sonar.api.utils.Logs;
import org.sonar.api.utils.XmlParserException;
import java.io.File;
@@ -42,6 +43,9 @@ public class PmdSensor implements Sensor {
}
public void analyse(Project project, SensorContext context) {
+ if (project.getReuseExistingRulesConfig()) {
+ Logs.INFO.warn("Reusing existing PMD configuration is not supported any more.");
+ }
try {
File xmlReport = executor.execute();
AbstractViolationsStaxParser parser = getStaxParser(project, context);
@@ -66,4 +70,4 @@ public class PmdSensor implements Sensor {
public String toString() {
return getClass().getSimpleName();
}
-} \ No newline at end of file
+}
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdConfigurationTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdConfigurationTest.java
index 2fc6936cfb8..4a5498e8d3a 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdConfigurationTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdConfigurationTest.java
@@ -19,20 +19,19 @@
*/
package org.sonar.plugins.pmd;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.test.MavenTestUtils;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
public class PmdConfigurationTest {
@Test
@@ -48,23 +47,4 @@ public class PmdConfigurationTest {
assertThat(FileUtils.readFileToString(xmlFile), is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<ruleset />\r\n\r\n"));
}
- @Test
- public void findConfigurationToReuse() throws IOException {
- Project project = MavenTestUtils.loadProjectFromPom(getClass(), "findConfigurationToReuse/pom.xml");
-
- PmdConfiguration configuration = new PmdConfiguration(null, null, project);
- List<String> rulesets = configuration.getRulesets();
- assertThat(rulesets.size(), is(2));
- assertThat(rulesets, hasItem("ruleset/maven.xml"));
- assertThat(rulesets, hasItem("ruleset/basic.xml"));
- }
-
- @Test(expected = RuntimeException.class)
- public void failIfConfigurationToReuseDoesNotExist() throws IOException {
- Project project = MavenTestUtils.loadProjectFromPom(getClass(), "failIfConfigurationToReuseDoesNotExist/pom.xml");
-
- PmdConfiguration configuration = new PmdConfiguration(null, null, project);
- configuration.getRulesets();
- }
-
}