]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9576 More simple predicate to skip default status filter
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 4 Aug 2017 13:33:05 +0000 (15:33 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 7 Aug 2017 09:44:06 +0000 (11:44 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/StatusPredicate.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/SameInputFilePredicateTest.java

index 0c8b576bc0c4ccc3a544e89c4241fa29e3905f59..c4e1c2e4ebd594c720ad2c15a80264c4a662d824 100644 (file)
@@ -154,6 +154,16 @@ public interface FilePredicates {
 
   FilePredicate and(FilePredicate first, FilePredicate second);
 
+  /**
+   * Look for InputFile having a specific {@link InputFile#status()}
+   * @since 6.6
+   */
   FilePredicate hasStatus(InputFile.Status status);
 
+  /**
+   * Explicitely look for InputFile having any {@link InputFile#status()}
+   * @since 6.6
+   */
+  FilePredicate hasAnyStatus();
+
 }
index 83c4dd41aabd86548aafa6df6c9266de21d8df87..16c6cc11c6a00c53f7da54c2076d223f37733e30 100644 (file)
@@ -205,4 +205,9 @@ public class DefaultFilePredicates implements FilePredicates {
   public FilePredicate hasStatus(Status status) {
     return new StatusPredicate(status);
   }
+
+  @Override
+  public FilePredicate hasAnyStatus() {
+    return new StatusPredicate(null);
+  }
 }
index 342748d2a4f4ccc09c729371f94410e062fbf985..033df2f1f0451ce5dc63c18a7bc362ce76555293 100644 (file)
  */
 package org.sonar.api.batch.fs.internal;
 
+import javax.annotation.Nullable;
 import org.sonar.api.batch.fs.InputFile;
 
 public class StatusPredicate extends AbstractFilePredicate {
 
   private final InputFile.Status status;
 
-  StatusPredicate(InputFile.Status status) {
+  StatusPredicate(@Nullable InputFile.Status status) {
     this.status = status;
   }
 
   @Override
   public boolean apply(InputFile f) {
-    return status == f.status();
+    return status == null || status == f.status();
   }
 
 }
index fb543499dd7feed81e907849fa238ae39f597898..de95977978a18ee79f3e8ef093f0b242315184a2 100644 (file)
@@ -176,6 +176,7 @@ public class DefaultFilePredicatesTest {
 
   @Test
   public void has_status() {
+    assertThat(predicates.hasAnyStatus().apply(javaFile)).isTrue();
     assertThat(predicates.hasStatus(InputFile.Status.SAME).apply(javaFile)).isTrue();
     assertThat(predicates.hasStatus(InputFile.Status.ADDED).apply(javaFile)).isFalse();
   }
index 049f576d84d541b2012802ec5260078f651466f1..0597befba708db4bfe932ae66da489620aa87cc7 100644 (file)
@@ -46,6 +46,7 @@ public class SameInputFilePredicateTest {
   public void testHasExplicitFilterOnStatus() {
     assertThat(SameInputFilePredicate.hasExplicitFilterOnStatus(predicates.all())).isFalse();
     assertThat(SameInputFilePredicate.hasExplicitFilterOnStatus(predicates.hasStatus(InputFile.Status.ADDED))).isTrue();
+    assertThat(SameInputFilePredicate.hasExplicitFilterOnStatus(predicates.hasAnyStatus())).isTrue();
     assertThat(SameInputFilePredicate.hasExplicitFilterOnStatus(predicates.and(predicates.all(), predicates.hasStatus(InputFile.Status.ADDED)))).isTrue();
   }
 }