aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-12-22 14:51:08 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2011-12-22 14:51:08 +0100
commit2b75ca36f7546d358d7f65861f858086371b8ade (patch)
tree604e2d3fc96022bc91efd0e73ff79edadb0fc0db /sonar-plugin-api
parent5d02d93ba42efbf926d25126f746a632b922b1ca (diff)
downloadsonarqube-2b75ca36f7546d358d7f65861f858086371b8ade.tar.gz
sonarqube-2b75ca36f7546d358d7f65861f858086371b8ade.zip
SONAR-3096 Exclude source sub-directories starting with a dot
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java8
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java13
-rw-r--r--sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.dirPrefixedWithDot/Excluded.java1
-rw-r--r--sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.sonar/Excluded2.java1
-rw-r--r--sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/sonar/Included.java3
5 files changed, 23 insertions, 3 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java
index 1c22f52d05c..7ab9dc30d4d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/DefaultProjectFileSystem.java
@@ -23,6 +23,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOCase;
import org.apache.commons.io.filefilter.*;
import org.apache.commons.lang.CharEncoding;
import org.apache.commons.lang.StringUtils;
@@ -204,7 +205,7 @@ public class DefaultProjectFileSystem implements ProjectFileSystem {
return !testFiles(lang.getKey()).isEmpty();
}
- private List<InputFile> getFiles(List<File> directories, List<File> initialFiles, boolean applyExclusionPatterns, String... langs) {
+ List<InputFile> getFiles(List<File> directories, List<File> initialFiles, boolean applyExclusionPatterns, String... langs) {
List<InputFile> result = Lists.newArrayList();
if (directories == null) {
return result;
@@ -224,8 +225,9 @@ public class DefaultProjectFileSystem implements ProjectFileSystem {
IOFileFilter visibleFileFilter = HiddenFileFilter.VISIBLE;
List<IOFileFilter> fileFilters = Lists.newArrayList(visibleFileFilter, suffixFilter, exclusionFilter, initialFilesFilter);
fileFilters.addAll(this.filters);
-
- List<File> files = (List<File>) FileUtils.listFiles(dir, new AndFileFilter(fileFilters), HiddenFileFilter.VISIBLE);
+
+ IOFileFilter dotPrefixDirFilter = FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter("."));
+ List<File> files = (List<File>) FileUtils.listFiles(dir, new AndFileFilter(fileFilters), FileFilterUtils.and(HiddenFileFilter.VISIBLE, dotPrefixDirFilter));
for (File file : files) {
String relativePath = DefaultProjectFileSystem.getRelativePath(file, dir);
result.add(InputFileUtils.create(dir, relativePath));
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java
index 867464ce822..af412294ce0 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/DefaultProjectFileSystemTest.java
@@ -42,6 +42,7 @@ import org.sonar.api.test.MavenTestUtils;
import java.io.File;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
public class DefaultProjectFileSystemTest {
@@ -229,6 +230,18 @@ public class DefaultProjectFileSystemTest {
assertThat(filter.accept(new File("foo/World.java")), Matchers.is(false));
}
+ /**
+ * SONAR-3096
+ */
+ @Test
+ public void shouldExcludeDirectoriesStartingWithDot() {
+ List<File> dirs = Arrays.asList(new File("test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src"));
+
+ List<InputFile> files = new DefaultProjectFileSystem(null, null).getFiles(dirs, Collections.<File>emptyList(), false);
+ assertThat(files.size(), is(1));
+ assertThat(files.get(0).getRelativePath(), is("org/sonar/Included.java"));
+ }
+
private DefaultProjectFileSystem newDefaultProjectFileSystem(Project project) {
return (DefaultProjectFileSystem) project.getFileSystem();
}
diff --git a/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.dirPrefixedWithDot/Excluded.java b/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.dirPrefixedWithDot/Excluded.java
new file mode 100644
index 00000000000..9578920820c
--- /dev/null
+++ b/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.dirPrefixedWithDot/Excluded.java
@@ -0,0 +1 @@
+public class Excluded2 {} \ No newline at end of file
diff --git a/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.sonar/Excluded2.java b/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.sonar/Excluded2.java
new file mode 100644
index 00000000000..9578920820c
--- /dev/null
+++ b/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.sonar/Excluded2.java
@@ -0,0 +1 @@
+public class Excluded2 {} \ No newline at end of file
diff --git a/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/sonar/Included.java b/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/sonar/Included.java
new file mode 100644
index 00000000000..78e1aabbba7
--- /dev/null
+++ b/sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/sonar/Included.java
@@ -0,0 +1,3 @@
+package org.sonar;
+
+public class Included {} \ No newline at end of file