]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4790 complete documentation of FileSystem
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 14 Mar 2014 11:41:20 +0000 (12:41 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 14 Mar 2014 11:44:24 +0000 (12:44 +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/FileSystem.java

index 9fbe470b280dcec6dd1e25cf785cfcc9ebf055dc..cf6af57a06c166e67279a01f6de2a4f3217a6590 100644 (file)
@@ -45,7 +45,11 @@ import org.sonar.plugins.cpd.index.SonarDuplicationsIndex;
 import javax.annotation.CheckForNull;
 import java.util.Collection;
 import java.util.List;
-import java.util.concurrent.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 public class SonarBridgeEngine extends CpdEngine {
 
@@ -81,10 +85,11 @@ public class SonarBridgeEngine extends CpdEngine {
   public void analyse(Project project, String languageKey, SensorContext context) {
     String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
     logExclusions(cpdExclusions, LOG);
-    List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(fs.predicates().and(
-      fs.predicates().hasType(InputFile.Type.MAIN),
-      fs.predicates().hasLanguage(languageKey),
-      fs.predicates().doesNotMatchPathPatterns(cpdExclusions)
+    FilePredicates p = fs.predicates();
+    List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and(
+      p.hasType(InputFile.Type.MAIN),
+      p.hasLanguage(languageKey),
+      p.doesNotMatchPathPatterns(cpdExclusions)
     )));
     if (sourceFiles.isEmpty()) {
       return;
index 671cebb77da7d9a556b036744095ace020632cd9..c1890f4a08cd7a82f3ec53b1a49b3ec5a14fde64 100644 (file)
@@ -93,10 +93,11 @@ public class SonarEngine extends CpdEngine {
   public void analyse(Project project, String languageKey, SensorContext context) {
     String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
     logExclusions(cpdExclusions, LOG);
-    List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(fs.predicates().and(
-      fs.predicates().hasType(InputFile.Type.MAIN),
-      fs.predicates().hasLanguage(languageKey),
-      fs.predicates().doesNotMatchPathPatterns(cpdExclusions)
+    FilePredicates p = fs.predicates();
+    List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and(
+      p.hasType(InputFile.Type.MAIN),
+      p.hasLanguage(languageKey),
+      p.doesNotMatchPathPatterns(cpdExclusions)
     )));
     if (sourceFiles.isEmpty()) {
       return;
index b362d151206773bf399501257b812ca94182a273..5172eb8d54221672c9ac606b6b071103da0bc4dc 100644 (file)
@@ -82,6 +82,13 @@ public interface FileSystem extends BatchComponent {
    * Returns the single element matching the predicate. If more than one elements match
    * the predicate, then {@link IllegalArgumentException} is thrown. Returns {@code null}
    * if no files match.
+   *
+   * <p/>
+   * How to use :
+   * <pre>
+   * InputFile file = fs.inputFile(fs.predicates().hasRelativePath("src/Foo.php"));
+   * </pre>
+   *
    * @see #predicates()
    */
   @CheckForNull
@@ -91,9 +98,16 @@ public interface FileSystem extends BatchComponent {
    * Input files matching the given attributes. Return all the files if the parameter
    * <code>attributes</code> is empty.
    * <p/>
-   * Important - result is an {@link java.lang.Iterable} to benefit from streaming and decreasing
+   * <b>Important</b> - result is an {@link java.lang.Iterable} to benefit from streaming and decreasing
    * memory consumption. It should be iterated only once, else copy it into a list :
    * {@code com.google.common.collect.Lists.newArrayList(inputFiles(predicate))}
+   * <p/>
+   * How to use :
+   * <pre>
+   * FilePredicates p = fs.predicates();
+   * Iterable<InputFile> files = fs.inputFiles(p.and(p.hasLanguage("java"), p.hasType(InputFile.Type.MAIN)));
+   * </pre>
+   *
    * @see #predicates()
    */
   Iterable<InputFile> inputFiles(FilePredicate predicate);