aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-findbugs-plugin
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-20 23:25:14 +0000
committerGodin <mandrikov@gmail.com>2010-10-20 23:25:14 +0000
commit0b1219c671f28f4352cfb34026a1c1652f0dd332 (patch)
treec98532fc545f92ecb54a7d6fb39dc3baa7336ac3 /plugins/sonar-findbugs-plugin
parentd6910162656f1af6f54fbf8496cf7492248cc2d1 (diff)
downloadsonarqube-0b1219c671f28f4352cfb34026a1c1652f0dd332.tar.gz
sonarqube-0b1219c671f28f4352cfb34026a1c1652f0dd332.zip
SONAR-1772: Use existing rules config
Diffstat (limited to 'plugins/sonar-findbugs-plugin')
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java25
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java15
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsNativeSensor.java2
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java16
4 files changed, 40 insertions, 18 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 5541701a6e1..84c3f49364d 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
@@ -4,8 +4,11 @@ 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.batch.maven.MavenPlugin;
+import org.sonar.api.batch.maven.MavenUtils;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
+import org.sonar.api.utils.Logs;
import org.sonar.api.utils.SonarException;
import org.sonar.plugins.findbugs.xml.ClassFilter;
import org.sonar.plugins.findbugs.xml.FindBugsFilter;
@@ -40,6 +43,10 @@ public class FindbugsConfiguration implements BatchExtension {
}
public edu.umd.cs.findbugs.Project getFindbugsProject() {
+ if (project.getReuseExistingRulesConfig()) {
+ Logs.INFO.warn("Reusing existing Findbugs configuration is deprecated as it's unstable and can not provide meaningful results. This feature will be removed soon.");
+ }
+
File classesDir = project.getFileSystem().getBuildOutputDir();
if (classesDir == null || !classesDir.exists()) {
throw new SonarException("Findbugs needs sources to be compiled. "
@@ -60,13 +67,23 @@ public class FindbugsConfiguration implements BatchExtension {
return findbugsProject;
}
- public File saveIncludeConfigXml() throws IOException {
+ private MavenPlugin getFindbugsMavenPlugin() {
+ return MavenPlugin.getPlugin(project.getPom(), MavenUtils.GROUP_ID_CODEHAUS_MOJO, "findbugs-maven-plugin");
+ }
+
+ public String saveIncludeConfigXml() throws IOException {
+ if (project.getReuseExistingRulesConfig()) {
+ return getFindbugsMavenPlugin().getParameter("includeFilterFile");
+ }
StringWriter conf = new StringWriter();
exporter.exportProfile(profile, conf);
- return project.getFileSystem().writeToWorkingDirectory(conf.toString(), "findbugs-include.xml");
+ return project.getFileSystem().writeToWorkingDirectory(conf.toString(), "findbugs-include.xml").getAbsolutePath();
}
- public File saveExcludeConfigXml() throws IOException {
+ public String saveExcludeConfigXml() throws IOException {
+ if (project.getReuseExistingRulesConfig()) {
+ return getFindbugsMavenPlugin().getParameter("excludeFilterFile");
+ }
FindBugsFilter findBugsFilter = new FindBugsFilter();
if (project.getExclusionPatterns() != null) {
for (String exclusion : project.getExclusionPatterns()) {
@@ -74,7 +91,7 @@ public class FindbugsConfiguration implements BatchExtension {
findBugsFilter.addMatch(new Match(classFilter));
}
}
- return project.getFileSystem().writeToWorkingDirectory(findBugsFilter.toXml(), "findbugs-exclude.xml");
+ return project.getFileSystem().writeToWorkingDirectory(findBugsFilter.toXml(), "findbugs-exclude.xml").getAbsolutePath();
}
public String getEffort() {
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 99a980a1899..e182f2d3ebb 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
@@ -9,7 +9,12 @@ import org.sonar.api.BatchExtension;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.TimeProfiler;
-import edu.umd.cs.findbugs.*;
+import edu.umd.cs.findbugs.Detector;
+import edu.umd.cs.findbugs.DetectorFactoryCollection;
+import edu.umd.cs.findbugs.FindBugs;
+import edu.umd.cs.findbugs.FindBugs2;
+import edu.umd.cs.findbugs.Project;
+import edu.umd.cs.findbugs.XMLBugReporter;
import edu.umd.cs.findbugs.config.UserPreferences;
import java.io.File;
@@ -63,8 +68,8 @@ public class FindbugsExecutor implements BatchExtension {
userPreferences.setEffort(configuration.getEffort());
engine.setUserPreferences(userPreferences);
- engine.addFilter(configuration.saveIncludeConfigXml().getAbsolutePath(), true);
- engine.addFilter(configuration.saveExcludeConfigXml().getAbsolutePath(), false);
+ engine.addFilter(configuration.saveIncludeConfigXml(), true);
+ engine.addFilter(configuration.saveExcludeConfigXml(), false);
engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance());
engine.setAnalysisFeatureSettings(FindBugs.DEFAULT_EFFORT);
@@ -72,8 +77,8 @@ public class FindbugsExecutor implements BatchExtension {
engine.finishSettings();
Executors.newSingleThreadExecutor()
- .submit(new FindbugsTask(engine))
- .get(configuration.getTimeout(), TimeUnit.MILLISECONDS);
+ .submit(new FindbugsTask(engine))
+ .get(configuration.getTimeout(), TimeUnit.MILLISECONDS);
profiler.stop();
return xmlReport;
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsNativeSensor.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsNativeSensor.java
index 6bf24b8f0e9..08e9dcc865e 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsNativeSensor.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsNativeSensor.java
@@ -33,7 +33,7 @@ public class FindbugsNativeSensor implements Sensor {
public boolean shouldExecuteOnProject(Project project) {
return project.getFileSystem().hasJavaSourceFiles()
- && !profile.getActiveRulesByRepository(FindbugsConstants.REPOSITORY_KEY).isEmpty()
+ && ( !profile.getActiveRulesByRepository(FindbugsConstants.REPOSITORY_KEY).isEmpty() || project.getReuseExistingRulesConfig())
&& project.getPom() != null && !StringUtils.equalsIgnoreCase(project.getPom().getPackaging(), "ear");
}
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 ce41df5002b..d4e9706dc34 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
@@ -1,5 +1,11 @@
package org.sonar.plugins.findbugs;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.internal.matchers.StringContains.containsString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.sonar.api.utils.SonarException;
@@ -8,12 +14,6 @@ import edu.umd.cs.findbugs.Project;
import java.io.File;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.internal.matchers.StringContains.containsString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
public class FindbugsExecutorTest {
@Test
@@ -46,8 +46,8 @@ public class FindbugsExecutorTest {
project.addSourceDir(new File("test-resources/src").getCanonicalPath());
project.setCurrentWorkingDirectory(new File("test-resources"));
when(conf.getFindbugsProject()).thenReturn(project);
- when(conf.saveExcludeConfigXml()).thenReturn(new File("test-resources/findbugs-exclude.xml"));
- when(conf.saveIncludeConfigXml()).thenReturn(new File("test-resources/findbugs-include.xml"));
+ when(conf.saveExcludeConfigXml()).thenReturn(new File("test-resources/findbugs-exclude.xml").getAbsolutePath());
+ when(conf.saveIncludeConfigXml()).thenReturn(new File("test-resources/findbugs-include.xml").getAbsolutePath());
when(conf.getEffort()).thenReturn("default");
when(conf.getTimeout()).thenReturn(FindbugsConstants.FINDBUGS_TIMEOUT_DEFAULT_VALUE);
return conf;