@ExtensionPoint
public final class PropertyDefinition {
- private static final Set<String> SUPPORTED_QUALIFIERS = unmodifiableSet(new LinkedHashSet<>(asList(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.MODULE, Qualifiers.SUBVIEW)));
+ private static final Set<String> SUPPORTED_QUALIFIERS = unmodifiableSet(new LinkedHashSet<>(
+ asList(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.MODULE, Qualifiers.SUBVIEW, Qualifiers.APP)));
private String key;
private String defaultValue;
* See supported constant values in {@link Qualifiers}. By default property is available
* only in General Settings.
*
- * @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE},
+ * @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE}, {@link Qualifiers#APP APP},
* {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
*/
public Builder onQualifiers(String first, String... rest) {
* See supported constant values in {@link Qualifiers}. By default property is available
* only in General Settings.
*
+ * @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE}, {@link Qualifiers#APP APP},
+ * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
* @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE},
* {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
*/
* See supported constant values in {@link Qualifiers}. By default property is available
* only in General Settings.
*
- * @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE},
+ * @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE}, {@link Qualifiers#APP APP},
* {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
*/
public Builder onlyOnQualifiers(String first, String... rest) {
* See supported constant values in {@link Qualifiers}. By default property is available
* only in General Settings.
*
- * @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE},
+ * @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE}, {@link Qualifiers#APP APP},
* {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
*/
public Builder onlyOnQualifiers(List<String> qualifiers) {
*/
package org.sonar.api.resources;
-import org.apache.commons.lang.StringUtils;
+import java.util.Objects;
/**
* The qualifier determines the exact type of a resource.
* @param resource not nullable
*/
public static boolean isView(final Resource resource, final boolean acceptSubViews) {
- boolean isView = StringUtils.equals(VIEW, resource.getQualifier());
+ boolean isView = Objects.equals(VIEW, resource.getQualifier());
if (!isView && acceptSubViews) {
- isView = StringUtils.equals(SUBVIEW, resource.getQualifier());
+ isView = Objects.equals(SUBVIEW, resource.getQualifier());
}
return isView;
* @param resource not nullable
*/
public static boolean isSubview(final Resource resource) {
- return StringUtils.equals(SUBVIEW, resource.getScope());
+ return Objects.equals(SUBVIEW, resource.getScope());
}
/**
* @param resource not nullable
*/
public static boolean isProject(final Resource resource, final boolean acceptModules) {
- boolean isProject = StringUtils.equals(PROJECT, resource.getQualifier());
+ boolean isProject = Objects.equals(PROJECT, resource.getQualifier());
if (!isProject && acceptModules) {
- isProject = StringUtils.equals(MODULE, resource.getQualifier());
+ isProject = Objects.equals(MODULE, resource.getQualifier());
}
return isProject;
}
* @param resource not nullable
*/
public static boolean isModule(final Resource resource) {
- return StringUtils.equals(MODULE, resource.getQualifier());
+ return Objects.equals(MODULE, resource.getQualifier());
}
/**
* @param resource not nullable
*/
public static boolean isDirectory(final Resource resource) {
- return StringUtils.equals(DIRECTORY, resource.getQualifier());
+ return Objects.equals(DIRECTORY, resource.getQualifier());
}
/**
* @param resource not nullable
*/
public static boolean isFile(final Resource resource) {
- return StringUtils.equals(FILE, resource.getQualifier());
+ return Objects.equals(FILE, resource.getQualifier());
}
}
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;
treeByQualifier = unmodifiableMap(new LinkedHashMap<>(treeMap));
typeByQualifier = unmodifiableMap(new LinkedHashMap<>(typeMap));
rootTypes = unmodifiableList(new ArrayList<>(rootsSet));
+ orderedTypes = unmodifiableSet(orderedTypes(typeMap));
+ }
- 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);
- }
+ 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);
- orderedTypes = unmodifiableSet(new LinkedHashSet<>(mutableOrderedTypes));
+ return Stream.concat(Stream.of(view, subView, application), mutableTypesByQualifier.values().stream())
+ .filter(Objects::nonNull)
+ .collect(Collectors.toCollection(LinkedHashSet::new));
}
public ResourceType get(String qualifier) {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Cannot be hidden and defining qualifiers on which to display");
- PropertyDefinition.builder("foo").name("foo").onQualifiers(Qualifiers.VIEW).hidden().build();
+ PropertyDefinition.builder("foo").name("foo").onQualifiers(Qualifiers.PROJECT).hidden().build();
}
@Test
biConsumer.accept(builder, qualifier);
fail("A IllegalArgumentException should have been thrown for qualifier " + qualifier);
} catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("Qualifier must be one of [TRK, VW, BRC, SVW]");
+ assertThat(e).hasMessage("Qualifier must be one of [TRK, VW, BRC, SVW, APP]");
}
});
}
*/
package org.sonar.api.config;
+import java.util.Arrays;
+import java.util.List;
import org.junit.Test;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.resources.Qualifiers;
-import java.util.Arrays;
-import java.util.List;
-
import static org.assertj.core.api.Assertions.assertThat;
public class PropertyDefinitionsTest {
PropertyDefinition.builder("global3").name("Global3").category("catGlobal2").build(),
PropertyDefinition.builder("project").name("Project").category("catProject").onlyOnQualifiers(Qualifiers.PROJECT).build(),
PropertyDefinition.builder("module").name("Module").category("catModule").onlyOnQualifiers(Qualifiers.MODULE).build(),
- PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build()
+ PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build(),
+ PropertyDefinition.builder("app").name("Application").category("catApp").onlyOnQualifiers(Qualifiers.APP).build()
);
assertThat(def.propertiesByCategory(null).keySet()).contains(new Category("catGlobal1"), new Category("catGlobal2"));
assertThat(def.propertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly(new Category("catProject"));
assertThat(def.propertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly(new Category("catModule"));
assertThat(def.propertiesByCategory(Qualifiers.VIEW).keySet()).containsOnly(new Category("catView"));
+ assertThat(def.propertiesByCategory(Qualifiers.APP).keySet()).containsOnly(new Category("catApp"));
assertThat(def.propertiesByCategory("Unkown").keySet()).isEmpty();
}
assertThat(Qualifiers.isProject(root, false)).isFalse();
}
+ @Test
+ public void application() {
+ View root = View.createRootApp();
+ assertThat(Qualifiers.isView(root, true)).isFalse();
+ assertThat(Qualifiers.isView(root, false)).isFalse();
+ assertThat(Qualifiers.isProject(root, true)).isFalse();
+ assertThat(Qualifiers.isProject(root, false)).isFalse();
+ }
+
@Test
public void testSubView() {
View subview = View.createSubView();
return new View(Qualifiers.VIEW);
}
+ static View createRootApp() {
+ return new View(Qualifiers.APP);
+ }
+
static View createSubView() {
return new View(Qualifiers.SUBVIEW);
}
*/
package org.sonar.api.resources;
-import com.google.common.base.Function;
import com.google.common.collect.Collections2;
-import org.junit.Test;
-
import java.util.Collection;
+import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
.addRelations(Qualifiers.SUBVIEW, Qualifiers.PROJECT)
.build();
+ private ResourceTypeTree applicationTree = ResourceTypeTree.builder()
+ .addType(ResourceType.builder(Qualifiers.APP).setProperty("supportsMeasureFilters", "true").build())
+ .addRelations(Qualifiers.APP, Qualifiers.PROJECT)
+ .build();
+
private ResourceTypeTree defaultTree = ResourceTypeTree.builder()
.addType(ResourceType.builder(Qualifiers.PROJECT).setProperty("supportsMeasureFilters", "true").build())
.addType(ResourceType.builder(Qualifiers.DIRECTORY).build())
.addRelations(Qualifiers.DIRECTORY, Qualifiers.FILE)
.build();
- private ResourceTypes types = new ResourceTypes(new ResourceTypeTree[] {defaultTree, viewsTree});
+ private ResourceTypes types = new ResourceTypes(new ResourceTypeTree[] {defaultTree, viewsTree, applicationTree});
@Test
public void get() {
@Test
public void get_all() {
- assertThat(qualifiers(types.getAll())).containsExactly(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, Qualifiers.APP);
}
@Test
public void get_all_ordered() {
- assertThat(qualifiers(types.getAllOrdered())).containsExactly(Qualifiers.VIEW, Qualifiers.SUBVIEW, Qualifiers.PROJECT, Qualifiers.DIRECTORY, Qualifiers.FILE);
+ 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);
+ 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).doesNotHaveDuplicates();
+ 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.VIEW, Qualifiers.PROJECT);
+ 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.VIEW, Qualifiers.PROJECT);
- assertThat(qualifiers(types.getAllWithPropertyValue("supportsMeasureFilters", true))).containsOnly(Qualifiers.VIEW, Qualifiers.PROJECT);
+ 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_leaves_qualifiers() {
assertThat(types.getLeavesQualifiers(Qualifiers.PROJECT)).containsExactly(Qualifiers.FILE);
-
assertThat(types.getLeavesQualifiers(Qualifiers.DIRECTORY)).containsExactly(Qualifiers.FILE);
-
assertThat(types.getLeavesQualifiers(Qualifiers.VIEW)).containsExactly(Qualifiers.PROJECT);
-
+ assertThat(types.getLeavesQualifiers(Qualifiers.APP)).containsExactly(Qualifiers.PROJECT);
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();
}
}
static Collection<String> qualifiers(Collection<ResourceType> types) {
- return Collections2.transform(types, new Function<ResourceType, String>() {
- public String apply(ResourceType type) {
- return type.getQualifier();
- }
- });
+ return Collections2.transform(types, ResourceType::getQualifier);
}
}