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;
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;
}
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;
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);
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) {
}
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]));
}
public static FilePredicate doesNotMatchPathPatterns(String[] exclusionPatterns) {
+ if (exclusionPatterns.length == 0) {
+ return ALWAYS_TRUE;
+ }
return not(matchesPathPatterns(exclusionPatterns));
}