*/
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;
*/
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) {
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
*/
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;
@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));
}
*/
@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);
@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);