aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-findbugs-plugin
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-21 10:59:03 +0000
committerGodin <mandrikov@gmail.com>2010-10-21 10:59:03 +0000
commitd0127fb555aebf6c10647d4495e0534c87e073f3 (patch)
tree02352a08e629d355a48b97d1eb9b8a6b5376848a /plugins/sonar-findbugs-plugin
parent195e40ac3cf5813d5779e93e23733feb08de7ed1 (diff)
downloadsonarqube-d0127fb555aebf6c10647d4495e0534c87e073f3.tar.gz
sonarqube-d0127fb555aebf6c10647d4495e0534c87e073f3.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/FindbugsConstants.java2
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java30
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java24
4 files changed, 55 insertions, 15 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 84c3f49364d..34e2699ba7c 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,17 +63,20 @@ public class FindbugsConfiguration implements BatchExtension {
findbugsProject.addAuxClasspathEntry(file.getAbsolutePath());
}
}
- findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBuildDir());
+ findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBasedir());
return findbugsProject;
}
- private MavenPlugin getFindbugsMavenPlugin() {
+ protected 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");
+ String existingIncludeFilterConfig = getFindbugsMavenPlugin().getParameter("includeFilterFile");
+ if ( !StringUtils.isBlank(existingIncludeFilterConfig)) {
+ return existingIncludeFilterConfig;
+ }
}
StringWriter conf = new StringWriter();
exporter.exportProfile(profile, conf);
@@ -82,7 +85,10 @@ public class FindbugsConfiguration implements BatchExtension {
public String saveExcludeConfigXml() throws IOException {
if (project.getReuseExistingRulesConfig()) {
- return getFindbugsMavenPlugin().getParameter("excludeFilterFile");
+ String existingExcludeFilterConfig = getFindbugsMavenPlugin().getParameter("excludeFilterFile");
+ if ( !StringUtils.isBlank(existingExcludeFilterConfig)) {
+ return existingExcludeFilterConfig;
+ }
}
FindBugsFilter findBugsFilter = new FindBugsFilter();
if (project.getExclusionPatterns() != null) {
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConstants.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConstants.java
index 69d72ee3e13..9ca7b8de47a 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConstants.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConstants.java
@@ -32,6 +32,6 @@ public final class FindbugsConstants {
* @since 2.4
*/
public static final String GENERATE_XML_KEY = "sonar.findbugs.generateXml";
- public static final boolean GENERATE_XML_DEFAULT_VALUE = true; // TODO should be false
+ public static final boolean GENERATE_XML_DEFAULT_VALUE = true; // TODO should be false - see SONAR-1880
public static final long FINDBUGS_TIMEOUT_DEFAULT_VALUE = 600000;
}
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
new file mode 100644
index 00000000000..baef38169c9
--- /dev/null
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
@@ -0,0 +1,30 @@
+package org.sonar.plugins.findbugs;
+
+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 static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+public class FindbugsConfigurationTest {
+ @Test
+ public void shouldReuseExistingRulesConfig() throws Exception {
+ Project project = mock(Project.class);
+ when(project.getReuseExistingRulesConfig()).thenReturn(true);
+
+ MavenPlugin plugin = new MavenPlugin(MavenUtils.GROUP_ID_CODEHAUS_MOJO, "findbugs-maven-plugin", "2.3.1");
+ plugin.setParameter("excludeFilterFile", "rules/exclude.xml");
+ plugin.setParameter("includeFilterFile", "rules/include.xml");
+
+ 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"));
+ }
+}
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java
index e07429aa93e..907a5c7d83e 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsNativeSensorTest.java
@@ -1,15 +1,5 @@
package org.sonar.plugins.findbugs;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
import org.apache.commons.configuration.Configuration;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
@@ -25,6 +15,12 @@ import org.sonar.api.test.IsViolation;
import java.io.File;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.*;
+
public class FindbugsNativeSensorTest extends FindbugsTests {
@Test
@@ -35,6 +31,14 @@ public class FindbugsNativeSensorTest extends FindbugsTests {
}
@Test
+ public void shouldExecuteWhenReuseExistingRulesConfig() throws Exception {
+ FindbugsNativeSensor analyser = new FindbugsNativeSensor(RulesProfile.create(), new FindbugsRuleFinder(), null);
+ Project pom = createProject();
+ when(pom.getReuseExistingRulesConfig()).thenReturn(true);
+ assertTrue(analyser.shouldExecuteOnProject(pom));
+ }
+
+ @Test
public void shouldNotExecuteWhenNoRulesAreActive() throws Exception {
FindbugsNativeSensor analyser = new FindbugsNativeSensor(RulesProfile.create(), new FindbugsRuleFinder(), null);
Project pom = createProject();