From 2b75ca36f7546d358d7f65861f858086371b8ade Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 22 Dec 2011 14:51:08 +0100 Subject: SONAR-3096 Exclude source sub-directories starting with a dot --- .../org/sonar/api/resources/DefaultProjectFileSystem.java | 8 +++++--- .../sonar/api/resources/DefaultProjectFileSystemTest.java | 13 +++++++++++++ .../src/org/.dirPrefixedWithDot/Excluded.java | 1 + .../src/org/.sonar/Excluded2.java | 1 + .../src/org/sonar/Included.java | 3 +++ 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.dirPrefixedWithDot/Excluded.java create mode 100644 sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/.sonar/Excluded2.java create mode 100644 sonar-plugin-api/test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src/org/sonar/Included.java (limited to 'sonar-plugin-api') 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 getFiles(List directories, List initialFiles, boolean applyExclusionPatterns, String... langs) { + List getFiles(List directories, List initialFiles, boolean applyExclusionPatterns, String... langs) { List result = Lists.newArrayList(); if (directories == null) { return result; @@ -224,8 +225,9 @@ public class DefaultProjectFileSystem implements ProjectFileSystem { IOFileFilter visibleFileFilter = HiddenFileFilter.VISIBLE; List fileFilters = Lists.newArrayList(visibleFileFilter, suffixFilter, exclusionFilter, initialFilesFilter); fileFilters.addAll(this.filters); - - List files = (List) FileUtils.listFiles(dir, new AndFileFilter(fileFilters), HiddenFileFilter.VISIBLE); + + IOFileFilter dotPrefixDirFilter = FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter(".")); + List files = (List) 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 dirs = Arrays.asList(new File("test-resources/org/sonar/api/resources/DefaultProjectFileSystemTest/shouldExcludeDirectoriesStartingWithDot/src")); + + List files = new DefaultProjectFileSystem(null, null).getFiles(dirs, Collections.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 -- cgit v1.2.3