aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-03-17 19:33:41 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-03-17 20:08:53 +0100
commita568fb063bc7f87d473ede426dd719caf8014365 (patch)
treeac6cc03cfac1b13731f5f242698174e60e9e0f7a /sonar-batch
parente7c7e73b8e6c55715c762ba3d9e8c79c7b0295c0 (diff)
downloadsonarqube-a568fb063bc7f87d473ede426dd719caf8014365.tar.gz
sonarqube-a568fb063bc7f87d473ede426dd719caf8014365.zip
SONAR-926 apply inclusions and exclusions to source directories
If sonar.sources is not set (blank), then no files are analyzed
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java24
2 files changed, 13 insertions, 15 deletions
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 1ffaa77bf29..2447fa0aaad 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
@@ -101,10 +101,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
@Override
public List<File> sourceDirs() {
- if (sourceDirs.isEmpty()) {
- // For backward compatibility with File::fromIOFile(file, sourceDirs) we need to always return something
- return Arrays.asList(baseDir());
- }
return sourceDirs;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
index eb9b3f0abae..b4afd35d7d2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
@@ -78,9 +78,14 @@ public class FileIndexer implements BatchComponent {
// Index only provided files
indexFiles(inputFileBuilder, fileSystem, progress, fileSystem.sourceFiles(), InputFile.Type.MAIN);
indexFiles(inputFileBuilder, fileSystem, progress, fileSystem.testFiles(), InputFile.Type.TEST);
- } else if (fileSystem.baseDir() != null) {
- // index from basedir
- indexDirectory(inputFileBuilder, fileSystem, progress, fileSystem.baseDir());
+ } else {
+ for (File mainDir : fileSystem.sourceDirs()) {
+ indexDirectory(inputFileBuilder, fileSystem, progress, mainDir, InputFile.Type.MAIN);
+ }
+ for (File testDir : fileSystem.testDirs()) {
+ indexDirectory(inputFileBuilder, fileSystem, progress, testDir, InputFile.Type.TEST);
+ }
+
}
// Remove files that have been removed since previous indexation
@@ -101,16 +106,13 @@ public class FileIndexer implements BatchComponent {
}
}
- private void indexDirectory(InputFileBuilder inputFileBuilder, DefaultModuleFileSystem fileSystem, Progress status, File dirToIndex) {
+ private void indexDirectory(InputFileBuilder inputFileBuilder, DefaultModuleFileSystem fileSystem, Progress status, File dirToIndex, InputFile.Type type) {
Collection<File> files = FileUtils.listFiles(dirToIndex, FILE_FILTER, DIR_FILTER);
- for (File sourceFile : files) {
- DefaultInputFile inputFile = inputFileBuilder.create(sourceFile);
+ for (File file : files) {
+ DefaultInputFile inputFile = inputFileBuilder.create(file);
if (inputFile != null) {
- if (exclusionFilters.accept(inputFile, InputFile.Type.MAIN)) {
- indexFile(inputFileBuilder, fileSystem, status, inputFile, InputFile.Type.MAIN);
- }
- if (exclusionFilters.accept(inputFile, InputFile.Type.TEST)) {
- indexFile(inputFileBuilder, fileSystem, status, inputFile, InputFile.Type.TEST);
+ if (exclusionFilters.accept(inputFile, type)) {
+ indexFile(inputFileBuilder, fileSystem, status, inputFile, type);
}
}
}