aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-09-26 12:16:31 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-09-26 12:17:00 +0200
commit00126a9dca35e1b62509ea8f044753d8ad05f2b0 (patch)
treec5f51a468bbddfb94b871ed36c2616ff80ad7cb1
parent7d741a1e1ccb6ae5b756150f4c389e3629ef7719 (diff)
downloadsonarqube-00126a9dca35e1b62509ea8f044753d8ad05f2b0.tar.gz
sonarqube-00126a9dca35e1b62509ea8f044753d8ad05f2b0.zip
SONAR-2827 The property sonar.exclusions can not be changed by extensions
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java26
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java17
2 files changed, 28 insertions, 15 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java
index f594d194835..f7bc914d5fe 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java
@@ -19,8 +19,9 @@
*/
package org.sonar.plugins.core.batch;
+import org.apache.commons.configuration.Configuration;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ResourceFilter;
-import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
@@ -29,14 +30,10 @@ import org.sonar.api.resources.ResourceUtils;
*/
public class ExcludedResourceFilter implements ResourceFilter {
- private String[] exclusionPatterns;
+ private Configuration conf;
- public ExcludedResourceFilter(Project project) {
- this(project.getExclusionPatterns());
- }
-
- protected ExcludedResourceFilter(String[] exclusionPatterns) {
- this.exclusionPatterns = (exclusionPatterns==null ? new String[0] : exclusionPatterns);
+ public ExcludedResourceFilter(Configuration conf) {
+ this.conf = conf;
}
public boolean isIgnored(Resource resource) {
@@ -45,11 +42,18 @@ public class ExcludedResourceFilter implements ResourceFilter {
return false;
}
- for (String pattern : exclusionPatterns) {
- if (resource.matchFilePattern(pattern)) {
- return true;
+ String[] patterns = getExclusionPatterns();
+ if (patterns != null) {
+ for (String pattern : patterns) {
+ if (resource.matchFilePattern(pattern)) {
+ return true;
+ }
}
}
return false;
}
+
+ String[] getExclusionPatterns() {
+ return conf.getStringArray(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY);
+ }
} \ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java
index 2079725ed5e..dbbe8fd9e13 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java
@@ -19,7 +19,9 @@
*/
package org.sonar.plugins.core.batch;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
+import org.sonar.api.CoreProperties;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
@@ -32,13 +34,16 @@ public class ExcludedResourceFilterTest {
@Test
public void doNotFailIfNoPatterns() {
- ExcludedResourceFilter filter = new ExcludedResourceFilter((String[]) null);
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ ExcludedResourceFilter filter = new ExcludedResourceFilter(conf);
assertThat(filter.isIgnored(mock(Resource.class)), is(false));
}
@Test
public void noPatternsMatch() {
- ExcludedResourceFilter filter = new ExcludedResourceFilter(new String[]{"**/foo/*.java", "**/bar/*"});
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
+ ExcludedResourceFilter filter = new ExcludedResourceFilter(conf);
assertThat(filter.isIgnored(mock(Resource.class)), is(false));
}
@@ -47,7 +52,9 @@ public class ExcludedResourceFilterTest {
*/
@Test
public void ignoreResourceIfMatchesPattern() {
- ExcludedResourceFilter filter = new ExcludedResourceFilter(new String[]{"**/foo/*.java", "**/bar/*"});
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
+ ExcludedResourceFilter filter = new ExcludedResourceFilter(conf);
Resource resource = mock(Resource.class);
when(resource.matchFilePattern("**/bar/*")).thenReturn(true);
@@ -57,7 +64,9 @@ public class ExcludedResourceFilterTest {
@Test
public void doNotExcludeUnitTestFiles() {
- ExcludedResourceFilter filter = new ExcludedResourceFilter(new String[]{"**/foo/*.java", "**/bar/*"});
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
+ ExcludedResourceFilter filter = new ExcludedResourceFilter(conf);
Resource unitTest = mock(Resource.class);
when(unitTest.getQualifier()).thenReturn(Qualifiers.UNIT_TEST_FILE);