aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java22
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java45
2 files changed, 42 insertions, 25 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java
index 5ecf6606dc0..e1e5c4d1fcc 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java
@@ -21,6 +21,7 @@ package org.sonar.batch.bootstrap;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
+import org.slf4j.LoggerFactory;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
@@ -40,7 +41,7 @@ public class ProjectFilter {
public boolean isExcluded(Project project) {
Project p = project;
while (p != null) {
- if (isExcluded(getArtifactId(p))) {
+ if (isExcludedModule(getArtifactId(p), p.isRoot())) {
return true;
}
p = p.getParent();
@@ -48,14 +49,21 @@ public class ProjectFilter {
return false;
}
- private boolean isExcluded(String artifactId) {
+ private boolean isExcludedModule(String artifactId, boolean isRoot) {
String[] includedArtifactIds = settings.getStringArray("sonar.includedModules");
-
- if (includedArtifactIds.length > 0) {
- return !ArrayUtils.contains(includedArtifactIds, artifactId);
+ boolean excluded = false;
+ if (!isRoot && includedArtifactIds.length > 0) {
+ excluded = !ArrayUtils.contains(includedArtifactIds, artifactId);
+ }
+ if (!excluded) {
+ String[] excludedArtifactIds = settings.getStringArray("sonar.skippedModules");
+ excluded = ArrayUtils.contains(excludedArtifactIds, artifactId);
+ }
+ if (excluded && isRoot) {
+ LoggerFactory.getLogger(getClass()).warn("The root module can't be excluded: " + artifactId);
+ excluded = false;
}
- String[] excludedArtifactIds = settings.getStringArray("sonar.skippedModules");
- return ArrayUtils.contains(excludedArtifactIds, artifactId);
+ return excluded;
}
// TODO see http://jira.codehaus.org/browse/SONAR-2324
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java
index d01f5150bf9..3d5b4eaa545 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java
@@ -22,51 +22,60 @@ package org.sonar.batch.bootstrap;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
-import org.sonar.batch.config.ProjectSettings;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
public class ProjectFilterTest {
+ private Project root = new Project("root");
+
@Test
- public void testSkippedModule() {
+ public void testSkippedModules() {
Settings settings = new Settings();
settings.setProperty("sonar.skippedModules", "foo,bar");
ProjectFilter filter = new ProjectFilter(settings);
- assertTrue(filter.isExcluded(new Project("my:foo")));
+ assertTrue(filter.isExcluded(new Project("foo").setParent(root)));
+ assertFalse(filter.isExcluded(new Project("other").setParent(root)));
}
@Test
- public void testNotExcluded() {
+ public void shouldNotSkipRoot() {
Settings settings = new Settings();
- settings.setProperty("sonar.skippedModules", "foo,bar");
-
+ settings.setProperty("sonar.skippedModules", "root,foo,bar");
ProjectFilter filter = new ProjectFilter(settings);
- assertFalse(filter.isExcluded(new Project("my:other")));
+
+ assertFalse(filter.isExcluded(root));
}
+
@Test
public void testNoSkippedModules() {
Settings settings = new Settings();
-
ProjectFilter filter = new ProjectFilter(settings);
- assertFalse(filter.isExcluded(new Project("my:other")));
+
+ assertFalse(filter.isExcluded(new Project("foo").setParent(root)));
+ assertFalse(filter.isExcluded(root));
}
@Test
public void testIncludedModules() {
Settings settings = new Settings();
settings.setProperty("sonar.includedModules", "foo");
+ ProjectFilter filter = new ProjectFilter(settings);
+
+ assertFalse(filter.isExcluded(new Project("foo").setParent(root)));
+ assertTrue(filter.isExcluded(new Project("bar").setParent(root)));
+ }
+ @Test
+ public void shouldNotIncludeRoot() {
+ Settings settings = new Settings();
+ settings.setProperty("sonar.includedModules", "foo,bar");
ProjectFilter filter = new ProjectFilter(settings);
- assertFalse(filter.isExcluded(new Project("my:foo")));
- filter = new ProjectFilter(settings);
- assertTrue(filter.isExcluded(new Project("my:bar")));
+ assertFalse(filter.isExcluded(root));
}
@Test
@@ -74,11 +83,11 @@ public class ProjectFilterTest {
Settings settings = new Settings();
settings.setProperty("sonar.skippedModules", "parent");
- Project parent = new Project("my:parent");
- Project child = new Project("my:child");
- child.setParent(parent);
+ Project parent = new Project("parent").setParent(root);
+ Project child = new Project("child").setParent(parent);
ProjectFilter filter = new ProjectFilter(settings);
+ assertTrue(filter.isExcluded(parent));
assertTrue(filter.isExcluded(child));
}