]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6068 Do not break FilePredicate interface as it is used by SonarGraph plugin
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 11 Feb 2015 09:52:43 +0000 (10:52 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 11 Feb 2015 09:53:55 +0000 (10:53 +0100)
18 files changed:
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicates.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/AbstractFilePredicate.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbsolutePathPredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractFilePredicate.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FalsePredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/LanguagePredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/NotPredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OptimizedFilePredicate.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OptimizedFilePredicateAdapter.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/PathPatternPredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/RelativePathPredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/StatusPredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TruePredicate.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TypePredicate.java

index 83fbd7454264d2c7c1e3029a9dac9377bd0f6fbc..cb4d4461d11c9a420625a752f31a66b49e5af2d8 100644 (file)
@@ -19,7 +19,8 @@
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
+import org.sonar.api.batch.fs.internal.AbstractFilePredicate;
+
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
 
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/AbstractFilePredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/AbstractFilePredicate.java
deleted file mode 100644 (file)
index ff112cf..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.api.batch.fs;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import org.sonar.api.batch.fs.FileSystem.Index;
-
-/**
- * Partial implementation of {@link FilePredicate}.
- * @since 5.1
- */
-public abstract class AbstractFilePredicate implements FilePredicate {
-
-  protected static final int DEFAULT_PRIORITY = 10;
-  protected static final int USE_INDEX = 20;
-
-  @Override
-  public Iterable<InputFile> filter(Iterable<InputFile> target) {
-    return Iterables.filter(target, new Predicate<InputFile>() {
-      @Override
-      public boolean apply(InputFile input) {
-        return AbstractFilePredicate.this.apply(input);
-      }
-    });
-  }
-
-  @Override
-  public Iterable<InputFile> get(Index index) {
-    return filter(index.inputFiles());
-  }
-
-  @Override
-  public int priority() {
-    return DEFAULT_PRIORITY;
-  }
-
-  @Override
-  public int compareTo(FilePredicate o) {
-    return o.priority() - priority();
-  }
-
-}
index 57be61fe3b7919f3ade768952ff899a6e43ce902..1174c4cc0f78127377cf2b14a58adbf8f3155f73 100644 (file)
  */
 package org.sonar.api.batch.fs;
 
-import org.sonar.api.batch.fs.internal.RelativePathPredicate;
 
 /**
  * Determines if a file must be kept in search results. See {@link org.sonar.api.batch.fs.FileSystem}
  * and {@link org.sonar.api.batch.fs.FilePredicates}.
  * @since 4.2
  */
-public interface FilePredicate extends Comparable<FilePredicate> {
+public interface FilePredicate {
   /**
    * Test if provided file is valid for this predicate
    */
   boolean apply(InputFile inputFile);
 
-  /**
-   * Filter provided files to keep only the ones that are valid for this predicate
-   */
-  Iterable<InputFile> filter(Iterable<InputFile> inputFiles);
-
-  /**
-   * Get all files that are valid for this predicate.
-   */
-  Iterable<InputFile> get(FileSystem.Index index);
-
-  /**
-   * For optimization. FilePredicates will be applied in priority order. For example when doing
-   * p.and(p1, p2, p3) then p1, p2 and p3 will be applied according to their priority value. Higher priority value
-   * are applied first.
-   * Assign a high priority when the predicate will likely highly reduce the set of InputFiles to filter. Also
-   * {@link RelativePathPredicate} and AbsolutePathPredicate have a high priority since they are using cache index.
-   */
-  int priority();
 }
index 218d00e891ddf855292a5b6477e08b017b926a16..ab18e3c76ee084608971d10f23e7168487a0ec8a 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
 import org.sonar.api.batch.fs.FileSystem.Index;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.scan.filesystem.PathResolver;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractFilePredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractFilePredicate.java
new file mode 100644 (file)
index 0000000..ba0560b
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.FileSystem.Index;
+import org.sonar.api.batch.fs.InputFile;
+
+/**
+ * Partial implementation of {@link FilePredicate}.
+ * @since 5.1
+ */
+public abstract class AbstractFilePredicate implements OptimizedFilePredicate {
+
+  protected static final int DEFAULT_PRIORITY = 10;
+  protected static final int USE_INDEX = 20;
+
+  @Override
+  public Iterable<InputFile> filter(Iterable<InputFile> target) {
+    return Iterables.filter(target, new Predicate<InputFile>() {
+      @Override
+      public boolean apply(InputFile input) {
+        return AbstractFilePredicate.this.apply(input);
+      }
+    });
+  }
+
+  @Override
+  public Iterable<InputFile> get(Index index) {
+    return filter(index.inputFiles());
+  }
+
+  @Override
+  public int priority() {
+    return DEFAULT_PRIORITY;
+  }
+
+  @Override
+  public final int compareTo(OptimizedFilePredicate o) {
+    return o.priority() - priority();
+  }
+
+}
index 29485c7d470b0e8101643c0a273b8d70afa27337..b833d3405ebb6e1b928027303fbb23b4d1dec5c9 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.api.batch.fs.internal;
 
 import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
 import org.sonar.api.batch.fs.FilePredicate;
 import org.sonar.api.batch.fs.FileSystem.Index;
 import org.sonar.api.batch.fs.InputFile;
@@ -35,7 +34,7 @@ import java.util.List;
  */
 class AndPredicate extends AbstractFilePredicate {
 
-  private final List<FilePredicate> predicates = new ArrayList<>();
+  private final List<OptimizedFilePredicate> predicates = new ArrayList<>();
 
   private AndPredicate() {
   }
@@ -53,7 +52,7 @@ class AndPredicate extends AbstractFilePredicate {
       } else if (filePredicate instanceof AndPredicate) {
         result.predicates.addAll(((AndPredicate) filePredicate).predicates);
       } else {
-        result.predicates.add(filePredicate);
+        result.predicates.add(OptimizedFilePredicateAdapter.create(filePredicate));
       }
     }
     Collections.sort(result.predicates);
@@ -62,7 +61,7 @@ class AndPredicate extends AbstractFilePredicate {
 
   @Override
   public boolean apply(InputFile f) {
-    for (FilePredicate predicate : predicates) {
+    for (OptimizedFilePredicate predicate : predicates) {
       if (!predicate.apply(f)) {
         return false;
       }
@@ -73,7 +72,7 @@ class AndPredicate extends AbstractFilePredicate {
   @Override
   public Iterable<InputFile> filter(Iterable<InputFile> target) {
     Iterable<InputFile> result = target;
-    for (FilePredicate predicate : predicates) {
+    for (OptimizedFilePredicate predicate : predicates) {
       result = predicate.filter(result);
     }
     return result;
@@ -93,7 +92,7 @@ class AndPredicate extends AbstractFilePredicate {
   }
 
   @VisibleForTesting
-  Collection<FilePredicate> predicates() {
+  Collection<OptimizedFilePredicate> predicates() {
     return predicates;
   }
 
index 898fdad5f0f7bef3b666ee2d1b00c80cd38f26cc..e727b3b578f2e6f54da7d4ca360ca7c5914157ae 100644 (file)
@@ -133,13 +133,12 @@ public class DefaultFileSystem implements FileSystem {
   @Override
   public Iterable<InputFile> inputFiles(FilePredicate predicate) {
     doPreloadFiles();
-    return predicate.get(cache);
+    return OptimizedFilePredicateAdapter.create(predicate).get(cache);
   }
 
   @Override
   public boolean hasFiles(FilePredicate predicate) {
-    doPreloadFiles();
-    return predicate.get(cache).iterator().hasNext();
+    return inputFiles(predicate).iterator().hasNext();
   }
 
   @Override
index fb59c5e37cc26b912fe347e06a743d60226265d5..bab5060a9b8b696209c2becca15bae32fe7672c6 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
 import org.sonar.api.batch.fs.FilePredicate;
 import org.sonar.api.batch.fs.FileSystem.Index;
 import org.sonar.api.batch.fs.InputFile;
index 47be5cb98ccdfeff2c48cea75a61f726ff1db1a0..0418629235b2db25a8978622c1828e8f14f3359a 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
 import org.sonar.api.batch.fs.InputFile;
 
 /**
index eae74b1b63120833c617a417f70ec2a61d5f2013..15b6aa3238fcf04b38a4c208c0f815efea2eb0c3 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
 import org.sonar.api.batch.fs.FilePredicate;
 import org.sonar.api.batch.fs.InputFile;
 
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OptimizedFilePredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OptimizedFilePredicate.java
new file mode 100644 (file)
index 0000000..99ba698
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.fs.InputFile;
+
+/**
+ * Optimized version of FilePredicate allowing to speed up query by looking at InputFile by index.
+ */
+public interface OptimizedFilePredicate extends FilePredicate, Comparable<OptimizedFilePredicate> {
+
+  /**
+   * Filter provided files to keep only the ones that are valid for this predicate
+   */
+  Iterable<InputFile> filter(Iterable<InputFile> inputFiles);
+
+  /**
+   * Get all files that are valid for this predicate.
+   */
+  Iterable<InputFile> get(FileSystem.Index index);
+
+  /**
+   * For optimization. FilePredicates will be applied in priority order. For example when doing
+   * p.and(p1, p2, p3) then p1, p2 and p3 will be applied according to their priority value. Higher priority value
+   * are applied first.
+   * Assign a high priority when the predicate will likely highly reduce the set of InputFiles to filter. Also
+   * {@link RelativePathPredicate} and AbsolutePathPredicate have a high priority since they are using cache index.
+   */
+  int priority();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OptimizedFilePredicateAdapter.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OptimizedFilePredicateAdapter.java
new file mode 100644 (file)
index 0000000..81eec77
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.InputFile;
+
+class OptimizedFilePredicateAdapter extends AbstractFilePredicate {
+
+  private FilePredicate unoptimizedPredicate;
+
+  private OptimizedFilePredicateAdapter(FilePredicate unoptimizedPredicate) {
+    this.unoptimizedPredicate = unoptimizedPredicate;
+  }
+
+  @Override
+  public boolean apply(InputFile inputFile) {
+    return unoptimizedPredicate.apply(inputFile);
+  }
+
+  public static OptimizedFilePredicate create(FilePredicate predicate) {
+    if (predicate instanceof OptimizedFilePredicate) {
+      return (OptimizedFilePredicate) predicate;
+    } else {
+      return new OptimizedFilePredicateAdapter(predicate);
+    }
+  }
+
+}
index 627623956a47b95e95899164858bfc7574dc4a74..7ff190d72e8188a74bba6d9ec50112f5f5cf236d 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.api.batch.fs.internal;
 
 import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.batch.fs.AbstractFilePredicate;
 import org.sonar.api.batch.fs.FilePredicate;
 import org.sonar.api.batch.fs.InputFile;
 
index fa4d21d7c6dac581b7dd1d84ac6e14db3b3e1713..9ccf48bffa52660a959b7886aed7d20af48fff85 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
 import org.sonar.api.batch.fs.InputFile;
 
 /**
index 887f254754bb729df73b4471ce5fdce7880b2fd9..66c25246111d20269686b57d1f8556b191dab8e8 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
 import org.sonar.api.batch.fs.FileSystem.Index;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.utils.PathUtils;
index a31032b23d3035e9d15cd13307a3dfd446901365..449df0418d6f3bc619c2764a0e8c0237e1888ee8 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
 import org.sonar.api.batch.fs.InputFile;
 
 /**
index 55ab8620c45e9289d586fe9b1b0e5c6024304aad..6457aee090ff29e5d3c8e31c57fddb166802f6aa 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
 import org.sonar.api.batch.fs.FilePredicate;
 import org.sonar.api.batch.fs.FileSystem.Index;
 import org.sonar.api.batch.fs.InputFile;
index c619c29e293832a6f80c05c3c2ec39b8b7f471fc..e5e266d7d233235dfaa195d2054c759fa724e0cf 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.api.batch.fs.internal;
 
-import org.sonar.api.batch.fs.AbstractFilePredicate;
-
 import org.sonar.api.batch.fs.InputFile;
 
 /**