aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java/org/sonar
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-25 15:51:44 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-25 16:03:35 +0200
commit25a221af79dabe8cdff5dc07080f69eb1c580c0e (patch)
tree248bbcf9bd6ba9ea96b08c7ef785a42a62f9957d /sonar-ws-client/src/main/java/org/sonar
parentc26e5ebef93099f1d845404d85e0bee7061e23a5 (diff)
downloadsonarqube-25a221af79dabe8cdff5dc07080f69eb1c580c0e.tar.gz
sonarqube-25a221af79dabe8cdff5dc07080f69eb1c580c0e.zip
SONAR-4764 Add Java WS Client to restore default profiles
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java15
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/QProfileClient.java31
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/QProfileResult.java30
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/internal/DefaultQProfileClient.java46
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/internal/DefaultQProfileResult.java61
5 files changed, 180 insertions, 3 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 03e1c2fca23..7e06483dcd5 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
@@ -19,9 +19,6 @@
*/
package org.sonar.wsclient;
-import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
-
-import org.sonar.wsclient.qualitygate.QualityGateClient;
import org.sonar.wsclient.internal.HttpRequestFactory;
import org.sonar.wsclient.issue.ActionPlanClient;
import org.sonar.wsclient.issue.IssueClient;
@@ -31,6 +28,10 @@ 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.qprofile.QProfileClient;
+import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
+import org.sonar.wsclient.qualitygate.QualityGateClient;
+import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
import org.sonar.wsclient.rule.RuleClient;
import org.sonar.wsclient.rule.RuleTagClient;
import org.sonar.wsclient.rule.internal.DefaultRuleClient;
@@ -131,6 +132,14 @@ public class SonarClient {
return new DefaultQualityGateClient(requestFactory);
}
+ /**
+ * New client to interact with web services related to quality profilesgates
+ */
+ public QProfileClient qProfileClient() {
+ return new DefaultQProfileClient(requestFactory);
+ }
+
+
public SystemClient systemClient() {
return new DefaultSystemClient(requestFactory);
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/QProfileClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/QProfileClient.java
new file mode 100644
index 00000000000..e26cd1449d7
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/QProfileClient.java
@@ -0,0 +1,31 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.qprofile;
+
+
+/**
+ * @since 4.4
+ */
+public interface QProfileClient {
+
+ QProfileResult restoreDefault(String language);
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/QProfileResult.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/QProfileResult.java
new file mode 100644
index 00000000000..9734e4ce16c
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/QProfileResult.java
@@ -0,0 +1,30 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.qprofile;
+
+import java.util.List;
+
+public interface QProfileResult {
+
+ List<String> infos();
+
+ List<String> warnings();
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/internal/DefaultQProfileClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/internal/DefaultQProfileClient.java
new file mode 100644
index 00000000000..f0ce08cd502
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/internal/DefaultQProfileClient.java
@@ -0,0 +1,46 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.qprofile.internal;
+
+import org.json.simple.JSONValue;
+import org.sonar.wsclient.internal.HttpRequestFactory;
+import org.sonar.wsclient.qprofile.QProfileClient;
+import org.sonar.wsclient.qprofile.QProfileResult;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class DefaultQProfileClient implements QProfileClient {
+
+ private final HttpRequestFactory requestFactory;
+
+ public DefaultQProfileClient(HttpRequestFactory requestFactory) {
+ this.requestFactory = requestFactory;
+ }
+
+ @Override
+ public QProfileResult restoreDefault(String language) {
+ String json = requestFactory.post("/api/qprofiles/restore_default", Collections.singletonMap("language", (Object) language));
+ Map jsonRoot = (Map) JSONValue.parse(json);
+ return new DefaultQProfileResult(jsonRoot);
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/internal/DefaultQProfileResult.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/internal/DefaultQProfileResult.java
new file mode 100644
index 00000000000..ca9e6237e06
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qprofile/internal/DefaultQProfileResult.java
@@ -0,0 +1,61 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.qprofile.internal;
+
+import org.sonar.wsclient.qprofile.QProfileResult;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class DefaultQProfileResult implements QProfileResult {
+
+ private Map json;
+
+ DefaultQProfileResult(Map json) {
+ this.json = json;
+ }
+
+ @Override
+ public List<String> infos() {
+ List<String> infos = new ArrayList<String>();
+ List<String> jsonInfos = (List<String>) json.get("infos");
+ if (jsonInfos != null) {
+ for (String info : jsonInfos) {
+ infos.add(info);
+ }
+ }
+ return infos;
+ }
+
+ @Override
+ public List<String> warnings() {
+ List<String> warnings = new ArrayList<String>();
+ List<String> jsonWarnings = (List<String>) json.get("warnings");
+ if (jsonWarnings != null) {
+ for (String warning : jsonWarnings) {
+ warnings.add(warning);
+ }
+ }
+ return warnings;
+ }
+
+}