From 097437f96c9d57375e7537da53a5a95bc096655a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 25 Apr 2014 20:42:57 +0200 Subject: Complete WebService with new param metadata --- .../java/org/sonar/api/server/ws/WebService.java | 65 ++++++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) (limited to 'sonar-plugin-api/src/main/java') 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 a4725146bdd..0dbcfd0aa5c 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 @@ -35,10 +35,10 @@ import java.util.Map; /** * Defines a web service. Note that contrary to the deprecated {@link org.sonar.api.web.Webservice} * the ws is fully implemented in Java and does not require any Ruby on Rails code. - * + *

*

* The classes implementing this extension point must be declared in {@link org.sonar.api.SonarPlugin#getExtensions()}. - * + *

*

How to use

*
  * public class HelloWs implements WebService {
@@ -370,7 +370,9 @@ public interface WebService extends ServerExtension {
   }
 
   class NewParam {
-    private String key, description;
+    private String key, description, exampleValue;
+    private boolean required = false;
+    private String[] possibleValues = null;
 
     private NewParam(String key) {
       this.key = key;
@@ -381,6 +383,33 @@ public interface WebService extends ServerExtension {
       return this;
     }
 
+    /**
+     * Is the parameter required or optional ? Default value is false (optional).
+     * @since 4.4
+     */
+    public NewParam setRequired(boolean b) {
+      this.required = b;
+      return this;
+    }
+
+    /**
+     * @since 4.4
+     */
+    public NewParam setExampleValue(@Nullable String s) {
+      this.exampleValue = s;
+      return this;
+    }
+
+    /**
+     * Exhaustive list of possible values when it makes sense, for example
+     * list of severities.
+     * @since 4.4
+     */
+    public NewParam setPossibleValues(@Nullable String... s) {
+      this.possibleValues = s;
+      return this;
+    }
+
     @Override
     public String toString() {
       return key;
@@ -389,11 +418,16 @@ public interface WebService extends ServerExtension {
 
   @Immutable
   class Param {
-    private final String key, description;
+    private final String key, description, exampleValue;
+    private final boolean required;
+    private final String[] possibleValues;
 
     public Param(NewParam newParam) {
       this.key = newParam.key;
       this.description = newParam.description;
+      this.exampleValue = newParam.exampleValue;
+      this.required = newParam.required;
+      this.possibleValues = (newParam.possibleValues == null ? new String[0] : newParam.possibleValues);
     }
 
     public String key() {
@@ -405,6 +439,29 @@ public interface WebService extends ServerExtension {
       return description;
     }
 
+    /**
+     * @since 4.4
+     */
+    @CheckForNull
+    public String exampleValue() {
+      return exampleValue;
+    }
+
+    /**
+     * Is the parameter required or optional ?
+     * @since 4.4
+     */
+    public boolean isRequired() {
+      return required;
+    }
+
+    /**
+     * @since 4.4
+     */
+    public String[] possibleValues() {
+      return possibleValues;
+    }
+
     @Override
     public String toString() {
       return key;
-- 
cgit v1.2.3