diff options
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java | 81 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypesTest.java | 49 |
2 files changed, 1 insertions, 129 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java index 7073db99af6..a0fa602aeda 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java @@ -27,17 +27,11 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; -import static java.util.Collections.unmodifiableSet; import static java.util.Objects.requireNonNull; /** @@ -48,17 +42,10 @@ import static java.util.Objects.requireNonNull; @ComputeEngineSide public class ResourceTypes { - public static final Predicate<ResourceType> AVAILABLE_FOR_FILTERS = input -> input != null && input.getBooleanProperty("supportsMeasureFilters"); - private final Map<String, ResourceTypeTree> treeByQualifier; private final Map<String, ResourceType> typeByQualifier; - private final Collection<ResourceType> orderedTypes; private final Collection<ResourceType> rootTypes; - public ResourceTypes() { - this(new ResourceTypeTree[0]); - } - public ResourceTypes(ResourceTypeTree[] trees) { requireNonNull(trees); @@ -79,18 +66,6 @@ public class ResourceTypes { treeByQualifier = unmodifiableMap(new LinkedHashMap<>(treeMap)); typeByQualifier = unmodifiableMap(new LinkedHashMap<>(typeMap)); rootTypes = unmodifiableList(new ArrayList<>(rootsSet)); - orderedTypes = unmodifiableSet(orderedTypes(typeMap)); - } - - private static Set<ResourceType> orderedTypes(Map<String, ResourceType> typeByQualifier) { - Map<String, ResourceType> mutableTypesByQualifier = new LinkedHashMap<>(typeByQualifier); - ResourceType view = mutableTypesByQualifier.remove(Qualifiers.VIEW); - ResourceType subView = mutableTypesByQualifier.remove(Qualifiers.SUBVIEW); - ResourceType application = mutableTypesByQualifier.remove(Qualifiers.APP); - - return Stream.concat(Stream.of(view, subView, application), mutableTypesByQualifier.values().stream()) - .filter(Objects::nonNull) - .collect(Collectors.toCollection(LinkedHashSet::new)); } public ResourceType get(String qualifier) { @@ -102,59 +77,10 @@ public class ResourceTypes { return typeByQualifier.values(); } - public Collection<ResourceType> getAllOrdered() { - return orderedTypes; - } - public Collection<ResourceType> getRoots() { return rootTypes; } - public Collection<ResourceType> getAll(Predicate<ResourceType> predicate) { - return typeByQualifier.values().stream() - .filter(predicate) - .collect(Collectors.toList()); - } - - public Collection<ResourceType> getAllWithPropertyKey(String propertyKey) { - return typeByQualifier.values() - .stream() - .filter(Objects::nonNull) - .filter(input -> input.hasProperty(propertyKey)) - .collect(Collectors.toList()); - } - - public Collection<ResourceType> getAllWithPropertyValue(String propertyKey, String propertyValue) { - return typeByQualifier.values() - .stream() - .filter(Objects::nonNull) - .filter(input -> Objects.equals(propertyValue, input.getStringProperty(propertyKey))) - .collect(Collectors.toList()); - } - - public Collection<ResourceType> getAllWithPropertyValue(String propertyKey, boolean propertyValue) { - return typeByQualifier.values() - .stream() - .filter(Objects::nonNull) - .filter(input -> input.getBooleanProperty(propertyKey) == propertyValue) - .collect(Collectors.toList()); - } - - public List<String> getChildrenQualifiers(String qualifier) { - ResourceTypeTree tree = getTree(qualifier); - if (tree != null) { - return tree.getChildren(qualifier); - } - return Collections.emptyList(); - } - - public List<ResourceType> getChildren(String qualifier) { - return getChildrenQualifiers(qualifier) - .stream() - .map(typeByQualifier::get) - .collect(Collectors.toList()); - } - public List<String> getLeavesQualifiers(String qualifier) { ResourceTypeTree tree = getTree(qualifier); if (tree != null) { @@ -163,12 +89,7 @@ public class ResourceTypes { return Collections.emptyList(); } - public ResourceTypeTree getTree(String qualifier) { + private ResourceTypeTree getTree(String qualifier) { return treeByQualifier.get(qualifier); } - - public ResourceType getRoot(String qualifier) { - return getTree(qualifier).getRootType(); - } - } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypesTest.java index 470ad544c43..8eb691a3111 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypesTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypesTest.java @@ -63,48 +63,11 @@ public class ResourceTypesTest { } @Test - public void get_all_ordered() { - assertThat(qualifiers(types.getAllOrdered())).containsExactly(Qualifiers.VIEW, Qualifiers.SUBVIEW, Qualifiers.APP, Qualifiers.PROJECT, Qualifiers.DIRECTORY, Qualifiers.FILE); - } - - @Test public void get_roots() { assertThat(qualifiers(types.getRoots())).containsOnly(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.APP); } @Test - public void get_all_predicate() { - Collection<ResourceType> forFilters = types.getAll(ResourceTypes.AVAILABLE_FOR_FILTERS); - assertThat(qualifiers(forFilters)).containsOnly(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.APP).doesNotHaveDuplicates(); - } - - @Test - public void get_all_with_property_key() { - assertThat(qualifiers(types.getAllWithPropertyKey("supportsMeasureFilters"))).containsOnly(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.PROJECT); - } - - @Test - public void get_all_with_property_value() { - assertThat(qualifiers(types.getAllWithPropertyValue("supportsMeasureFilters", "true"))).containsOnly(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.PROJECT); - assertThat(qualifiers(types.getAllWithPropertyValue("supportsMeasureFilters", true))).containsOnly(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.PROJECT); - assertThat(qualifiers(types.getAllWithPropertyValue("supportsMeasureFilters", false))).containsOnly(Qualifiers.SUBVIEW, Qualifiers.DIRECTORY, Qualifiers.FILE); - } - - @Test - public void get_children_qualifiers() { - assertThat(types.getChildrenQualifiers(Qualifiers.PROJECT)).containsExactly(Qualifiers.DIRECTORY); - assertThat(types.getChildrenQualifiers(Qualifiers.SUBVIEW)).containsExactly(Qualifiers.PROJECT); - assertThat(types.getChildrenQualifiers("xxx")).isEmpty(); - assertThat(types.getChildrenQualifiers(Qualifiers.FILE)).isEmpty(); - } - - @Test - public void get_children() { - assertThat(qualifiers(types.getChildren(Qualifiers.PROJECT))).contains(Qualifiers.DIRECTORY); - assertThat(qualifiers(types.getChildren(Qualifiers.SUBVIEW))).contains(Qualifiers.PROJECT); - } - - @Test public void get_leaves_qualifiers() { assertThat(types.getLeavesQualifiers(Qualifiers.PROJECT)).containsExactly(Qualifiers.FILE); assertThat(types.getLeavesQualifiers(Qualifiers.DIRECTORY)).containsExactly(Qualifiers.FILE); @@ -113,18 +76,6 @@ public class ResourceTypesTest { assertThat(types.getLeavesQualifiers("xxx")).isEmpty(); } - @Test - public void get_tree() { - assertThat(qualifiers(types.getTree(Qualifiers.VIEW).getTypes())).containsOnly(Qualifiers.VIEW, Qualifiers.SUBVIEW).doesNotHaveDuplicates(); - assertThat(qualifiers(types.getTree(Qualifiers.APP).getTypes())).containsOnly(Qualifiers.APP).doesNotHaveDuplicates(); - assertThat(types.getTree("xxx")).isNull(); - } - - @Test - public void get_root() { - assertThat(types.getRoot(Qualifiers.FILE).getQualifier()).isEqualTo(Qualifiers.PROJECT); - } - @Test(expected = IllegalStateException.class) public void fail_on_duplicated_qualifier() { ResourceTypeTree tree1 = ResourceTypeTree.builder() |