aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-07-21 17:51:29 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-08-07 11:44:06 +0200
commit460f96aa6333c848b3b733d538b27459fee3999a (patch)
treea9eed04e9681e57e6b00575db3b1e8b54b2b65ae /sonar-plugin-api/src
parentc69324daaf2b08efa2fdc68d01c2fff105b34cdf (diff)
downloadsonarqube-460f96aa6333c848b3b733d538b27459fee3999a.tar.gz
sonarqube-460f96aa6333c848b3b733d538b27459fee3999a.zip
SONAR-9576 Add component status in the scanner report
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicate.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java16
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java11
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/NotPredicate.java9
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OperatorPredicate.java32
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java15
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/StatusPredicate.java37
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java8
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java2
11 files changed, 122 insertions, 19 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicate.java
index dac1bedf984..c841431b43f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicate.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicate.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.batch.fs;
-
/**
* 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}.
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 255d6e2a8c8..0c8b576bc0c 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,4 +154,6 @@ public interface FilePredicates {
FilePredicate and(FilePredicate first, FilePredicate second);
+ FilePredicate hasStatus(InputFile.Status status);
+
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java
index 863864c185c..48cb675c8b9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java
@@ -19,19 +19,20 @@
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.FilePredicate;
-import org.sonar.api.batch.fs.FileSystem.Index;
-import org.sonar.api.batch.fs.InputFile;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.FileSystem.Index;
+import org.sonar.api.batch.fs.InputFile;
+
+import static java.util.stream.Collectors.toList;
/**
* @since 4.2
*/
-class AndPredicate extends AbstractFilePredicate {
+class AndPredicate extends AbstractFilePredicate implements OperatorPredicate {
private final List<OptimizedFilePredicate> predicates = new ArrayList<>();
@@ -94,4 +95,9 @@ class AndPredicate extends AbstractFilePredicate {
return predicates;
}
+ @Override
+ public List<FilePredicate> operands() {
+ return predicates.stream().map(p -> (FilePredicate) p).collect(toList());
+ }
+
}
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 3e06099e4e4..83c4dd41aab 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
@@ -29,6 +29,7 @@ import java.util.List;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputFile.Status;
/**
* Factory of {@link org.sonar.api.batch.fs.FilePredicate}
@@ -42,7 +43,7 @@ public class DefaultFilePredicates implements FilePredicates {
/**
* Client code should use {@link org.sonar.api.batch.fs.FileSystem#predicates()} to get an instance
*/
- DefaultFilePredicates(Path baseDir) {
+ public DefaultFilePredicates(Path baseDir) {
this.baseDir = baseDir;
}
@@ -199,4 +200,9 @@ public class DefaultFilePredicates implements FilePredicates {
public FilePredicate and(FilePredicate first, FilePredicate second) {
return AndPredicate.create(Arrays.asList(first, second));
}
+
+ @Override
+ public FilePredicate hasStatus(Status status) {
+ return new StatusPredicate(status);
+ }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
index e5246813378..0794bd9bddb 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
@@ -31,6 +31,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@@ -53,7 +54,7 @@ public class DefaultFileSystem implements FileSystem {
private Path workDir;
private Charset encoding;
protected final FilePredicates predicates;
- private Predicate<InputFile> defaultPredicate;
+ private Function<FilePredicate, Predicate<InputFile>> defaultPredicateFactory;
/**
* Only for testing
@@ -99,8 +100,8 @@ public class DefaultFileSystem implements FileSystem {
return this;
}
- public DefaultFileSystem setDefaultPredicate(@Nullable Predicate<InputFile> predicate) {
- this.defaultPredicate = predicate;
+ public DefaultFileSystem setDefaultPredicate(@Nullable Function<FilePredicate, Predicate<InputFile>> defaultPredicateFactory) {
+ this.defaultPredicateFactory = defaultPredicateFactory;
return this;
}
@@ -146,9 +147,9 @@ public class DefaultFileSystem implements FileSystem {
@Override
public Iterable<InputFile> inputFiles(FilePredicate predicate) {
Iterable<InputFile> iterable = OptimizedFilePredicateAdapter.create(predicate).get(cache);
- if (defaultPredicate != null) {
+ if (defaultPredicateFactory != null) {
return StreamSupport.stream(iterable.spliterator(), false)
- .filter(defaultPredicate::test).collect(Collectors.toList());
+ .filter(defaultPredicateFactory.apply(predicate)).collect(Collectors.toList());
}
return iterable;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/NotPredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/NotPredicate.java
index 9fda653d7ac..fb90e16c580 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/NotPredicate.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/NotPredicate.java
@@ -19,13 +19,15 @@
*/
package org.sonar.api.batch.fs.internal;
+import java.util.Arrays;
+import java.util.List;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.InputFile;
/**
* @since 4.2
*/
-class NotPredicate extends AbstractFilePredicate {
+class NotPredicate extends AbstractFilePredicate implements OperatorPredicate {
private final FilePredicate predicate;
@@ -38,4 +40,9 @@ class NotPredicate extends AbstractFilePredicate {
return !predicate.apply(f);
}
+ @Override
+ public List<FilePredicate> operands() {
+ return Arrays.asList(predicate);
+ }
+
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OperatorPredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OperatorPredicate.java
new file mode 100644
index 00000000000..e42e296b675
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OperatorPredicate.java
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 java.util.List;
+import org.sonar.api.batch.fs.FilePredicate;
+
+/**
+ * A predicate that associate other predicates
+ */
+public interface OperatorPredicate extends FilePredicate {
+
+ List<FilePredicate> operands();
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java
index b711b7c87ef..0f70fb7545a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java
@@ -19,18 +19,18 @@
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.batch.fs.FilePredicate;
-import org.sonar.api.batch.fs.InputFile;
-
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.InputFile;
/**
* @since 4.2
*/
-class OrPredicate extends AbstractFilePredicate {
+class OrPredicate extends AbstractFilePredicate implements OperatorPredicate {
- private final Collection<FilePredicate> predicates = new ArrayList<>();
+ private final List<FilePredicate> predicates = new ArrayList<>();
private OrPredicate() {
}
@@ -68,4 +68,9 @@ class OrPredicate extends AbstractFilePredicate {
return predicates;
}
+ @Override
+ public List<FilePredicate> operands() {
+ return predicates;
+ }
+
}
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
new file mode 100644
index 00000000000..342748d2a4f
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/StatusPredicate.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.InputFile;
+
+public class StatusPredicate extends AbstractFilePredicate {
+
+ private final InputFile.Status status;
+
+ StatusPredicate(InputFile.Status status) {
+ this.status = status;
+ }
+
+ @Override
+ public boolean apply(InputFile f) {
+ return 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 8efcbe6d3cd..fb543499dd7 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
@@ -32,6 +32,7 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputFile.Status;
import static org.assertj.core.api.Assertions.assertThat;
@@ -56,6 +57,7 @@ public class DefaultFilePredicatesTest {
javaFile = new TestInputFileBuilder("foo", "src/main/java/struts/Action.java")
.setModuleBaseDir(moduleBasePath)
.setLanguage("java")
+ .setStatus(Status.SAME)
.build();
}
@@ -173,6 +175,12 @@ public class DefaultFilePredicatesTest {
}
@Test
+ public void has_status() {
+ assertThat(predicates.hasStatus(InputFile.Status.SAME).apply(javaFile)).isTrue();
+ assertThat(predicates.hasStatus(InputFile.Status.ADDED).apply(javaFile)).isFalse();
+ }
+
+ @Test
public void not() {
assertThat(predicates.not(predicates.hasType(InputFile.Type.MAIN)).apply(javaFile)).isFalse();
assertThat(predicates.not(predicates.hasType(InputFile.Type.TEST)).apply(javaFile)).isTrue();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
index 60908c48166..55d2d4b53de 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
@@ -120,7 +120,7 @@ public class DefaultFileSystemTest {
fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
fs.add(new TestInputFileBuilder("foo", "src/Baz.java").setLanguage("java").build());
- fs.setDefaultPredicate(f -> f.relativePath().endsWith("Foo.php"));
+ fs.setDefaultPredicate(p -> f -> f.relativePath().endsWith("Foo.php"));
Iterator<File> iterator = fs.files(fs.predicates().all()).iterator();
assertThat(iterator.hasNext()).isTrue();
assertThat(iterator.next()).isEqualTo(file1.file());