aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-findbugs-plugin
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-21 15:50:56 +0000
committerGodin <mandrikov@gmail.com>2010-10-21 15:50:56 +0000
commitec338d6e49b8aa9b4f53237cbf4d598ca87a8db9 (patch)
treed901d6a914baf9f8e3eef819dd2f8ae2a5b0c899 /plugins/sonar-findbugs-plugin
parentbe88575d78fa32e4f493de883dfe2e50ae3af060 (diff)
downloadsonarqube-ec338d6e49b8aa9b4f53237cbf4d598ca87a8db9.tar.gz
sonarqube-ec338d6e49b8aa9b4f53237cbf4d598ca87a8db9.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.java14
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java11
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java10
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java16
4 files changed, 25 insertions, 26 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 34e2699ba7c..95e30fe637e 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
@@ -63,7 +63,7 @@ public class FindbugsConfiguration implements BatchExtension {
findbugsProject.addAuxClasspathEntry(file.getAbsolutePath());
}
}
- findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBasedir());
+ findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBuildDir());
return findbugsProject;
}
@@ -71,23 +71,23 @@ public class FindbugsConfiguration implements BatchExtension {
return MavenPlugin.getPlugin(project.getPom(), MavenUtils.GROUP_ID_CODEHAUS_MOJO, "findbugs-maven-plugin");
}
- public String saveIncludeConfigXml() throws IOException {
+ public File saveIncludeConfigXml() throws IOException {
if (project.getReuseExistingRulesConfig()) {
String existingIncludeFilterConfig = getFindbugsMavenPlugin().getParameter("includeFilterFile");
if ( !StringUtils.isBlank(existingIncludeFilterConfig)) {
- return existingIncludeFilterConfig;
+ return new File(project.getFileSystem().getBasedir(), existingIncludeFilterConfig);
}
}
StringWriter conf = new StringWriter();
exporter.exportProfile(profile, conf);
- return project.getFileSystem().writeToWorkingDirectory(conf.toString(), "findbugs-include.xml").getAbsolutePath();
+ return project.getFileSystem().writeToWorkingDirectory(conf.toString(), "findbugs-include.xml");
}
- public String saveExcludeConfigXml() throws IOException {
+ public File saveExcludeConfigXml() throws IOException {
if (project.getReuseExistingRulesConfig()) {
String existingExcludeFilterConfig = getFindbugsMavenPlugin().getParameter("excludeFilterFile");
if ( !StringUtils.isBlank(existingExcludeFilterConfig)) {
- return existingExcludeFilterConfig;
+ return new File(project.getFileSystem().getBasedir(), existingExcludeFilterConfig);
}
}
FindBugsFilter findBugsFilter = new FindBugsFilter();
@@ -97,7 +97,7 @@ public class FindbugsConfiguration implements BatchExtension {
findBugsFilter.addMatch(new Match(classFilter));
}
}
- return project.getFileSystem().writeToWorkingDirectory(findBugsFilter.toXml(), "findbugs-exclude.xml").getAbsolutePath();
+ return project.getFileSystem().writeToWorkingDirectory(findBugsFilter.toXml(), "findbugs-exclude.xml");
}
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 e182f2d3ebb..93831dfe9c5 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,12 +9,7 @@ import org.sonar.api.BatchExtension;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.TimeProfiler;
-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.*;
import edu.umd.cs.findbugs.config.UserPreferences;
import java.io.File;
@@ -68,8 +63,8 @@ public class FindbugsExecutor implements BatchExtension {
userPreferences.setEffort(configuration.getEffort());
engine.setUserPreferences(userPreferences);
- engine.addFilter(configuration.saveIncludeConfigXml(), true);
- engine.addFilter(configuration.saveExcludeConfigXml(), false);
+ engine.addFilter(configuration.saveIncludeConfigXml().getAbsolutePath(), true);
+ engine.addFilter(configuration.saveExcludeConfigXml().getAbsolutePath(), false);
engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance());
engine.setAnalysisFeatureSettings(FindBugs.DEFAULT_EFFORT);
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
index baef38169c9..b4e84de80bd 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
@@ -4,9 +4,10 @@ import org.junit.Test;
import org.sonar.api.batch.maven.MavenPlugin;
import org.sonar.api.batch.maven.MavenUtils;
import org.sonar.api.resources.Project;
+import org.sonar.api.resources.ProjectFileSystem;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -17,6 +18,9 @@ public class FindbugsConfigurationTest {
public void shouldReuseExistingRulesConfig() throws Exception {
Project project = mock(Project.class);
when(project.getReuseExistingRulesConfig()).thenReturn(true);
+ ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
+ // when(fileSystem.getBasedir()).thenReturn(new File("/tmp"));
+ when(project.getFileSystem()).thenReturn(fileSystem);
MavenPlugin plugin = new MavenPlugin(MavenUtils.GROUP_ID_CODEHAUS_MOJO, "findbugs-maven-plugin", "2.3.1");
plugin.setParameter("excludeFilterFile", "rules/exclude.xml");
@@ -24,7 +28,7 @@ public class FindbugsConfigurationTest {
FindbugsConfiguration conf = spy(new FindbugsConfiguration(project, null, null, null));
doReturn(plugin).when(conf).getFindbugsMavenPlugin();
- assertThat(conf.saveExcludeConfigXml(), is("rules/exclude.xml"));
- assertThat(conf.saveIncludeConfigXml(), is("rules/include.xml"));
+ assertThat(conf.saveExcludeConfigXml(), notNullValue());
+ assertThat(conf.saveIncludeConfigXml(), notNullValue());
}
}
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 d4e9706dc34..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
@@ -1,11 +1,5 @@
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;
@@ -14,6 +8,12 @@ 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").getAbsolutePath());
- when(conf.saveIncludeConfigXml()).thenReturn(new File("test-resources/findbugs-include.xml").getAbsolutePath());
+ when(conf.saveExcludeConfigXml()).thenReturn(new File("test-resources/findbugs-exclude.xml"));
+ when(conf.saveIncludeConfigXml()).thenReturn(new File("test-resources/findbugs-include.xml"));
when(conf.getEffort()).thenReturn("default");
when(conf.getTimeout()).thenReturn(FindbugsConstants.FINDBUGS_TIMEOUT_DEFAULT_VALUE);
return conf;