aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-02-13 19:05:05 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-02-13 19:06:38 +0100
commit787a472b3de5e4fe60ac6407d2cd6aa5054ab863 (patch)
tree9fca565ebaf1f5ce2bc51d79d5e355c23124552f
parentdea30cbbfe616b707fb8681a2d26c19132b942af (diff)
downloadsonarqube-787a472b3de5e4fe60ac6407d2cd6aa5054ab863.tar.gz
sonarqube-787a472b3de5e4fe60ac6407d2cd6aa5054ab863.zip
SONAR-2760 file exclusions by absolute path
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ScanContainer.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFileFilter.java122
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileFilterContext.java18
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFileFilterTest.java47
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileExclusions.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleExclusions.java)6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileFilter.java9
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/FileExclusionsTest.java (renamed from sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/ModuleExclusionsTest.java)10
9 files changed, 173 insertions, 54 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ScanContainer.java
index 35a0273109a..44b8ad2a22a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ScanContainer.java
@@ -26,7 +26,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
-import org.sonar.api.scan.filesystem.ModuleExclusions;
+import org.sonar.api.scan.filesystem.FileExclusions;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.batch.DefaultProfileLoader;
import org.sonar.batch.DefaultProjectClasspath;
@@ -96,7 +96,7 @@ public class ScanContainer extends Container {
// file system
container.addSingleton(PathResolver.class);
- container.addSingleton(ModuleExclusions.class);
+ container.addSingleton(FileExclusions.class);
container.addSingleton(LanguageFileFilters.class);
container.addSingleton(ExclusionFileFilter.class);
container.addSingleton(DefaultProjectClasspath.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
index 0e9e7734a22..a00aadd3af5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
@@ -174,6 +174,11 @@ public class DefaultModuleFileSystem implements ModuleFileSystem {
private boolean accept(File file, FileFilterContext context) {
context.setFileRelativePath(pathResolver.relativePath(context.sourceDir(), file));
+ try {
+ context.setFileCanonicalPath(file.getCanonicalPath());
+ } catch (Exception e) {
+ throw new IllegalStateException("Fail to get the canonical path of: " + file);
+ }
for (FileFilter fileFilter : fileFilters) {
if (!fileFilter.accept(file, context)) {
return false;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFileFilter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFileFilter.java
index ee6470cbe57..a6fe2f7793f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFileFilter.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFileFilter.java
@@ -19,62 +19,63 @@
*/
package org.sonar.batch.scan.filesystem;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.ResourceFilter;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
+import org.sonar.api.scan.filesystem.FileExclusions;
import org.sonar.api.scan.filesystem.FileFilter;
-import org.sonar.api.scan.filesystem.ModuleExclusions;
import org.sonar.api.utils.WildcardPattern;
import java.io.File;
public class ExclusionFileFilter implements FileFilter, ResourceFilter, BatchComponent {
- private final WildcardPattern[] sourceInclusions;
- private final WildcardPattern[] testInclusions;
- private final WildcardPattern[] sourceExclusions;
- private final WildcardPattern[] testExclusions;
+ private final FilePattern[] sourceInclusions;
+ private final FilePattern[] testInclusions;
+ private final FilePattern[] sourceExclusions;
+ private final FilePattern[] testExclusions;
- public ExclusionFileFilter(ModuleExclusions exclusions) {
- sourceInclusions = WildcardPattern.create(exclusions.sourceInclusions());
+ public ExclusionFileFilter(FileExclusions exclusions) {
+ sourceInclusions = FilePattern.create(exclusions.sourceInclusions());
log("Included sources: ", sourceInclusions);
- sourceExclusions = WildcardPattern.create(exclusions.sourceExclusions());
+ sourceExclusions = FilePattern.create(exclusions.sourceExclusions());
log("Excluded sources: ", sourceExclusions);
- testInclusions = WildcardPattern.create(exclusions.testInclusions());
+ testInclusions = FilePattern.create(exclusions.testInclusions());
log("Included tests: ", testInclusions);
- testExclusions = WildcardPattern.create(exclusions.testExclusions());
+ testExclusions = FilePattern.create(exclusions.testExclusions());
log("Excluded tests: ", testExclusions);
}
- private void log(String title, WildcardPattern[] patterns) {
+ private void log(String title, FilePattern[] patterns) {
if (patterns.length > 0) {
Logger log = LoggerFactory.getLogger(ExclusionFileFilter.class);
log.info(title);
- for (WildcardPattern pattern : patterns) {
+ for (FilePattern pattern : patterns) {
log.info(" " + pattern);
}
}
}
public boolean accept(File file, Context context) {
- WildcardPattern[] inclusionPatterns = (context.fileType() == FileType.TEST ? testInclusions : sourceInclusions);
+ FilePattern[] inclusionPatterns = (context.fileType() == FileType.TEST ? testInclusions : sourceInclusions);
if (inclusionPatterns.length > 0) {
boolean matchInclusion = false;
- for (WildcardPattern pattern : inclusionPatterns) {
- matchInclusion |= pattern.match(context.fileRelativePath());
+ for (FilePattern pattern : inclusionPatterns) {
+ matchInclusion |= pattern.match(context);
}
if (!matchInclusion) {
return false;
}
}
- WildcardPattern[] exclusionPatterns = (context.fileType() == FileType.TEST ? testExclusions : sourceExclusions);
- for (WildcardPattern pattern : exclusionPatterns) {
- if (pattern.match(context.fileRelativePath())) {
+ FilePattern[] exclusionPatterns = (context.fileType() == FileType.TEST ? testExclusions : sourceExclusions);
+ for (FilePattern pattern : exclusionPatterns) {
+ if (pattern.match(context)) {
return false;
}
}
@@ -89,38 +90,103 @@ public class ExclusionFileFilter implements FileFilter, ResourceFilter, BatchCom
}
private boolean isIgnoredFileResource(Resource resource) {
- WildcardPattern[] inclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testInclusions : sourceInclusions);
+ FilePattern[] inclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testInclusions : sourceInclusions);
if (inclusionPatterns.length > 0) {
boolean matchInclusion = false;
- for (WildcardPattern pattern : inclusionPatterns) {
- matchInclusion |= resource.matchFilePattern(pattern.toString());
+ for (FilePattern pattern : inclusionPatterns) {
+ matchInclusion |= pattern.match(resource);
}
if (!matchInclusion) {
return true;
}
}
- WildcardPattern[] exclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testExclusions : sourceExclusions);
- for (WildcardPattern pattern : exclusionPatterns) {
- if (resource.matchFilePattern(pattern.toString())) {
+ FilePattern[] exclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testExclusions : sourceExclusions);
+ for (FilePattern pattern : exclusionPatterns) {
+ if (pattern.match(resource)) {
return true;
}
}
return false;
}
- WildcardPattern[] sourceInclusions() {
+ FilePattern[] sourceInclusions() {
return sourceInclusions;
}
- WildcardPattern[] testInclusions() {
+ FilePattern[] testInclusions() {
return testInclusions;
}
- WildcardPattern[] sourceExclusions() {
+ FilePattern[] sourceExclusions() {
return sourceExclusions;
}
- WildcardPattern[] testExclusions() {
+ FilePattern[] testExclusions() {
return testExclusions;
}
+
+ static abstract class FilePattern {
+ final WildcardPattern pattern;
+
+ protected FilePattern(String pattern) {
+ this.pattern = WildcardPattern.create(pattern);
+ }
+
+ abstract boolean match(Context context);
+
+ abstract boolean match(Resource resource);
+
+ static FilePattern create(String s) {
+ if (StringUtils.startsWithIgnoreCase(s, "file:")) {
+ return new AbsolutePathPattern(StringUtils.substring(s, "file:".length()));
+ }
+ return new RelativePathPattern(s);
+ }
+
+ static FilePattern[] create(String[] s) {
+ FilePattern[] result = new FilePattern[s.length];
+ for (int i = 0; i < s.length; i++) {
+ result[i] = FilePattern.create(s[i]);
+ }
+ return result;
+ }
+ }
+
+ private static class AbsolutePathPattern extends FilePattern {
+ private AbsolutePathPattern(String pattern) {
+ super(pattern);
+ }
+
+ boolean match(Context context) {
+ return pattern.match(context.fileCanonicalPath());
+ }
+
+ boolean match(Resource resource) {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "file:" + pattern.toString();
+ }
+ }
+
+ private static class RelativePathPattern extends FilePattern {
+ private RelativePathPattern(String pattern) {
+ super(pattern);
+ }
+
+ boolean match(Context context) {
+ return pattern.match(context.fileRelativePath());
+ }
+
+ boolean match(Resource resource) {
+ return resource.matchFilePattern(pattern.toString());
+ }
+
+ @Override
+ public String toString() {
+ return pattern.toString();
+ }
+ }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileFilterContext.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileFilterContext.java
index 937eb6e0421..86436bbc2ee 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileFilterContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileFilterContext.java
@@ -29,6 +29,7 @@ class FileFilterContext implements FileFilter.Context {
private final FileFilter.FileType fileType;
private File sourceDir;
private String fileRelativePath;
+ private String fileCanonicalPath;
FileFilterContext(ModuleFileSystem fileSystem, FileFilter.FileType fileType) {
this.fileSystem = fileSystem;
@@ -51,13 +52,22 @@ class FileFilterContext implements FileFilter.Context {
return fileRelativePath;
}
- FileFilterContext setSourceDir(File sourceDir) {
- this.sourceDir = sourceDir;
+ public String fileCanonicalPath() {
+ return fileCanonicalPath;
+ }
+
+ FileFilterContext setSourceDir(File d) {
+ this.sourceDir = d;
+ return this;
+ }
+
+ FileFilterContext setFileRelativePath(String s) {
+ this.fileRelativePath = s;
return this;
}
- FileFilterContext setFileRelativePath(String fileRelativePath) {
- this.fileRelativePath = fileRelativePath;
+ FileFilterContext setFileCanonicalPath(String s) {
+ this.fileCanonicalPath = s;
return this;
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFileFilterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFileFilterTest.java
index 0bdf7ea726b..f1f86021332 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFileFilterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFileFilterTest.java
@@ -26,8 +26,9 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.File;
import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Project;
+import org.sonar.api.scan.filesystem.FileExclusions;
import org.sonar.api.scan.filesystem.FileFilter;
-import org.sonar.api.scan.filesystem.ModuleExclusions;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import java.io.IOException;
@@ -43,7 +44,7 @@ public class ExclusionFileFilterTest {
public void source_inclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
- ExclusionFileFilter filter = new ExclusionFileFilter(new ModuleExclusions(settings));
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
FileFilterContext context = new FileFilterContext(mock(ModuleFileSystem.class), FileFilter.FileType.SOURCE);
context.setFileRelativePath("com/mycompany/Foo.java");
@@ -62,7 +63,7 @@ public class ExclusionFileFilterTest {
public void source_exclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.java");
- ExclusionFileFilter filter = new ExclusionFileFilter(new ModuleExclusions(settings));
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
FileFilterContext context = new FileFilterContext(mock(ModuleFileSystem.class), FileFilter.FileType.SOURCE);
context.setFileRelativePath("com/mycompany/FooDao.java");
@@ -78,10 +79,29 @@ public class ExclusionFileFilterTest {
}
@Test
+ public void source_exclusion_by_absolute_path() throws IOException {
+ java.io.File includedFile = temp.newFile("Foo.java");
+ java.io.File excludedFile = temp.newFile("Bar.java");
+
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:" + excludedFile.getCanonicalPath());
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
+
+ FileFilterContext context = new FileFilterContext(mock(ModuleFileSystem.class), FileFilter.FileType.SOURCE);
+ context.setFileRelativePath("org/bar/Foo.java");
+ context.setFileCanonicalPath(includedFile.getCanonicalPath());
+ assertThat(filter.accept(includedFile, context)).isTrue();
+
+ context.setFileRelativePath("org/bar/Bar.java");
+ context.setFileCanonicalPath(excludedFile.getCanonicalPath());
+ assertThat(filter.accept(excludedFile, context)).isFalse();
+ }
+
+ @Test
public void resource_inclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.c");
- ExclusionFileFilter filter = new ExclusionFileFilter(new ModuleExclusions(settings));
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
assertThat(filter.isIgnored(new File("org/sonar", "FooDao.c"))).isFalse();
assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isTrue();
@@ -91,7 +111,7 @@ public class ExclusionFileFilterTest {
public void resource_exclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.c");
- ExclusionFileFilter filter = new ExclusionFileFilter(new ModuleExclusions(settings));
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
assertThat(filter.isIgnored(new File("org/sonar", "FooDao.c"))).isTrue();
assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isFalse();
@@ -104,7 +124,7 @@ public class ExclusionFileFilterTest {
public void java_resource_inclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
- ExclusionFileFilter filter = new ExclusionFileFilter(new ModuleExclusions(settings));
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
assertThat(filter.isIgnored(new JavaFile("org.sonar", "FooDao"))).isFalse();
assertThat(filter.isIgnored(new JavaFile("org.sonar", "Foo"))).isTrue();
@@ -117,20 +137,29 @@ public class ExclusionFileFilterTest {
public void java_resource_exclusions() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.java");
- ExclusionFileFilter filter = new ExclusionFileFilter(new ModuleExclusions(settings));
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
assertThat(filter.isIgnored(new JavaFile("org.sonar", "FooDao"))).isTrue();
assertThat(filter.isIgnored(new JavaFile("org.sonar", "Foo"))).isFalse();
}
@Test
+ public void do_not_check_exclusions_on_non_file_resources() throws IOException {
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "*");
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
+
+ assertThat(filter.isIgnored(new Project("MyProject"))).isFalse();
+ }
+
+ @Test
public void test_settings() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "source/inclusions");
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "source/exclusions");
settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "test/inclusions");
settings.setProperty(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY, "test/exclusions");
- ExclusionFileFilter filter = new ExclusionFileFilter(new ModuleExclusions(settings));
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
assertThat(filter.sourceInclusions()[0].toString()).isEqualTo("source/inclusions");
assertThat(filter.testInclusions()[0].toString()).isEqualTo("test/inclusions");
@@ -142,7 +171,7 @@ public class ExclusionFileFilterTest {
public void should_trim_pattern() throws IOException {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, " **/*Dao.java ");
- ExclusionFileFilter filter = new ExclusionFileFilter(new ModuleExclusions(settings));
+ ExclusionFileFilter filter = new ExclusionFileFilter(new FileExclusions(settings));
assertThat(filter.sourceExclusions()[0].toString()).isEqualTo("**/*Dao.java");
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
index 28d2b3a436a..7c99e49b36b 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
@@ -330,7 +330,7 @@ public class Project extends Resource {
* Patterns of resource exclusion as defined in project settings page.
*
* @since 3.3 also applies exclusions in general settings page and global exclusions.
- * @deprecated replaced by {@link org.sonar.api.scan.filesystem.ModuleExclusions} in version 3.5
+ * @deprecated replaced by {@link org.sonar.api.scan.filesystem.FileExclusions} in version 3.5
*/
@Deprecated
public String[] getExclusionPatterns() {
@@ -344,7 +344,7 @@ public class Project extends Resource {
* Also applies exclusions in general settings page and global exclusions.
*
* @since 3.3
- * @deprecated replaced by {@link org.sonar.api.scan.filesystem.ModuleExclusions} in version 3.5
+ * @deprecated replaced by {@link org.sonar.api.scan.filesystem.FileExclusions} in version 3.5
*/
@Deprecated
public String[] getTestExclusionPatterns() {
@@ -369,7 +369,7 @@ public class Project extends Resource {
/**
* Set exclusion patterns. Configuration is not saved, so this method must be used ONLY IN UNIT TESTS.
- * @deprecated replaced by {@link org.sonar.api.scan.filesystem.ModuleExclusions} in version 3.5
+ * @deprecated replaced by {@link org.sonar.api.scan.filesystem.FileExclusions} in version 3.5
*/
@Deprecated
public Project setExclusionPatterns(String[] s) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleExclusions.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileExclusions.java
index 7331a984419..a79929f558e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleExclusions.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileExclusions.java
@@ -33,10 +33,10 @@ import java.util.List;
*
* @since 3.5
*/
-public class ModuleExclusions implements BatchComponent {
+public class FileExclusions implements BatchComponent {
private final Settings settings;
- public ModuleExclusions(Settings settings) {
+ public FileExclusions(Settings settings) {
this.settings = settings;
}
@@ -52,7 +52,7 @@ public class ModuleExclusions implements BatchComponent {
String[] patterns = sanitize(settings.getStringArray(propertyKey));
List<String> list = Lists.newArrayList();
for (String pattern : patterns) {
- if (!"**/*".equals(pattern)) {
+ if (!"**/*".equals(pattern) && !"file:**/*".equals(pattern)) {
list.add(pattern);
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileFilter.java
index ec4067d8de4..7ff169087dc 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileFilter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileFilter.java
@@ -37,7 +37,16 @@ public interface FileFilter extends BatchExtension {
ModuleFileSystem fileSystem();
FileType fileType();
File sourceDir();
+
+ /**
+ * File path relative to source directory. Never return null.
+ */
String fileRelativePath();
+
+ /**
+ * Absolute file path. Never return null.
+ */
+ String fileCanonicalPath();
}
boolean accept(File file, Context context);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/ModuleExclusionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/FileExclusionsTest.java
index 25f52de601e..5f9d3acaeea 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/ModuleExclusionsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/FileExclusionsTest.java
@@ -25,14 +25,14 @@ import org.sonar.api.config.Settings;
import static org.fest.assertions.Assertions.assertThat;
-public class ModuleExclusionsTest {
+public class FileExclusionsTest {
@Test
public void ignore_inclusion_of_world() {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*");
settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "**/*");
- assertThat(new ModuleExclusions(settings).sourceInclusions()).isEmpty();
- assertThat(new ModuleExclusions(settings).testInclusions()).isEmpty();
+ assertThat(new FileExclusions(settings).sourceInclusions()).isEmpty();
+ assertThat(new FileExclusions(settings).testInclusions()).isEmpty();
}
@Test
@@ -40,7 +40,7 @@ public class ModuleExclusionsTest {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Foo.java");
settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "**/*FooTest.java");
- ModuleExclusions moduleExclusions = new ModuleExclusions(settings);
+ FileExclusions moduleExclusions = new FileExclusions(settings);
assertThat(moduleExclusions.sourceInclusions()).containsOnly("**/*Foo.java");
assertThat(moduleExclusions.testInclusions()).containsOnly("**/*FooTest.java");
@@ -51,7 +51,7 @@ public class ModuleExclusionsTest {
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Foo.java");
settings.setProperty(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY, "**/*FooTest.java");
- ModuleExclusions moduleExclusions = new ModuleExclusions(settings);
+ FileExclusions moduleExclusions = new FileExclusions(settings);
assertThat(moduleExclusions.sourceInclusions()).isEmpty();
assertThat(moduleExclusions.sourceExclusions()).containsOnly("**/*Foo.java");