aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-19 10:35:16 +0000
committerGodin <mandrikov@gmail.com>2010-10-19 10:35:16 +0000
commit01586574fb0f0f8e6f68b0bd0668fcd50de34fed (patch)
tree9ca0a9b7a0f9174f3a4b9bfed04ebab9ac03b11a /plugins
parent4b7b2d44d286f1c15c24627b334d3c3f044229df (diff)
downloadsonarqube-01586574fb0f0f8e6f68b0bd0668fcd50de34fed.tar.gz
sonarqube-01586574fb0f0f8e6f68b0bd0668fcd50de34fed.zip
SONAR-1772:
* Provide aux classpath for findbugs * Produce xml report with messages
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java10
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java10
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java11
-rw-r--r--plugins/sonar-findbugs-plugin/test-resources/classes/Hello$1.classbin0 -> 733 bytes
-rw-r--r--plugins/sonar-findbugs-plugin/test-resources/classes/Hello.classbin397 -> 747 bytes
-rw-r--r--plugins/sonar-findbugs-plugin/test-resources/src/Hello.java9
6 files changed, 29 insertions, 11 deletions
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
index 7d0510c6855..5541701a6e1 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
@@ -3,6 +3,7 @@ package org.sonar.plugins.findbugs;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.ProjectClasspath;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;
@@ -22,11 +23,13 @@ public class FindbugsConfiguration implements BatchExtension {
private Project project;
private RulesProfile profile;
private FindbugsProfileExporter exporter;
+ private ProjectClasspath projectClasspath;
- public FindbugsConfiguration(Project project, RulesProfile profile, FindbugsProfileExporter exporter) {
+ public FindbugsConfiguration(Project project, RulesProfile profile, FindbugsProfileExporter exporter, ProjectClasspath classpath) {
this.project = project;
this.profile = profile;
this.exporter = exporter;
+ this.projectClasspath = classpath;
}
public File getTargetXMLReport() {
@@ -48,6 +51,11 @@ public class FindbugsConfiguration implements BatchExtension {
findbugsProject.addSourceDir(dir.getAbsolutePath());
}
findbugsProject.addFile(classesDir.getAbsolutePath());
+ for (File file : projectClasspath.getElements()) {
+ if ( !file.equals(classesDir)) {
+ findbugsProject.addAuxClasspathEntry(file.getAbsolutePath());
+ }
+ }
findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBuildDir());
return findbugsProject;
}
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java
index cc9cc188b3e..99a980a1899 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java
@@ -10,7 +10,6 @@ import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.TimeProfiler;
import edu.umd.cs.findbugs.*;
-import edu.umd.cs.findbugs.annotations.Priority;
import edu.umd.cs.findbugs.config.UserPreferences;
import java.io.File;
@@ -45,7 +44,8 @@ public class FindbugsExecutor implements BatchExtension {
engine.setProject(project);
XMLBugReporter xmlBugReporter = new XMLBugReporter(project);
- xmlBugReporter.setPriorityThreshold(Priority.LOW.getPriorityValue());
+ xmlBugReporter.setPriorityThreshold(Detector.LOW_PRIORITY);
+ xmlBugReporter.setAddMessages(true);
// xmlBugReporter.setErrorVerbosity(BugReporter.SILENT);
File xmlReport = configuration.getTargetXMLReport();
@@ -59,16 +59,14 @@ public class FindbugsExecutor implements BatchExtension {
engine.setBugReporter(xmlBugReporter);
- engine.setProject(project);
-
- engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance());
UserPreferences userPreferences = UserPreferences.createDefaultUserPreferences();
userPreferences.setEffort(configuration.getEffort());
+ engine.setUserPreferences(userPreferences);
engine.addFilter(configuration.saveIncludeConfigXml().getAbsolutePath(), true);
engine.addFilter(configuration.saveExcludeConfigXml().getAbsolutePath(), false);
- engine.setUserPreferences(userPreferences);
+ engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance());
engine.setAnalysisFeatureSettings(FindBugs.DEFAULT_EFFORT);
engine.finishSettings();
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java
index 3061414b21b..ce41df5002b 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java
@@ -19,13 +19,16 @@ public class FindbugsExecutorTest {
@Test
public void canGenerateXMLReport() throws Exception {
FindbugsConfiguration conf = mockConf();
- File report = new File("target/test-tmp/findbugs-report.xml");
- when(conf.getTargetXMLReport()).thenReturn(report);
+ File reportFile = new File("target/test-tmp/findbugs-report.xml");
+ when(conf.getTargetXMLReport()).thenReturn(reportFile);
new FindbugsExecutor(conf).execute();
- assertThat(report.exists(), is(true));
- assertThat(FileUtils.readFileToString(report), containsString("<BugInstance"));
+ assertThat(reportFile.exists(), is(true));
+ String report = FileUtils.readFileToString(reportFile);
+ assertThat("Report should contain bug instance", report, containsString("<BugInstance"));
+ assertThat("Report should be generated with messages", report, containsString("<Message>"));
+ assertThat(report, containsString("synthetic=\"true\""));
}
@Test(expected = SonarException.class)
diff --git a/plugins/sonar-findbugs-plugin/test-resources/classes/Hello$1.class b/plugins/sonar-findbugs-plugin/test-resources/classes/Hello$1.class
new file mode 100644
index 00000000000..7e0dca8ad32
--- /dev/null
+++ b/plugins/sonar-findbugs-plugin/test-resources/classes/Hello$1.class
Binary files differ
diff --git a/plugins/sonar-findbugs-plugin/test-resources/classes/Hello.class b/plugins/sonar-findbugs-plugin/test-resources/classes/Hello.class
index 45f085b02d8..f36889d4527 100644
--- a/plugins/sonar-findbugs-plugin/test-resources/classes/Hello.class
+++ b/plugins/sonar-findbugs-plugin/test-resources/classes/Hello.class
Binary files differ
diff --git a/plugins/sonar-findbugs-plugin/test-resources/src/Hello.java b/plugins/sonar-findbugs-plugin/test-resources/src/Hello.java
index 5bb582c7254..1fc7ebcdc3e 100644
--- a/plugins/sonar-findbugs-plugin/test-resources/src/Hello.java
+++ b/plugins/sonar-findbugs-plugin/test-resources/src/Hello.java
@@ -1,9 +1,18 @@
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+
class Hello {
static String name;
public void methodWithViolations(String n) {
name = n;
+ Collections.sort(Arrays.asList(new Integer[]{1, 2, 3}), new Comparator<Integer>() {
+ public int compare(Integer o1, Integer o2) {
+ return o1 - o2;
+ }
+ });
}
@Override