aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-09-22 16:57:21 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-09-22 18:22:45 +0200
commit205b4e422fa3ad3f6b65d4e07b0fe0757b88a874 (patch)
treef7f7f046037cf9bd43ee203e749a11216678ef88 /sonar-plugin-api
parent4e9392499d71805b80b126343e504fc6aa40dc33 (diff)
downloadsonarqube-205b4e422fa3ad3f6b65d4e07b0fe0757b88a874.tar.gz
sonarqube-205b4e422fa3ad3f6b65d4e07b0fe0757b88a874.zip
Add possibility to set a deprecated key on a param
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java48
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java12
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java8
4 files changed, 57 insertions, 13 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 d656213f30e..d08e0fdc923 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
@@ -32,13 +32,10 @@ import org.sonar.api.ServerExtension;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
+
import java.io.IOException;
import java.net.URL;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* Defines a web service. Note that contrary to the deprecated {@link org.sonar.api.web.Webservice}
@@ -251,7 +248,7 @@ public interface WebService extends ServerExtension {
class NewAction {
private final String key;
- private String description, since;
+ private String deprecatedKey, description, since;
private boolean post = false, isInternal = false;
private RequestHandler handler;
private Map<String, NewParam> newParams = Maps.newHashMap();
@@ -261,6 +258,11 @@ public interface WebService extends ServerExtension {
this.key = key;
}
+ public NewAction setDeprecatedKey(@Nullable String s) {
+ this.deprecatedKey = s;
+ return this;
+ }
+
public NewAction setDescription(@Nullable String s) {
this.description = s;
return this;
@@ -324,7 +326,7 @@ public interface WebService extends ServerExtension {
@Immutable
class Action {
- private final String key, path, description, since;
+ private final String key, deprecatedKey, path, description, since;
private final boolean post, isInternal;
private final RequestHandler handler;
private final Map<String, Param> params;
@@ -332,6 +334,7 @@ public interface WebService extends ServerExtension {
private Action(Controller controller, NewAction newAction) {
this.key = newAction.key;
+ this.deprecatedKey = newAction.deprecatedKey;
this.path = String.format("%s/%s", controller.path(), key);
this.description = newAction.description;
this.since = StringUtils.defaultIfBlank(newAction.since, controller.since);
@@ -344,17 +347,21 @@ public interface WebService extends ServerExtension {
}
this.handler = newAction.handler;
- ImmutableMap.Builder<String, Param> mapBuilder = ImmutableMap.builder();
+ ImmutableMap.Builder<String, Param> paramsBuilder = ImmutableMap.builder();
for (NewParam newParam : newAction.newParams.values()) {
- mapBuilder.put(newParam.key, new Param(newParam));
+ paramsBuilder.put(newParam.key, new Param(newParam));
}
- this.params = mapBuilder.build();
+ this.params = paramsBuilder.build();
}
public String key() {
return key;
}
+ public String deprecatedKey() {
+ return deprecatedKey;
+ }
+
public String path() {
return path;
}
@@ -434,7 +441,7 @@ public interface WebService extends ServerExtension {
}
class NewParam {
- private String key, description, exampleValue, defaultValue;
+ private String key, deprecatedKey, description, exampleValue, defaultValue;
private boolean required = false;
private Set<String> possibleValues = null;
@@ -442,6 +449,14 @@ public interface WebService extends ServerExtension {
this.key = key;
}
+ /**
+ * @since 5.0
+ */
+ public NewParam setDeprecatedKey(@Nullable String s) {
+ this.deprecatedKey = s;
+ return this;
+ }
+
public NewParam setDescription(@Nullable String s) {
this.description = s;
return this;
@@ -516,12 +531,13 @@ public interface WebService extends ServerExtension {
@Immutable
class Param {
- private final String key, description, exampleValue, defaultValue;
+ private final String key, deprecatedKey, description, exampleValue, defaultValue;
private final boolean required;
private final Set<String> possibleValues;
public Param(NewParam newParam) {
this.key = newParam.key;
+ this.deprecatedKey = newParam.deprecatedKey;
this.description = newParam.description;
this.exampleValue = newParam.exampleValue;
this.defaultValue = newParam.defaultValue;
@@ -533,6 +549,14 @@ public interface WebService extends ServerExtension {
return key;
}
+ /**
+ * @since 5.0
+ */
+ @CheckForNull
+ public String deprecatedKey() {
+ return deprecatedKey;
+ }
+
@CheckForNull
public String description() {
return description;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java
index 002612f03c5..26567597a97 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java
@@ -28,6 +28,7 @@ import org.sonar.api.server.ws.WebService;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.util.List;
import java.util.Set;
@@ -61,6 +62,14 @@ public abstract class ValidatingRequest extends Request {
return value;
}
+// @CheckForNull
+// private WebService.Param getDefinition(String key){
+// WebService.Param definition = action.param(key);
+// if (definition == null) {
+// return action.
+// }
+// }
+
@CheckForNull
@Override
public List<String> paramAsStrings(String key) {
@@ -100,7 +109,8 @@ public abstract class ValidatingRequest extends Request {
LoggerFactory.getLogger(getClass()).error(message);
throw new IllegalArgumentException(message);
}
- String value = StringUtils.defaultString(readParam(key), definition.defaultValue());
+ String value = StringUtils.defaultString(readParam(definition.deprecatedKey()), readParam(key));
+ value = StringUtils.defaultString(value, definition.defaultValue());
if (value == null) {
return null;
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
index fe240c6ce89..4ee5587d843 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
@@ -46,6 +46,7 @@ public class DefaultIssueTest {
.setComponentId(1L)
.setProjectKey("Sample")
.setRuleKey(RuleKey.of("squid", "S100"))
+ .setLanguage("xoo")
.setSeverity("MINOR")
.setManualSeverity(true)
.setMessage("a message")
@@ -75,6 +76,7 @@ public class DefaultIssueTest {
assertThat(issue.componentId()).isEqualTo(1L);
assertThat(issue.projectKey()).isEqualTo("Sample");
assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("squid", "S100"));
+ assertThat(issue.language()).isEqualTo("xoo");
assertThat(issue.severity()).isEqualTo("MINOR");
assertThat(issue.manualSeverity()).isTrue();
assertThat(issue.message()).isEqualTo("a message");
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 2c57236b86c..752b0f819ea 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
@@ -88,6 +88,9 @@ public class RequestTest {
action.createParam("has_possible_values").setPossibleValues("foo", "bar");
+ action.createParam("new_param").setDeprecatedKey("deprecated_param");
+ action.createParam("new_param_with_default_value").setDeprecatedKey("deprecated_new_param_with_default_value").setDefaultValue("the_default_string");
+
controller.done();
}
}
@@ -210,6 +213,11 @@ public class RequestTest {
}
@Test
+ public void deprecated_key() throws Exception {
+ assertThat(request.setParam("deprecated_param", "bar").param("new_param")).isEqualTo("bar");
+ }
+
+ @Test
public void fail_if_param_is_not_defined() throws Exception {
try {
request.param("unknown");