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();
+
}
public FilePredicate hasStatus(Status status) {
return new StatusPredicate(status);
}
+
+ @Override
+ public FilePredicate hasAnyStatus() {
+ return new StatusPredicate(null);
+ }
}
*/
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();
}
}
@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();
}
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();
}
}