aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java/org/sonar
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-01-29 10:56:35 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-01-29 15:52:27 +0100
commit9a37480a156494a1486b6fa13b7f0d6c6f71fa19 (patch)
tree9c24d25ab6ffcb3a9fa6f9ebca4eca0eb5c1f2e9 /sonar-ws-client/src/main/java/org/sonar
parentff7d411f8307aca5c62e8422edece454e40c02fb (diff)
downloadsonarqube-9a37480a156494a1486b6fa13b7f0d6c6f71fa19.tar.gz
sonarqube-9a37480a156494a1486b6fa13b7f0d6c6f71fa19.zip
SONAR-4326 Add WS client to manage tags on rules (add/remove)
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java9
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleClient.java37
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleClient.java64
3 files changed, 110 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java
index 038c061d714..99341392df5 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java
@@ -28,7 +28,9 @@ import org.sonar.wsclient.permissions.PermissionClient;
import org.sonar.wsclient.permissions.internal.DefaultPermissionClient;
import org.sonar.wsclient.project.ProjectClient;
import org.sonar.wsclient.project.internal.DefaultProjectClient;
+import org.sonar.wsclient.rule.RuleClient;
import org.sonar.wsclient.rule.RuleTagClient;
+import org.sonar.wsclient.rule.internal.DefaultRuleClient;
import org.sonar.wsclient.rule.internal.DefaultRuleTagClient;
import org.sonar.wsclient.system.SystemClient;
import org.sonar.wsclient.system.internal.DefaultSystemClient;
@@ -112,6 +114,13 @@ public class SonarClient {
return new DefaultRuleTagClient(requestFactory);
}
+ /**
+ * New client to interact with web services related to rules
+ */
+ public RuleClient ruleClient() {
+ return new DefaultRuleClient(requestFactory);
+ }
+
public SystemClient systemClient() {
return new DefaultSystemClient(requestFactory);
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleClient.java
new file mode 100644
index 00000000000..9d5f82c5a9d
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleClient.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.wsclient.rule;
+
+/**
+ * Allows management of rules
+ * @since 4.2
+ */
+public interface RuleClient {
+
+ /**
+ * Associate new tags to a rule
+ */
+ void addTags(String key, String... tags);
+
+ /**
+ * Remove tags from a rule
+ */
+ void removeTags(String key, String... tags);
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleClient.java
new file mode 100644
index 00000000000..04d0525010f
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleClient.java
@@ -0,0 +1,64 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.wsclient.rule.internal;
+
+import org.sonar.wsclient.internal.HttpRequestFactory;
+import org.sonar.wsclient.rule.RuleClient;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Do not instantiate this class, but use {@link org.sonar.wsclient.SonarClient#ruleClient()}.
+ */
+public class DefaultRuleClient implements RuleClient {
+
+ private static final String ROOT_URL = "/api/rules";
+ private static final String ADD_TAGS_URL = ROOT_URL + "/add_tags";
+ private static final String REMOVE_TAGS_URL = ROOT_URL + "/remove_tags";
+
+ private final HttpRequestFactory requestFactory;
+
+ public DefaultRuleClient(HttpRequestFactory requestFactory) {
+ this.requestFactory = requestFactory;
+ }
+
+ @Override
+ public void addTags(String key, String... tags) {
+ requestFactory.post(ADD_TAGS_URL, buildQueryParams(key, tags));
+ }
+
+ @Override
+ public void removeTags(String key, String... tags) {
+ requestFactory.post(REMOVE_TAGS_URL, buildQueryParams(key, tags));
+ }
+
+ private Map<String, Object> buildQueryParams(String key, String... tags) {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("key", key);
+ StringBuilder tagsBuilder = new StringBuilder();
+ for (int i=0; i < tags.length - 1; i++) {
+ tagsBuilder.append(tags[i]).append(",");
+ }
+ tagsBuilder.append(tags[tags.length - 1]);
+ params.put("tags", tagsBuilder.toString());
+ return params;
+ }
+}