aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2012-03-27 00:54:42 +0600
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-03-27 00:54:48 +0600
commit5d1eb7bae68a67ce5e530808dda0e587a840ab2c (patch)
treefee3e965ca8c75dd673738f45d095a5c6524be8d /plugins
parent3c98441e049fe73982ee3471ea0b9baa58fbaa91 (diff)
downloadsonarqube-5d1eb7bae68a67ce5e530808dda0e587a840ab2c.tar.gz
sonarqube-5d1eb7bae68a67ce5e530808dda0e587a840ab2c.zip
SONAR-3346 Add property "sonar.pmd.generateXml"
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdConfiguration.java24
-rw-r--r--plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java27
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdConfigurationTest.java2
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java8
4 files changed, 43 insertions, 18 deletions
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 d0e0228ecf3..6ec082908b1 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
@@ -20,6 +20,8 @@
package org.sonar.plugins.pmd;
import org.sonar.api.BatchExtension;
+import org.sonar.api.Property;
+import org.sonar.api.config.Settings;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
@@ -29,16 +31,29 @@ import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;
+@org.sonar.api.Properties({
+ @Property(
+ key = PmdConfiguration.PROPERTY_GENERATE_XML,
+ defaultValue = "false",
+ name = "Generate XML Report",
+ project = false,
+ global = false
+ )
+})
public class PmdConfiguration implements BatchExtension {
+ public static final String PROPERTY_GENERATE_XML = "sonar.pmd.generateXml";
+
private PmdProfileExporter pmdProfileExporter;
private RulesProfile rulesProfile;
private Project project;
+ private Settings settings;
- public PmdConfiguration(PmdProfileExporter pmdRulesRepository, RulesProfile rulesProfile, Project project) {
+ public PmdConfiguration(PmdProfileExporter pmdRulesRepository, RulesProfile rulesProfile, Project project, Settings settings) {
this.pmdProfileExporter = pmdRulesRepository;
this.rulesProfile = rulesProfile;
this.project = project;
+ this.settings = settings;
}
public List<String> getRulesets() {
@@ -55,4 +70,11 @@ public class PmdConfiguration implements BatchExtension {
throw new RuntimeException("Fail to save the PMD configuration", e);
}
}
+
+ public File getTargetXMLReport() {
+ if (settings.getBoolean(PROPERTY_GENERATE_XML)) {
+ return new File(project.getFileSystem().getSonarWorkingDirectory(), "pmd-result.xml");
+ }
+ return null;
+ }
}
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java
index 9b5eb9862bd..f0a5a3a00bd 100644
--- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java
+++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java
@@ -80,7 +80,7 @@ public class PmdExecutor implements BatchExtension {
}
}
- writeXmlReport(project, report);
+ writeXmlReport(report);
return report;
@@ -129,18 +129,19 @@ public class PmdExecutor implements BatchExtension {
}
}
- private File writeXmlReport(Project project, Report report) throws IOException {
- Renderer xmlRenderer = new XMLRenderer();
- Writer stringwriter = new StringWriter();
- xmlRenderer.setWriter(stringwriter);
- xmlRenderer.start();
- xmlRenderer.renderFileReport(report);
- xmlRenderer.end();
-
- File xmlReport = new File(project.getFileSystem().getSonarWorkingDirectory(), "pmd-result.xml");
- LOG.info("PMD output report: " + xmlReport.getAbsolutePath());
- FileUtils.write(xmlReport, stringwriter.toString());
- return xmlReport;
+ private void writeXmlReport(Report report) throws IOException {
+ File xmlReport = configuration.getTargetXMLReport();
+ if (xmlReport != null) {
+ Renderer xmlRenderer = new XMLRenderer();
+ Writer stringwriter = new StringWriter();
+ xmlRenderer.setWriter(stringwriter);
+ xmlRenderer.start();
+ xmlRenderer.renderFileReport(report);
+ xmlRenderer.end();
+
+ LOG.info("PMD output report: " + xmlReport.getAbsolutePath());
+ FileUtils.write(xmlReport, stringwriter.toString());
+ }
}
static String getNormalizedJavaVersion(String javaVersion) {
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 2ce2827bbac..3475f2db96e 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
@@ -38,7 +38,7 @@ public class PmdConfigurationTest {
public void writeConfigurationToWorkingDir() throws IOException {
Project project = MavenTestUtils.loadProjectFromPom(getClass(), "writeConfigurationToWorkingDir/pom.xml");
- PmdConfiguration configuration = new PmdConfiguration(new PmdProfileExporter(), RulesProfile.create(), project);
+ PmdConfiguration configuration = new PmdConfiguration(new PmdProfileExporter(), RulesProfile.create(), project, null);
List<String> rulesets = configuration.getRulesets();
assertThat(rulesets.size(), is(1));
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java
index 4ed43df3951..dd9feab2cd9 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java
@@ -62,10 +62,11 @@ public class PmdExecutorTest {
PmdConfiguration conf = mock(PmdConfiguration.class);
File file = FileUtils.toFile(getClass().getResource("/org/sonar/plugins/pmd/PmdExecutorTest/executeOnManySourceDirs/pmd.xml").toURI().toURL());
when(conf.getRulesets()).thenReturn(Arrays.asList(file.getAbsolutePath()));
+ File xmlReport = new File(workDir, "pmd-result.xml");
+ when(conf.getTargetXMLReport()).thenReturn(xmlReport);
PmdExecutor executor = new PmdExecutor(project, conf);
executor.execute();
- File xmlReport = new File(workDir, "pmd-result.xml");
assertThat(xmlReport.exists(), is(true));
String xml = FileUtils.readFileToString(xmlReport);
@@ -88,10 +89,11 @@ public class PmdExecutorTest {
PmdConfiguration conf = mock(PmdConfiguration.class);
when(conf.getRulesets()).thenReturn(Arrays.asList(new File("test-resources/ignorePmdFailures/pmd.xml").getAbsolutePath()));
-
+ File xmlReport = new File(workDir, "pmd-result.xml");
+ when(conf.getTargetXMLReport()).thenReturn(xmlReport);
PmdExecutor executor = new PmdExecutor(project, conf);
+
executor.execute();
- File xmlReport = new File(workDir, "pmd-result.xml");
assertThat(xmlReport.exists(), is(true));
}