aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-checkstyle-plugin/pom.xml6
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java26
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java6
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java26
-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
8 files changed, 29 insertions, 116 deletions
diff --git a/plugins/sonar-checkstyle-plugin/pom.xml b/plugins/sonar-checkstyle-plugin/pom.xml
index 26cb84c0fb4..519b7cf5e88 100644
--- a/plugins/sonar-checkstyle-plugin/pom.xml
+++ b/plugins/sonar-checkstyle-plugin/pom.xml
@@ -47,12 +47,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-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
index 62a111bd082..b33b0be8ece 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
@@ -29,8 +29,6 @@ import org.apache.commons.lang.CharEncoding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
-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.Java;
import org.sonar.api.resources.Project;
@@ -56,11 +54,6 @@ public class CheckstyleConfiguration implements BatchExtension {
}
public File getXMLDefinitionFile() {
- if (project.getReuseExistingRulesConfig()) {
- LOG.warn("Reusing existing Checkstyle configuration is deprecated as it's unstable and can not provide meaningful results. This feature will be removed soon.");
- return findExistingXML();
- }
-
Writer writer = null;
File xmlFile = new File(project.getFileSystem().getSonarWorkingDirectory(), "checkstyle.xml");
try {
@@ -77,24 +70,6 @@ public class CheckstyleConfiguration implements BatchExtension {
}
}
- private File findExistingXML() {
- File file = null;
- MavenPlugin mavenPlugin = MavenPlugin.getPlugin(project.getPom(), MavenUtils.GROUP_ID_APACHE_MAVEN, "maven-checkstyle-plugin");
- if (mavenPlugin != null) {
- String location = mavenPlugin.getParameter("configLocation");
- if (location != null) {
- file = new File(location);
- if (!file.exists()) {
- file = new File(project.getFileSystem().getBasedir(), location);
- }
- }
- }
- if (file == null || !file.isFile() || !file.exists()) {
- throw new SonarException("The checkstyle configuration file does not exist: " + file);
- }
- return file;
- }
-
public List<File> getSourceFiles() {
return project.getFileSystem().getSourceFiles(Java.INSTANCE);
}
@@ -119,7 +94,6 @@ public class CheckstyleConfiguration implements BatchExtension {
return ConfigurationLoader.loadConfiguration(xmlConfig.getAbsolutePath(), new PropertiesExpander(new Properties()));
}
-
private void defineCharset(Configuration configuration) {
Configuration[] modules = configuration.getChildren();
for (Configuration module : modules) {
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
index d3d15d98615..3cd042564eb 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
@@ -23,6 +23,7 @@ import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
+import org.sonar.api.utils.Logs;
public class CheckstyleSensor implements Sensor {
@@ -40,6 +41,9 @@ public class CheckstyleSensor implements Sensor {
}
public void analyse(Project project, SensorContext context) {
+ if (project.getReuseExistingRulesConfig()) {
+ Logs.INFO.warn("Reusing existing Checkstyle configuration is not supported any more.");
+ }
executor.execute();
}
@@ -47,4 +51,4 @@ public class CheckstyleSensor implements Sensor {
public String toString() {
return getClass().getSimpleName();
}
-} \ No newline at end of file
+}
diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
index 85b74b46631..4bd33ebd1b2 100644
--- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
+++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
@@ -21,7 +21,6 @@ package org.sonar.plugins.checkstyle;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
-import org.mockito.Mockito;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.test.MavenTestUtils;
@@ -32,8 +31,6 @@ import java.io.Writer;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
public class CheckstyleConfigurationTest {
@@ -49,29 +46,6 @@ public class CheckstyleConfigurationTest {
assertThat(FileUtils.readFileToString(xmlFile), is("<conf/>"));
}
- @Test
- public void findConfigurationToReuse() throws IOException {
- Project project = MavenTestUtils.loadProjectFromPom(getClass(), "findConfigurationToReuse/pom.xml");
-
- CheckstyleProfileExporter exporter = mock(CheckstyleProfileExporter.class);
- Mockito.doThrow(new RuntimeException()).when(exporter).exportProfile((RulesProfile)anyObject(), (Writer)anyObject());
- CheckstyleConfiguration configuration = new CheckstyleConfiguration(exporter, null, project);
-
- File xmlFile = configuration.getXMLDefinitionFile();
- assertThat(xmlFile.exists(), is(true));
- assertThat(FileUtils.readFileToString(xmlFile), is("<ondisk/>"));
- }
-
- @Test(expected=RuntimeException.class)
- public void failIfConfigurationToReuseDoesNotExist() throws IOException {
- Project project = MavenTestUtils.loadProjectFromPom(getClass(), "failIfConfigurationToReuseDoesNotExist/pom.xml");
-
- CheckstyleProfileExporter exporter = mock(CheckstyleProfileExporter.class);
- Mockito.doThrow(new RuntimeException()).when(exporter).exportProfile((RulesProfile)anyObject(), (Writer)anyObject());
- CheckstyleConfiguration configuration = new CheckstyleConfiguration(exporter, null, project);
- configuration.getXMLDefinitionFile();
- }
-
public class FakeExporter extends CheckstyleProfileExporter {
@Override
public void exportProfile(RulesProfile profile, Writer writer) {
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();
- }
-
}