diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-28 17:56:43 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-28 17:57:08 +0200 |
commit | dd38eb3d057eb1eb37a1be1567960906c85f10be (patch) | |
tree | 21c248466ba66fbcc075ad756353c349d2940b27 /sonar-plugin-api/src | |
parent | acf2f9c447cd5931a67f6aa2643dad4d919cc27d (diff) | |
download | sonarqube-dd38eb3d057eb1eb37a1be1567960906c85f10be.tar.gz sonarqube-dd38eb3d057eb1eb37a1be1567960906c85f10be.zip |
SONAR-5111 Add support for default parameters in Java WS, protection against undeclared params
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java | 22 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java | 3 |
2 files changed, 22 insertions, 3 deletions
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 0dbcfd0aa5c..e4aa651dba7 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 @@ -28,6 +28,7 @@ import org.sonar.api.ServerExtension; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; + import java.util.Collection; import java.util.List; import java.util.Map; @@ -370,7 +371,7 @@ public interface WebService extends ServerExtension { } class NewParam { - private String key, description, exampleValue; + private String key, description, exampleValue, defaultValue; private boolean required = false; private String[] possibleValues = null; @@ -410,6 +411,14 @@ public interface WebService extends ServerExtension { return this; } + /** + * @since 4.4 + */ + public NewParam setDefaultValue(@Nullable String s) { + this.defaultValue = s; + return this; + } + @Override public String toString() { return key; @@ -418,7 +427,7 @@ public interface WebService extends ServerExtension { @Immutable class Param { - private final String key, description, exampleValue; + private final String key, description, exampleValue, defaultValue; private final boolean required; private final String[] possibleValues; @@ -426,6 +435,7 @@ public interface WebService extends ServerExtension { this.key = newParam.key; this.description = newParam.description; this.exampleValue = newParam.exampleValue; + this.defaultValue = newParam.defaultValue; this.required = newParam.required; this.possibleValues = (newParam.possibleValues == null ? new String[0] : newParam.possibleValues); } @@ -462,6 +472,14 @@ public interface WebService extends ServerExtension { return possibleValues; } + /** + * @since 4.4 + */ + @CheckForNull + public String defaultValue() { + return defaultValue; + } + @Override public String toString() { return key; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java index 5848ee53066..c089bfbf2e0 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java @@ -248,7 +248,7 @@ public class WebServiceTest { NewController newController = context.createController("api/rule"); NewAction create = newController.createAction("create").setHandler(mock(RequestHandler.class)); create.createParam("key").setDescription("Key of the new rule"); - create.createParam("severity"); + create.createParam("severity").setDefaultValue("MAJOR"); newController.done(); } }.define(context); @@ -262,6 +262,7 @@ public class WebServiceTest { assertThat(action.param("severity").key()).isEqualTo("severity"); assertThat(action.param("severity").description()).isNull(); + assertThat(action.param("severity").defaultValue()).isEqualTo("MAJOR"); } @Test |