]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 fix support of CPD without exclusion patterns
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 20 Feb 2014 10:50:41 +0000 (11:50 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 20 Feb 2014 10:50:50 +0000 (11:50 +0100)
plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java
plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java

index 14b073d671129464492f6f8e714b9bbbda0655c3..0ff44946650f8b59a8376e9bb7f1af2f516bce13 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.plugins.cpd;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.CoreProperties;
@@ -80,12 +81,12 @@ public class SonarBridgeEngine extends CpdEngine {
   public void analyse(Project project, String languageKey, SensorContext context) {
     String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
     logExclusions(cpdExclusions, LOG);
-    Iterable<InputFile> sourceFiles = fs.inputFiles(FilePredicates.and(
+    List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(FilePredicates.and(
       FilePredicates.hasType(InputFile.Type.MAIN),
       FilePredicates.hasLanguage(languageKey),
       FilePredicates.doesNotMatchPathPatterns(cpdExclusions)
-    ));
-    if (!sourceFiles.iterator().hasNext()) {
+    )));
+    if (sourceFiles.isEmpty()) {
       return;
     }
 
index 0b340ce17c4020558f90669d6eb8d41657e94318..d463d8cf3148e3bfb1703bee26745cfb10fb2d9a 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.plugins.cpd;
 
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.slf4j.Logger;
@@ -93,12 +94,12 @@ public class SonarEngine extends CpdEngine {
   public void analyse(Project project, String languageKey, SensorContext context) {
     String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
     logExclusions(cpdExclusions, LOG);
-    Iterable<InputFile> sourceFiles = fs.inputFiles(FilePredicates.and(
+    List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(FilePredicates.and(
       FilePredicates.hasType(InputFile.Type.MAIN),
       FilePredicates.hasLanguage(languageKey),
       FilePredicates.doesNotMatchPathPatterns(cpdExclusions)
-    ));
-    if (!sourceFiles.iterator().hasNext()) {
+    )));
+    if (sourceFiles.isEmpty()) {
       return;
     }
     SonarDuplicationsIndex index = createIndex(project, sourceFiles);
@@ -135,7 +136,7 @@ public class SonarEngine extends CpdEngine {
     return index;
   }
 
-  private void detect(SonarDuplicationsIndex index, SensorContext context, Iterable<InputFile> sourceFiles) {
+  private void detect(SonarDuplicationsIndex index, SensorContext context, List<InputFile> sourceFiles) {
     ExecutorService executorService = Executors.newSingleThreadExecutor();
     try {
       for (InputFile inputFile : sourceFiles) {
index 877666c733bbf7e40c0614b23b307a2a485ab990..16c79cb962e2b6175f1603fcf4e5e85ecd7e5519 100644 (file)
@@ -65,6 +65,9 @@ public class FilePredicates {
   }
 
   public static FilePredicate matchesPathPatterns(String[] inclusionPatterns) {
+    if (inclusionPatterns.length == 0) {
+      return ALWAYS_TRUE;
+    }
     FilePredicate[] predicates = new FilePredicate[inclusionPatterns.length];
     for (int i = 0; i < inclusionPatterns.length; i++) {
       predicates[i] = new PathPatternPredicate(PathPattern.create(inclusionPatterns[i]));
@@ -77,6 +80,9 @@ public class FilePredicates {
   }
 
   public static FilePredicate doesNotMatchPathPatterns(String[] exclusionPatterns) {
+    if (exclusionPatterns.length == 0) {
+      return ALWAYS_TRUE;
+    }
     return not(matchesPathPatterns(exclusionPatterns));
   }