diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-04 15:33:05 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-07 11:44:06 +0200 |
commit | a0f2105b46566f5bea0da5915e923fc20fd31eda (patch) | |
tree | 3fab12c4f0babf2dda61f2c3c65348dcbf6fbf97 /sonar-plugin-api/src | |
parent | c9212b7924101f9c4c54bf12efb46df5724d77eb (diff) | |
download | sonarqube-a0f2105b46566f5bea0da5915e923fc20fd31eda.tar.gz sonarqube-a0f2105b46566f5bea0da5915e923fc20fd31eda.zip |
SONAR-9576 More simple predicate to skip default status filter
Diffstat (limited to 'sonar-plugin-api/src')
4 files changed, 19 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java index 0c8b576bc0c..c4e1c2e4ebd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java @@ -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(); + } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java index 83c4dd41aab..16c6cc11c6a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java @@ -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); + } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/StatusPredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/StatusPredicate.java index 342748d2a4f..033df2f1f04 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/StatusPredicate.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/StatusPredicate.java @@ -19,19 +19,20 @@ */ 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(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java index fb543499dd7..de95977978a 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java @@ -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(); } |