diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-01-09 11:11:50 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2018-01-09 14:25:49 +0100 |
commit | b2f15b50c6cf123765ca6c56c9bf5bffc451b771 (patch) | |
tree | 4b81c809a049a87a306dada296485726878581e4 | |
parent | 7af0b945e6772b8e10ee8c7548b78ee12ea88712 (diff) | |
download | sonarqube-b2f15b50c6cf123765ca6c56c9bf5bffc451b771.tar.gz sonarqube-b2f15b50c6cf123765ca6c56c9bf5bffc451b771.zip |
Clean-up unused code of ResourceTypes
This class should be dropped as no plugins provide new types anymore.
That was used only by the developer cockpit plugin, which is end
of life.
5 files changed, 17 insertions, 191 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ResourceTypesRule.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ResourceTypesRule.java index 3d97f07dc0d..0e90f242421 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ResourceTypesRule.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ResourceTypesRule.java @@ -36,16 +36,15 @@ import static java.util.Collections.emptySet; public class ResourceTypesRule extends ResourceTypes { private Set<ResourceType> allResourceTypes = emptySet(); private Set<ResourceType> rootResourceTypes = emptySet(); - private List<String> childrenQualifiers = emptyList(); private List<String> leavesQualifiers = emptyList(); - @Override - public Collection<ResourceType> getAll() { - return allResourceTypes; + public ResourceTypesRule() { + super(new ResourceTypeTree[0]); } + @Override - public Collection<ResourceType> getAllOrdered() { + public Collection<ResourceType> getAll() { return allResourceTypes; } @@ -69,11 +68,6 @@ public class ResourceTypesRule extends ResourceTypes { return this; } - public ResourceTypesRule setChildrenQualifiers(String... qualifiers) { - childrenQualifiers = ImmutableList.copyOf(qualifiers); - return this; - } - public ResourceTypesRule setAllQualifiers(String... qualifiers) { Set<ResourceType> resourceTypes = new HashSet<>(); for (String qualifier : qualifiers) { @@ -92,42 +86,7 @@ public class ResourceTypesRule extends ResourceTypes { } @Override - public Collection<ResourceType> getAllWithPropertyKey(String propertyKey) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection<ResourceType> getAllWithPropertyValue(String propertyKey, String propertyValue) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection<ResourceType> getAllWithPropertyValue(String propertyKey, boolean propertyValue) { - throw new UnsupportedOperationException(); - } - - @Override - public List<String> getChildrenQualifiers(String qualifier) { - return this.childrenQualifiers; - } - - @Override - public List<ResourceType> getChildren(String qualifier) { - throw new UnsupportedOperationException(); - } - - @Override public List<String> getLeavesQualifiers(String qualifier) { return this.leavesQualifiers; } - - @Override - public ResourceTypeTree getTree(String qualifier) { - throw new UnsupportedOperationException(); - } - - @Override - public ResourceType getRoot(String qualifier) { - throw new UnsupportedOperationException(); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index 1091a14e572..713908c8f66 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -58,9 +58,7 @@ import org.sonarqube.ws.Components.TreeWsResponse; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; -import static org.sonar.api.resources.Qualifiers.DIRECTORY; import static org.sonar.api.resources.Qualifiers.FILE; -import static org.sonar.api.resources.Qualifiers.MODULE; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE; import static org.sonar.db.component.ComponentTesting.newChildComponent; @@ -86,7 +84,6 @@ public class TreeActionTest { private ResourceTypesRule resourceTypes = new ResourceTypesRule() .setRootQualifiers(PROJECT) - .setChildrenQualifiers(MODULE, FILE, DIRECTORY) .setLeavesQualifiers(FILE, UNIT_TEST_FILE); private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); @@ -94,7 +91,7 @@ public class TreeActionTest { private WsActionTester ws = new WsActionTester(new TreeAction(dbClient, new ComponentFinder(dbClient, resourceTypes), resourceTypes, userSession, Mockito.mock(I18n.class))); @Test - public void verify_definition() throws Exception { + public void verify_definition() { WebService.Action action = ws.getDef(); assertThat(action.since()).isEqualTo("5.4"); @@ -141,7 +138,7 @@ public class TreeActionTest { } @Test - public void return_children() throws IOException { + public void return_children() { ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid"); componentDb.insertProjectAndSnapshot(project); ComponentDto module = newModuleDto("module-uuid-1", project); @@ -171,7 +168,7 @@ public class TreeActionTest { } @Test - public void return_descendants() throws IOException { + public void return_descendants() { ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); ComponentDto module = newModuleDto("module-uuid-1", project); @@ -201,7 +198,7 @@ public class TreeActionTest { } @Test - public void filter_descendants_by_qualifier() throws IOException { + public void filter_descendants_by_qualifier() { ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid"); componentDb.insertProjectAndSnapshot(project); componentDb.insertComponent(newFileDto(project, 1)); @@ -219,7 +216,7 @@ public class TreeActionTest { } @Test - public void return_leaves() throws IOException { + public void return_leaves() { ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"); componentDb.insertProjectAndSnapshot(project); ComponentDto module = newModuleDto("module-uuid-1", project); @@ -243,7 +240,7 @@ public class TreeActionTest { } @Test - public void sort_descendants_by_qualifier() throws IOException { + public void sort_descendants_by_qualifier() { ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid"); componentDb.insertProjectAndSnapshot(project); componentDb.insertComponent(newFileDto(project, 1)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 0d02785606e..8284ccf3979 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -63,7 +63,6 @@ import static org.sonar.api.measures.Metric.ValueType.INT; import static org.sonar.api.measures.Metric.ValueType.RATING; import static org.sonar.api.resources.Qualifiers.DIRECTORY; import static org.sonar.api.resources.Qualifiers.FILE; -import static org.sonar.api.resources.Qualifiers.MODULE; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE; import static org.sonar.api.server.ws.WebService.Param.SORT; @@ -73,12 +72,6 @@ import static org.sonar.db.component.ComponentTesting.newDirectory; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newProjectCopy; import static org.sonar.db.component.SnapshotTesting.newAnalysis; -import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY; -import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_PERIOD_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.WITH_MEASURES_ONLY_METRIC_SORT_FILTER; -import static org.sonar.test.JsonAssert.assertJson; import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIODS; import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; @@ -91,6 +84,12 @@ import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SO import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_QUALIFIERS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_STRATEGY; +import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY; +import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_PERIOD_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.WITH_MEASURES_ONLY_METRIC_SORT_FILTER; +import static org.sonar.test.JsonAssert.assertJson; public class ComponentTreeActionTest { @Rule @@ -103,7 +102,6 @@ public class ComponentTreeActionTest { private I18nRule i18n = new I18nRule(); private ResourceTypesRule resourceTypes = new ResourceTypesRule() .setRootQualifiers(PROJECT) - .setChildrenQualifiers(MODULE, FILE, DIRECTORY) .setLeavesQualifiers(FILE, UNIT_TEST_FILE); private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); 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() |