summaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java20
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java8
3 files changed, 24 insertions, 6 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java
index 0344d8b91d3..86f2e56f406 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java
@@ -60,7 +60,7 @@ public abstract class Request {
*/
public boolean mandatoryParamAsBoolean(String key) {
String s = mandatoryParam(key);
- return Boolean.parseBoolean(s);
+ return parseBoolean(key, s);
}
/**
@@ -122,8 +122,8 @@ public abstract class Request {
*/
@Deprecated
public boolean paramAsBoolean(String key, boolean defaultValue) {
- String s = param(key);
- return s == null ? defaultValue : Boolean.parseBoolean(s);
+ String value = param(key);
+ return value == null ? defaultValue : parseBoolean(key, value);
}
/**
@@ -149,8 +149,8 @@ public abstract class Request {
@CheckForNull
public Boolean paramAsBoolean(String key) {
- String s = param(key);
- return s == null ? null : Boolean.parseBoolean(s);
+ String value = param(key);
+ return value == null ? null : parseBoolean(key, value);
}
@CheckForNull
@@ -210,4 +210,14 @@ public abstract class Request {
}
return null;
}
+
+ private static boolean parseBoolean(String key, String value) {
+ if ("true".equals(value) || "yes".equals(value)) {
+ return true;
+ }
+ if ("false".equals(value) || "no".equals(value)) {
+ return false;
+ }
+ throw new IllegalArgumentException(String.format("Property %s is not a boolean value: %s", key, value));
+ }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
index d08e0fdc923..5b56ef5fef7 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
@@ -494,7 +494,7 @@ public interface WebService extends ServerExtension {
* @since 4.4
*/
public NewParam setBooleanPossibleValues() {
- return setPossibleValues("true", "false");
+ return setPossibleValues("true", "false", "yes", "no");
}
/**
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
index 752b0f819ea..db4559a14e9 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
@@ -173,7 +173,15 @@ public class RequestTest {
@Test
public void param_as_boolean() throws Exception {
assertThat(request.setParam("a_boolean", "true").paramAsBoolean("a_boolean")).isTrue();
+ assertThat(request.setParam("a_boolean", "yes").paramAsBoolean("a_boolean")).isTrue();
assertThat(request.setParam("a_boolean", "false").paramAsBoolean("a_boolean")).isFalse();
+ assertThat(request.setParam("a_boolean", "no").paramAsBoolean("a_boolean")).isFalse();
+ try {
+ request.setParam("a_boolean", "oui").paramAsBoolean("a_boolean");
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Property a_boolean is not a boolean value: oui");
+ }
}
@Test