aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-05 11:17:45 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-05 11:43:32 +0100
commit27858608f46ae9f1cd2c2269151e68f56f882417 (patch)
treeddf5be57dd165922923e890144da0dc9cb4eedab /sonar-plugin-api
parent58709fb2390f83a4b57a2c37a88744a66dcced30 (diff)
downloadsonarqube-27858608f46ae9f1cd2c2269151e68f56f882417.tar.gz
sonarqube-27858608f46ae9f1cd2c2269151e68f56f882417.zip
SONAR-7112 search box with correct component type order5.4-M13
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java34
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypesTest.java9
2 files changed, 37 insertions, 6 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 bc1cbbd4120..02beeab6ede 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,17 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import org.sonar.api.server.ServerSide;
-
-import javax.annotation.Nullable;
-
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nullable;
+import org.sonar.api.server.ServerSide;
/**
* @since 2.14
@@ -55,6 +55,7 @@ public class ResourceTypes {
private final Map<String, ResourceTypeTree> treeByQualifier;
private final Map<String, ResourceType> typeByQualifier;
+ private final Collection<ResourceType> orderedTypes;
private final Collection<ResourceType> rootTypes;
public ResourceTypes() {
@@ -81,6 +82,27 @@ public class ResourceTypes {
treeByQualifier = ImmutableMap.copyOf(treeMap);
typeByQualifier = ImmutableMap.copyOf(typeMap);
rootTypes = ImmutableList.copyOf(rootsSet);
+
+ List<ResourceType> mutableOrderedTypes = new ArrayList<>();
+ ResourceType view = null;
+ ResourceType subView = null;
+ for (ResourceType resourceType : typeByQualifier.values()) {
+ if (Qualifiers.VIEW.equals(resourceType.getQualifier())) {
+ view = resourceType;
+ } else if (Qualifiers.SUBVIEW.equals(resourceType.getQualifier())) {
+ subView = resourceType;
+ } else {
+ mutableOrderedTypes.add(resourceType);
+ }
+ }
+ if (subView != null) {
+ mutableOrderedTypes.add(0, subView);
+ }
+ if (view != null) {
+ mutableOrderedTypes.add(0, view);
+ }
+
+ orderedTypes = ImmutableSet.copyOf(mutableOrderedTypes);
}
public ResourceType get(String qualifier) {
@@ -92,6 +114,10 @@ public class ResourceTypes {
return typeByQualifier.values();
}
+ public Collection<ResourceType> getAllOrdered() {
+ return orderedTypes;
+ }
+
public Collection<ResourceType> getRoots() {
return rootTypes;
}
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 5efd1952a1c..0998acf43f9 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
@@ -44,7 +44,7 @@ public class ResourceTypesTest {
.addRelations(Qualifiers.DIRECTORY, Qualifiers.FILE)
.build();
- private ResourceTypes types = new ResourceTypes(new ResourceTypeTree[] {viewsTree, defaultTree});
+ private ResourceTypes types = new ResourceTypes(new ResourceTypeTree[] {defaultTree, viewsTree});
@Test
public void get() {
@@ -56,7 +56,12 @@ public class ResourceTypesTest {
@Test
public void get_all() {
- assertThat(qualifiers(types.getAll())).containsOnly(Qualifiers.PROJECT, Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.VIEW, Qualifiers.SUBVIEW);
+ assertThat(qualifiers(types.getAll())).containsExactly(Qualifiers.PROJECT, Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.VIEW, Qualifiers.SUBVIEW);
+ }
+
+ @Test
+ public void get_all_ordered() {
+ assertThat(qualifiers(types.getAllOrdered())).containsExactly(Qualifiers.VIEW, Qualifiers.SUBVIEW, Qualifiers.PROJECT, Qualifiers.DIRECTORY, Qualifiers.FILE);
}
@Test