aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-07-06 14:54:55 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-07-06 14:57:14 +0200
commit7f74b18354bc2c92f32b79a18baff4fb518f3e90 (patch)
treebcbf48baca9a04bda258bba8b84052922f98b169 /sonar-plugin-api
parent4843622503247b75f04cd061a7825350d0ffe99b (diff)
downloadsonarqube-7f74b18354bc2c92f32b79a18baff4fb518f3e90.tar.gz
sonarqube-7f74b18354bc2c92f32b79a18baff4fb518f3e90.zip
API: add ResourceType#setProperty(String,boolean) + remove some deprecated methods
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java54
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTest.java79
2 files changed, 74 insertions, 59 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 368e9f0e249..e5444ca5452 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
@@ -19,29 +19,28 @@
*/
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;
+import java.util.Map;
+
/**
* <p>Experimental extension to declare types of resources.</p>
* <p>
* Since 3.0, 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
+ * 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>
- * <li>"modifiable_history": if set to "true", then the history of this resource may be modified (deletion of snapshots, modification of events, ...)</li>
+ * <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>
+ * <li>"modifiable_history": if set to "true", then the history of this resource may be modified (deletion of snapshots, modification of events, ...)</li>
* </ul>
*
* @since 2.14
@@ -61,6 +60,7 @@ public final class ResourceType {
/**
* Creates a new {@link Builder}
+ *
* @param qualifier
*/
public Builder(String qualifier) {
@@ -69,7 +69,7 @@ public final class ResourceType {
/**
* Relative path of the icon used to represent the resource type.
- *
+ *
* @param iconPath path to icon, relative to context of web-application (e.g. "/images/q/DIR.png")
*/
public Builder setIconPath(@Nullable String iconPath) {
@@ -96,7 +96,7 @@ public final class ResourceType {
/**
* Sets a property on the resource type. See the description of {@link ResourceType} class for more information.
- *
+ *
* @since 3.0
*/
public Builder setProperty(String key, String value) {
@@ -107,6 +107,13 @@ public final class ResourceType {
}
/**
+ * @since 3.2
+ */
+ public Builder setProperty(String key, boolean value) {
+ return setProperty(key, String.valueOf(value));
+ }
+
+ /**
* Creates an instance of {@link ResourceType} based on all information given to the builder.
*/
public ResourceType build() {
@@ -119,6 +126,7 @@ public final class ResourceType {
/**
* Creates a new {@link Builder}
+ *
* @param qualifier
*/
public static Builder builder(String qualifier) {
@@ -141,7 +149,7 @@ public final class ResourceType {
/**
* Qualifier is the unique key.
- *
+ *
* @return the qualifier
*/
public String getQualifier() {
@@ -150,7 +158,7 @@ public final class ResourceType {
/**
* Returns the relative path of the icon used to represent the resource type
- *
+ *
* @return the relative path.
*/
public String getIconPath() {
@@ -158,17 +166,8 @@ public final class ResourceType {
}
/**
- * @deprecated since 3.0. Use {@link #getBooleanProperty(String)} with "availableForFilters".
- */
- @Deprecated
- public boolean isAvailableForFilters() {
- Boolean availableForFilters = getBooleanProperty("availableForFilters");
- return availableForFilters == null ? false : availableForFilters.booleanValue();
- }
-
- /**
* Tells whether resources of this type has source code or not.
- *
+ *
* @return true if the type has source code
*/
public boolean hasSourceCode() {
@@ -177,7 +176,7 @@ public final class ResourceType {
/**
* Returns the value of the property for this resource type.
- *
+ *
* @return the String value of the property, or NULL if the property hasn't been set.
* @since 3.0
*/
@@ -188,13 +187,14 @@ public final class ResourceType {
/**
* Returns the value of the property for this resource type.
- *
+ *
* @return the Boolean value of the property. If the property hasn't been set, False is returned.
* @since 3.0
*/
- public Boolean getBooleanProperty(String key) {
+ public boolean getBooleanProperty(String key) {
Preconditions.checkNotNull(key);
- return Boolean.valueOf(properties.get(key));
+ String value = properties.get(key);
+ return value != null && Boolean.parseBoolean(value);
}
@Override
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 b7a040852a3..998017b75f8 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,35 +19,35 @@
*/
package org.sonar.api.resources;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
import org.junit.Test;
+import static org.fest.assertions.Assertions.assertThat;
+
+
public class ResourceTypeTest {
@Test
public void shouldCreateWithDefaults() {
ResourceType def = ResourceType.builder("qualifier")
- .build();
- assertThat(def.getQualifier(), is("qualifier"));
- assertThat(def.getIconPath(), is("/images/q/qualifier.png"));
- assertThat(def.hasSourceCode(), is(false));
+ .build();
+ assertThat(def.getQualifier()).isEqualTo("qualifier");
+ assertThat(def.getIconPath()).isEqualTo("/images/q/qualifier.png");
+ assertThat(def.hasSourceCode()).isFalse();
}
@Test
public void shouldCreate() {
ResourceType def = ResourceType.builder("qualifier")
- .setIconPath("/custom-icon.png")
- .hasSourceCode()
- .setProperty("availableForFilters", "true")
- .setProperty("anotherProperty", "foo")
- .build();
- assertThat(def.getQualifier(), is("qualifier"));
- assertThat(def.getIconPath(), is("/custom-icon.png"));
- assertThat(def.hasSourceCode(), is(true));
- assertThat(def.getBooleanProperty("availableForFilters"), is(true));
- assertThat(def.getStringProperty("anotherProperty"), is("foo"));
+ .setIconPath("/custom-icon.png")
+ .hasSourceCode()
+ .setProperty("availableForFilters", "true")
+ .setProperty("anotherProperty", "foo")
+ .build();
+ assertThat(def.getQualifier()).isEqualTo("qualifier");
+ assertThat(def.getIconPath()).isEqualTo("/custom-icon.png");
+ assertThat(def.hasSourceCode()).isTrue();
+ assertThat(def.getBooleanProperty("availableForFilters")).isTrue();
+ assertThat(def.getStringProperty("anotherProperty")).isEqualTo("foo");
}
@Test(expected = IllegalArgumentException.class)
@@ -61,26 +61,41 @@ public class ResourceTypeTest {
ResourceType foo2 = ResourceType.builder("FOO").build();
ResourceType bar = ResourceType.builder("BAR").build();
- assertThat(foo1.equals(foo1), is(true));
- assertThat(foo1.equals(foo2), is(true));
- assertThat(foo1.equals(bar), is(false));
+ assertThat(foo1.equals(foo1)).isTrue();
+ assertThat(foo1.equals(foo2)).isTrue();
+ assertThat(foo1.equals(bar)).isFalse();
- assertThat(foo1.hashCode(), is(foo1.hashCode()));
+ assertThat(foo1.hashCode()).isEqualTo(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));
+ ResourceType def = ResourceType.builder("qualifier").build();
+ assertThat(def.getBooleanProperty("availableForFilters")).isFalse();
+
+ def = ResourceType.builder("qualifier").availableForFilters().build();
+ assertThat(def.getBooleanProperty("availableForFilters")).isTrue();
}
+ @Test
+ public void getBooleanProperty_is_set() {
+ // set with boolean parameter
+ ResourceType def = ResourceType.builder("qualifier").setProperty("availableForFilters", true).build();
+ assertThat(def.getBooleanProperty("availableForFilters")).isTrue();
+
+ def = ResourceType.builder("qualifier").setProperty("availableForFilters", false).build();
+ assertThat(def.getBooleanProperty("availableForFilters")).isFalse();
+
+ def = ResourceType.builder("qualifier").setProperty("availableForFilters", "true").build();
+ assertThat(def.getBooleanProperty("availableForFilters")).isTrue();
+
+ def = ResourceType.builder("qualifier").setProperty("availableForFilters", "false").build();
+ assertThat(def.getBooleanProperty("availableForFilters")).isFalse();
+ }
+
+ @Test
+ public void getBooleanProperty_is_not_set() {
+ ResourceType def = ResourceType.builder("qualifier").build();
+ assertThat(def.getBooleanProperty("availableForFilters")).isFalse();
+ }
}