aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-18 10:23:13 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-18 10:23:30 +0100
commit53370037d059598f10423a1576e6881a20b30f04 (patch)
tree46efc2a21d8c8dda12fccbc7eb6051a9438ef550 /sonar-batch
parent1dd34aeb44a7a8b46d74f3fd2b140b30c96f6a22 (diff)
downloadsonarqube-53370037d059598f10423a1576e6881a20b30f04.tar.gz
sonarqube-53370037d059598f10423a1576e6881a20b30f04.zip
SONAR-5552 Display how many files are excluded from the analysis
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java19
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java34
4 files changed, 59 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
index e3ff5fe20e9..16441588ac9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
@@ -53,6 +53,10 @@ public class ExclusionFilters implements BatchComponent {
log("Excluded tests: ", testExclusions);
}
+ public boolean hasPattern() {
+ return mainInclusions.length > 0 || mainExclusions.length > 0 || testInclusions.length > 0 || testExclusions.length > 0;
+ }
+
private void log(String title, PathPattern[] patterns) {
if (patterns.length > 0) {
LOG.info(title);
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 47acad7208c..c5eb6bef9b4 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
@@ -23,6 +23,8 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.HiddenFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputFile;
@@ -52,6 +54,8 @@ import java.util.concurrent.TimeUnit;
*/
public class FileIndexer implements BatchComponent {
+ private static final Logger LOG = LoggerFactory.getLogger(FileIndexer.class);
+
private static final IOFileFilter DIR_FILTER = FileFilterUtils.and(HiddenFileFilter.VISIBLE, FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter(".")));
private static final IOFileFilter FILE_FILTER = HiddenFileFilter.VISIBLE;
@@ -94,6 +98,10 @@ public class FileIndexer implements BatchComponent {
waitForTasksToComplete();
progressReport.stop(progress.count() + " files indexed");
+
+ if (exclusionFilters.hasPattern()) {
+ LOG.info(progress.excludedByPatternsCount() + " files ignored because of inclusion/exclusion patterns");
+ }
}
private void waitForTasksToComplete() {
@@ -134,6 +142,8 @@ public class FileIndexer implements BatchComponent {
inputFile.setModuleBaseDir(fileSystem.baseDirPath());
if (exclusionFilters.accept(inputFile, type)) {
indexFile(inputFileBuilder, fileSystem, progress, inputFile, type);
+ } else {
+ progress.increaseExcludedByPatternsCount();
}
}
}
@@ -174,6 +184,7 @@ public class FileIndexer implements BatchComponent {
private class Progress {
private final Set<Path> indexed = new HashSet<>();
+ private int excludedByPatternsCount = 0;
synchronized void markAsIndexed(InputFile inputFile) {
if (indexed.contains(inputFile.path())) {
@@ -184,6 +195,14 @@ public class FileIndexer implements BatchComponent {
progressReport.message(indexed.size() + " files indexed... (last one was " + inputFile.relativePath() + ")");
}
+ void increaseExcludedByPatternsCount() {
+ excludedByPatternsCount++;
+ }
+
+ public int excludedByPatternsCount() {
+ return excludedByPatternsCount;
+ }
+
int count() {
return indexed.size();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java
index 8f9297078c5..cc940ae1361 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java
@@ -138,13 +138,13 @@ public class CpdMediumTest {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
- String duplicatedStuff = "Sample xoo\nfoo\n";
+ String duplicatedStuff = "Sample xoo\n";
int blockCount = 10000;
File xooFile1 = new File(srcDir, "sample.xoo");
for (int i = 0; i < blockCount; i++) {
FileUtils.write(xooFile1, duplicatedStuff, true);
- FileUtils.write(xooFile1, "" + i, true);
+ FileUtils.write(xooFile1, "" + i + "\n", true);
}
TaskResult result = tester.newTask()
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
index 03c40181906..72023e2e180 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
@@ -173,6 +173,40 @@ public class FileSystemMediumTest {
}
@Test
+ public void fileInclusionsExclusions() throws IOException {
+ File srcDir = new File(baseDir, "src");
+ srcDir.mkdir();
+
+ File xooFile = new File(srcDir, "sample.xoo");
+ FileUtils.write(xooFile, "Sample xoo\ncontent");
+
+ File xooFile2 = new File(baseDir, "another.xoo");
+ FileUtils.write(xooFile2, "Sample xoo 2\ncontent");
+
+ File testDir = new File(baseDir, "test");
+ testDir.mkdir();
+
+ File xooTestFile = new File(baseDir, "sampleTest2.xoo");
+ FileUtils.write(xooTestFile, "Sample test xoo\ncontent");
+
+ File xooTestFile2 = new File(testDir, "sampleTest.xoo");
+ FileUtils.write(xooTestFile2, "Sample test xoo 2\ncontent");
+
+ TaskResult result = tester.newTask()
+ .properties(builder
+ .put("sonar.sources", "src,another.xoo")
+ .put("sonar.tests", "test,sampleTest2.xoo")
+ .put("sonar.inclusions", "src/**")
+ .put("sonar.exclusions", "**/another.*")
+ .put("sonar.test.inclusions", "**/sampleTest*.*")
+ .put("sonar.test.exclusions", "**/sampleTest2.xoo")
+ .build())
+ .start();
+
+ assertThat(result.inputFiles()).hasSize(2);
+ }
+
+ @Test
public void failForDuplicateInputFile() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();