]> source.dussan.org Git - sonarqube.git/commitdiff
Clean-up unused code of ResourceTypes
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 9 Jan 2018 10:11:50 +0000 (11:11 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 9 Jan 2018 13:25:49 +0000 (14:25 +0100)
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.

server/sonar-db-dao/src/test/java/org/sonar/db/component/ResourceTypesRule.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java
sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypesTest.java

index 3d97f07dc0dd69e00c3218e96d07693aa97a2e44..0e90f2424219e8e25be1ce9a7163098c7847f6f1 100644 (file)
@@ -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) {
@@ -91,43 +85,8 @@ public class ResourceTypesRule extends ResourceTypes {
       .findAny().orElse(null);
   }
 
-  @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();
-  }
 }
index 1091a14e5724f7a6d10ba61bfa808eba1450c744..713908c8f66893cf137c23260ef5d3b5ea9ca418 100644 (file)
@@ -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));
index 0d02785606eb215fc8cac0728c1e75440a4f2c31..8284ccf397946f0447b925ceb1a4e2bbf5d72632 100644 (file)
@@ -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();
index 7073db99af66dd9d434312bc9e3c3711172f99ee..a0fa602aeda5a7e79c7d3cfce2f6ffbadbb25cef 100644 (file)
@@ -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();
-  }
-
 }
index 470ad544c43ad830166a57236799aa63b891097d..8eb691a3111439d5ba2970cb9b8e5be8a3bc4698 100644 (file)
@@ -62,48 +62,11 @@ public class ResourceTypesTest {
     assertThat(qualifiers(types.getAll())).containsExactly(Qualifiers.PROJECT, Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.VIEW, Qualifiers.SUBVIEW, Qualifiers.APP);
   }
 
-  @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);
@@ -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()