diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2012-03-30 12:04:01 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2012-03-30 15:54:28 +0200 |
commit | bdde621718cf8162909bd39dfc9a328657848be6 (patch) | |
tree | b5c7664c0b5daa7d08c78ff311127971d7e14af8 /sonar-plugin-api | |
parent | af52433faa63a94218b3f45234099e505b981ff8 (diff) | |
download | sonarqube-bdde621718cf8162909bd39dfc9a328657848be6.tar.gz sonarqube-bdde621718cf8162909bd39dfc9a328657848be6.zip |
SONAR-3287 Use new ResourceType props for #isAvailableForFilters
Diffstat (limited to 'sonar-plugin-api')
4 files changed, 52 insertions, 18 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java index a86d0b411ab..9249f275cad 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java @@ -21,16 +21,27 @@ package org.sonar.api.resources; import java.util.Map; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; + import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Maps; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - /** - * Experimental extension to declare types of resources. + * <p>Experimental extension to declare types of resources.</p> + * <p> + * Since 2.15, ResourceType object can declare properties that give information about the capabilities of the + * resource type. Those properties may be used, of instance, to adapt the Web UI according to the type of + * the resource being displayed. + * <br> + * Currently, the following properties can be defined: + * </p> + * <ul> + * <li>"deletable": if set to "true", then this resource can be deleted/purged.</li> + * <li>"availableForFilters": if set to "true", then this resource can be displayed in the filters results</li> + * </ul> * * @since 2.14 */ @@ -41,7 +52,6 @@ public final class ResourceType { public static class Builder { private String qualifier; private String iconPath; - private boolean availableForFilters = false; private boolean hasSourceCode = false; private Map<String, String> properties = Maps.newHashMap(); @@ -57,8 +67,12 @@ public final class ResourceType { return this; } + /** + * @deprecated since 2.15. Use {@link #setProperty(String, String)} with "availableForFilters" set to "true". + */ + @Deprecated public Builder availableForFilters() { - this.availableForFilters = true; + setProperty("availableForFilters", "true"); return this; } @@ -94,13 +108,11 @@ public final class ResourceType { private final String qualifier; private final String iconPath; private final boolean hasSourceCode; - private final boolean availableForFilters; private Map<String, String> properties; private ResourceType(Builder builder) { this.qualifier = builder.qualifier; this.iconPath = builder.iconPath; - this.availableForFilters = builder.availableForFilters; this.hasSourceCode = builder.hasSourceCode; this.properties = Maps.newHashMap(builder.properties); } @@ -116,8 +128,13 @@ public final class ResourceType { return iconPath; } + /** + * @deprecated since 2.15. Use {@link #getBooleanProperty(String)} with "availableForFilters". + */ + @Deprecated public boolean isAvailableForFilters() { - return availableForFilters; + Boolean availableForFilters = getBooleanProperty("availableForFilters"); + return availableForFilters == null ? false : availableForFilters.booleanValue(); } public boolean hasSourceCode() { 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 4ae3c823bb9..6fbcc46f299 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 @@ -43,7 +43,7 @@ public final class ResourceTypes implements BatchComponent, ServerComponent { public static final Predicate<ResourceType> AVAILABLE_FOR_FILTERS = new Predicate<ResourceType>() { public boolean apply(ResourceType input) { - return input.isAvailableForFilters(); + return Boolean.TRUE.equals(input.getBooleanProperty("availableForFilters")); } }; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java index c8bcfecc335..b7a040852a3 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java @@ -19,11 +19,11 @@ */ package org.sonar.api.resources; -import org.junit.Test; - import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; +import org.junit.Test; + public class ResourceTypeTest { @Test @@ -39,13 +39,15 @@ public class ResourceTypeTest { public void shouldCreate() { ResourceType def = ResourceType.builder("qualifier") .setIconPath("/custom-icon.png") - .availableForFilters() .hasSourceCode() + .setProperty("availableForFilters", "true") + .setProperty("anotherProperty", "foo") .build(); assertThat(def.getQualifier(), is("qualifier")); assertThat(def.getIconPath(), is("/custom-icon.png")); - assertThat(def.isAvailableForFilters(), is(true)); assertThat(def.hasSourceCode(), is(true)); + assertThat(def.getBooleanProperty("availableForFilters"), is(true)); + assertThat(def.getStringProperty("anotherProperty"), is("foo")); } @Test(expected = IllegalArgumentException.class) @@ -66,4 +68,19 @@ public class ResourceTypeTest { assertThat(foo1.hashCode(), is(foo1.hashCode())); } + @Test + public void testDeprecatedIsAvailableForFiltesCompatibility() { + // test getter + ResourceType def = ResourceType.builder("qualifier") + .setProperty("availableForFilters", "true") + .build(); + assertThat(def.isAvailableForFilters(), is(true)); + + // test setter on Builder + def = ResourceType.builder("qualifier") + .availableForFilters() + .build(); + assertThat(def.getBooleanProperty("availableForFilters"), is(true)); + } + } 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 4da61fa537e..6c34aa65a38 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 @@ -34,21 +34,21 @@ import static org.junit.internal.matchers.IsCollectionContaining.hasItems; public class ResourceTypesTest { private ResourceTypeTree viewsTree = ResourceTypeTree.builder() - .addType(ResourceType.builder(Qualifiers.VIEW).availableForFilters().build()) + .addType(ResourceType.builder(Qualifiers.VIEW).setProperty("availableForFilters", "true").build()) .addType(ResourceType.builder(Qualifiers.SUBVIEW).build()) .addRelations(Qualifiers.VIEW, Qualifiers.SUBVIEW) .addRelations(Qualifiers.SUBVIEW, Qualifiers.PROJECT) .build(); private ResourceTypeTree defaultTree = ResourceTypeTree.builder() - .addType(ResourceType.builder(Qualifiers.PROJECT).availableForFilters().build()) + .addType(ResourceType.builder(Qualifiers.PROJECT).setProperty("availableForFilters", "true").build()) .addType(ResourceType.builder(Qualifiers.DIRECTORY).build()) .addType(ResourceType.builder(Qualifiers.FILE).build()) .addRelations(Qualifiers.PROJECT, Qualifiers.DIRECTORY) .addRelations(Qualifiers.DIRECTORY, Qualifiers.FILE) .build(); - private ResourceTypes types = new ResourceTypes(new ResourceTypeTree[]{viewsTree, defaultTree}); + private ResourceTypes types = new ResourceTypes(new ResourceTypeTree[] {viewsTree, defaultTree}); @Test public void get() { @@ -116,7 +116,7 @@ public class ResourceTypesTest { .addType(ResourceType.builder("foo").build()) .build(); - new ResourceTypes(new ResourceTypeTree[]{tree1, tree2}); + new ResourceTypes(new ResourceTypeTree[] {tree1, tree2}); } static Collection<String> qualifiers(Collection<ResourceType> types) { |