aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java/org/sonar/wsclient
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
commitaeadc1f9129274949daaa57738c7c4550bdfbc7b (patch)
tree08dadf5ef7474fc41d1d48f74648f1ba8b55f34d /sonar-ws-client/src/main/java/org/sonar/wsclient
downloadsonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.tar.gz
sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.zip
SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar/wsclient')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/Host.java65
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/JdkUtils.java45
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/Sonar.java90
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/ConnectionException.java37
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/Connector.java51
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/ConnectorFactory.java32
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java180
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java167
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java67
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/CreateQuery.java31
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/DeleteQuery.java29
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Dependency.java159
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java153
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTree.java128
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java88
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Event.java114
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/EventCreateQuery.java49
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/EventQuery.java114
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Favourite.java84
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java39
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java38
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteQuery.java35
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Measure.java190
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Metric.java114
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java57
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Model.java23
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Property.java63
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java57
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Query.java31
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Resource.java210
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceQuery.java250
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java46
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/ServerQuery.java37
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Source.java51
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java105
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyCreateQuery.java75
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java50
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java67
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java110
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java134
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java20
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AbstractUnmarshaller.java58
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshaller.java54
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshaller.java42
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/EventUnmarshaller.java38
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/FavouriteUnmarshaller.java37
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/JsonUtils.java94
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/MetricUnmarshaller.java39
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshaller.java33
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshaller.java90
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java42
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/SourceUnmarshaller.java40
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshaller.java32
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java50
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java49
55 files changed, 4183 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/Host.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/Host.java
new file mode 100644
index 00000000000..b2beaad138b
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/Host.java
@@ -0,0 +1,65 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient;
+
+public class Host {
+
+ private String host;
+ private String username;
+ private String password;
+
+ public Host(String host) {
+ this.host = host;
+ }
+
+ public Host(String host, String username, String password) {
+ this.host = host;
+ this.username = username;
+ this.password = password;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public Host setHost(String host) {
+ this.host = host;
+ return this;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public Host setUsername(String username) {
+ this.username = username;
+ return this;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public Host setPassword(String password) {
+ this.password = password;
+ return this;
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/JdkUtils.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/JdkUtils.java
new file mode 100644
index 00000000000..464fe78cb31
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/JdkUtils.java
@@ -0,0 +1,45 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient;
+
+import org.sonar.wsclient.services.WSUtils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public final class JdkUtils extends WSUtils {
+
+ public String format(Date date, String format) {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(format);
+ return dateFormat.format(date);
+ }
+
+ public String encodeUrl(String url) {
+ try {
+ return URLEncoder.encode(url, "UTF-8");
+
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/Sonar.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/Sonar.java
new file mode 100644
index 00000000000..22acd92d2f4
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/Sonar.java
@@ -0,0 +1,90 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient;
+
+import org.sonar.wsclient.connectors.Connector;
+import org.sonar.wsclient.connectors.ConnectorFactory;
+import org.sonar.wsclient.services.*;
+import org.sonar.wsclient.unmarshallers.Unmarshaller;
+import org.sonar.wsclient.unmarshallers.Unmarshallers;
+
+import java.util.Collections;
+import java.util.List;
+
+public class Sonar {
+
+ static {
+ WSUtils.setInstance(new JdkUtils());
+ }
+
+ private Connector connector;
+
+ public Sonar(Connector connector) {
+ this.connector = connector;
+ }
+
+ public Connector getConnector() {
+ return connector;
+ }
+
+ public <MODEL extends Model> MODEL find(Query<MODEL> query) {
+ String json = connector.execute(query);
+ MODEL result = null;
+ if (json != null) {
+ Unmarshaller<MODEL> unmarshaller = Unmarshallers.forModel(query.getModelClass());
+ result = unmarshaller.toModel(json);
+ }
+ return result;
+ }
+
+ public <MODEL extends Model> List<MODEL> findAll(Query<MODEL> query) {
+ String json = connector.execute(query);
+ List<MODEL> result;
+ if (json == null) {
+ result = Collections.emptyList();
+ } else {
+ Unmarshaller<MODEL> unmarshaller = Unmarshallers.forModel(query.getModelClass());
+ result = unmarshaller.toModels(json);
+ }
+ return result;
+ }
+
+ public <MODEL extends Model> MODEL create(CreateQuery<MODEL> query) {
+ String json = connector.execute(query);
+ MODEL result = null;
+ if (json != null) {
+ Unmarshaller<MODEL> unmarshaller = Unmarshallers.forModel(query.getModelClass());
+ result = unmarshaller.toModel(json);
+ }
+ return result;
+ }
+
+ public void delete(DeleteQuery query) {
+ connector.execute(query);
+ }
+
+ public static Sonar create(String host) {
+ return new Sonar(ConnectorFactory.create(new Host(host)));
+ }
+
+ public static Sonar create(String host, String username, String password) {
+ return new Sonar(ConnectorFactory.create(new Host(host, username, password)));
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/ConnectionException.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/ConnectionException.java
new file mode 100644
index 00000000000..370fe02c533
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/ConnectionException.java
@@ -0,0 +1,37 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.connectors;
+
+public class ConnectionException extends RuntimeException {
+ public ConnectionException() {
+ }
+
+ public ConnectionException(String s) {
+ super(s);
+ }
+
+ public ConnectionException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
+
+ public ConnectionException(Throwable throwable) {
+ super(throwable);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/Connector.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/Connector.java
new file mode 100644
index 00000000000..f6c7f1477b3
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/Connector.java
@@ -0,0 +1,51 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.connectors;
+
+import org.sonar.wsclient.services.CreateQuery;
+import org.sonar.wsclient.services.DeleteQuery;
+import org.sonar.wsclient.services.Query;
+
+/**
+ * @since 2.1
+ */
+public abstract class Connector {
+
+ protected static final int TIMEOUT_MS = 30000;
+
+ /**
+ * @return JSON response or null if 404 NOT FOUND error
+ * @throws ConnectionException if connection error or HTTP status not in (200, 404)
+ */
+ public abstract String execute(Query query);
+
+ /**
+ * @return JSON response or null if 404 NOT FOUND error
+ * @since 2.2
+ */
+ public abstract String execute(CreateQuery query);
+
+ /**
+ * @return JSON response or null if 404 NOT FOUND error
+ * @since 2.2
+ */
+ public abstract String execute(DeleteQuery query);
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/ConnectorFactory.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/ConnectorFactory.java
new file mode 100644
index 00000000000..e47ffa144d4
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/ConnectorFactory.java
@@ -0,0 +1,32 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.connectors;
+
+import org.sonar.wsclient.Host;
+
+public final class ConnectorFactory {
+
+ private ConnectorFactory() {
+ }
+
+ public static Connector create(Host server) {
+ return new HttpClient3Connector(server);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java
new file mode 100644
index 00000000000..da660d1eb27
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java
@@ -0,0 +1,180 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.connectors;
+
+import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+import org.apache.commons.httpclient.util.URIUtil;
+import org.sonar.wsclient.Host;
+import org.sonar.wsclient.services.CreateQuery;
+import org.sonar.wsclient.services.DeleteQuery;
+import org.sonar.wsclient.services.Query;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+/**
+ * @since 2.1
+ */
+public class HttpClient3Connector extends Connector {
+
+ private static final int MAX_TOTAL_CONNECTIONS = 40;
+ private static final int MAX_HOST_CONNECTIONS = 4;
+
+ private final Host server;
+ private HttpClient httpClient;
+
+ public HttpClient3Connector(final Host server) {
+ this.server = server;
+ createClient();
+ }
+
+ public HttpClient3Connector(Host server, HttpClient httpClient) {
+ this.httpClient = httpClient;
+ this.server = server;
+ }
+
+ private void createClient() {
+ final HttpConnectionManagerParams params = new HttpConnectionManagerParams();
+ params.setConnectionTimeout(TIMEOUT_MS);
+ params.setSoTimeout(TIMEOUT_MS);
+ params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
+ params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
+ final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+ connectionManager.setParams(params);
+ this.httpClient = new HttpClient(connectionManager);
+ configureCredentials();
+ }
+
+ private void configureCredentials() {
+ if (server.getUsername() != null) {
+ httpClient.getParams().setAuthenticationPreemptive(true);
+ Credentials defaultcreds = new UsernamePasswordCredentials(server.getUsername(), server.getPassword());
+ httpClient.getState().setCredentials(AuthScope.ANY, defaultcreds);
+ }
+ }
+
+ public String execute(Query query) {
+ return executeRequest(newGetRequest(query));
+ }
+
+ public String execute(CreateQuery query) {
+ return executeRequest(newPostRequest(query));
+ }
+
+ public String execute(DeleteQuery query) {
+ return executeRequest(newDeleteRequest(query));
+ }
+
+ private String executeRequest(HttpMethodBase method) {
+ String json = null;
+ try {
+ httpClient.executeMethod(method);
+ if (method.getStatusCode() == HttpStatus.SC_OK) {
+ json = getResponseBodyAsString(method);
+
+ } else if (method.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
+ throw new ConnectionException("HTTP error: " + method.getStatusCode() + ", msg: " + method.getStatusText() + ", query: " + method);
+ }
+
+ } catch (HttpException e) {
+ throw new ConnectionException("Query: " + method, e);
+
+ } catch (IOException e) {
+ throw new ConnectionException("Query: " + method, e);
+
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
+ }
+ return json;
+ }
+
+ private HttpMethodBase newGetRequest(Query query) {
+ try {
+ String url = server.getHost() + URIUtil.encodeQuery(query.getUrl());
+ HttpMethodBase method = new GetMethod(url);
+ method.setRequestHeader("Accept", "application/json");
+ return method;
+
+ } catch (URIException e) {
+ throw new ConnectionException("Query: " + query, e);
+ }
+ }
+
+ private HttpMethodBase newPostRequest(CreateQuery query) {
+ try {
+ String url = server.getHost() + URIUtil.encodeQuery(query.getUrl());
+ HttpMethodBase method = new PostMethod(url);
+ method.setRequestHeader("Accept", "application/json");
+ return method;
+
+ } catch (URIException e) {
+ throw new ConnectionException("Query: " + query, e);
+ }
+ }
+
+ private HttpMethodBase newDeleteRequest(DeleteQuery query) {
+ try {
+ String url = server.getHost() + URIUtil.encodeQuery(query.getUrl());
+ HttpMethodBase method = new DeleteMethod(url);
+ method.setRequestHeader("Accept", "application/json");
+ return method;
+
+ } catch (URIException e) {
+ throw new ConnectionException("Query: " + query, e);
+ }
+ }
+
+ private String getResponseBodyAsString(HttpMethod method) {
+ BufferedReader reader = null;
+ try {
+ final InputStream inputStream = method.getResponseBodyAsStream();
+ reader = new BufferedReader(new InputStreamReader(inputStream));
+ final StringBuilder sb = new StringBuilder();
+ String line;
+
+ while ((line = reader.readLine()) != null) {
+ sb.append(line).append("\n");
+ }
+ return sb.toString();
+
+ } catch (IOException e) {
+ throw new ConnectionException("Can not read response", e);
+
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+
+ } catch (Exception e) {
+ // TODO
+ }
+ }
+ }
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java
new file mode 100644
index 00000000000..73d1d15630f
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java
@@ -0,0 +1,167 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.connectors;
+
+import org.apache.http.*;
+import org.apache.http.auth.*;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+import org.sonar.wsclient.Host;
+import org.sonar.wsclient.services.CreateQuery;
+import org.sonar.wsclient.services.DeleteQuery;
+import org.sonar.wsclient.services.Query;
+
+import java.io.IOException;
+
+/**
+ * @since 2.1
+ */
+public class HttpClient4Connector extends Connector {
+
+ private Host server;
+
+ public HttpClient4Connector(Host server) {
+ this.server = server;
+ }
+
+ public String execute(Query query) {
+ return executeRequest(newGetMethod(query));
+ }
+
+ public String execute(CreateQuery query) {
+ return executeRequest(newPostMethod(query));
+ }
+
+ public String execute(DeleteQuery query) {
+ return executeRequest(newDeleteMethod(query));
+ }
+
+ private String executeRequest(HttpRequestBase request) {
+ String json = null;
+ DefaultHttpClient client = createClient();
+ try {
+ BasicHttpContext context = createLocalContext(client);
+ HttpResponse response = client.execute(request, context);
+ HttpEntity entity = response.getEntity();
+ if (entity != null) {
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+ json = EntityUtils.toString(entity);
+
+ } else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_FOUND) {
+ throw new ConnectionException("HTTP error: " + response.getStatusLine().getStatusCode() + ", msg: " + response.getStatusLine().getReasonPhrase() + ", query: " + request.toString());
+ }
+ }
+
+ } catch (IOException e) {
+ throw new ConnectionException("Query: " + request.getURI(), e);
+
+ } finally {
+ client.getConnectionManager().shutdown();
+ }
+ return json;
+ }
+
+ private DefaultHttpClient createClient() {
+ DefaultHttpClient client = new DefaultHttpClient();
+ HttpParams params = client.getParams();
+ HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_MS);
+ HttpConnectionParams.setSoTimeout(params, TIMEOUT_MS);
+ if (server.getUsername() != null) {
+ client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(server.getUsername(), server.getPassword()));
+ }
+ return client;
+ }
+
+ private BasicHttpContext createLocalContext(DefaultHttpClient client) {
+ BasicHttpContext localcontext = new BasicHttpContext();
+
+ if (server.getUsername() != null) {
+ // Generate BASIC scheme object and stick it to the local
+ // execution context
+ BasicScheme basicAuth = new BasicScheme();
+ localcontext.setAttribute("preemptive-auth", basicAuth);
+
+ // Add as the first request interceptor
+ client.addRequestInterceptor(new PreemptiveAuth(), 0);
+ }
+ return localcontext;
+ }
+
+ private HttpGet newGetMethod(Query query) {
+ HttpGet get = new HttpGet(server.getHost() + query.getUrl());
+ setJsonHeader(get);
+ return get;
+ }
+
+ private HttpDelete newDeleteMethod(DeleteQuery query) {
+ HttpDelete delete = new HttpDelete(server.getHost() + query.getUrl());
+ setJsonHeader(delete);
+ return delete;
+ }
+
+ private HttpPost newPostMethod(CreateQuery query) {
+ HttpPost post = new HttpPost(server.getHost() + query.getUrl());
+ setJsonHeader(post);
+ return post;
+ }
+
+ private void setJsonHeader(HttpRequestBase request) {
+ request.setHeader("Accept", "application/json");
+ }
+
+ static final class PreemptiveAuth implements HttpRequestInterceptor {
+ public void process(
+ final HttpRequest request,
+ final HttpContext context) throws HttpException {
+
+ AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
+
+ // If no auth scheme avaialble yet, try to initialize it preemptively
+ if (authState.getAuthScheme() == null) {
+ AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
+ CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
+ HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
+ if (authScheme != null) {
+ Credentials creds = credsProvider.getCredentials(
+ new AuthScope(
+ targetHost.getHostName(),
+ targetHost.getPort()));
+ if (creds == null) {
+ throw new HttpException("No credentials for preemptive authentication");
+ }
+ authState.setAuthScheme(authScheme);
+ authState.setCredentials(creds);
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java
new file mode 100644
index 00000000000..f2133b5fe02
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java
@@ -0,0 +1,67 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.Date;
+
+/**
+ * @since 2.2
+ */
+public abstract class AbstractQuery<MODEL extends Model> {
+
+ /**
+ * Must start with a slash, for example: /api/metrics
+ */
+ public abstract String getUrl();
+
+ protected static void appendUrlParameter(StringBuilder url, String paramKey, Object paramValue) {
+ if (paramValue != null) {
+ url.append(paramKey)
+ .append('=')
+ .append(paramValue)
+ .append('&');
+ }
+ }
+
+ protected static void appendUrlParameter(StringBuilder url, String paramKey, Object[] paramValues) {
+ if (paramValues != null) {
+ url.append(paramKey).append('=');
+ for (int index = 0; index < paramValues.length; index++) {
+ if (index > 0) {
+ url.append(',');
+ }
+ if (paramValues[index] != null) {
+ url.append(paramValues[index]);
+ }
+ }
+ url.append('&');
+ }
+ }
+
+ protected static void appendUrlParameter(StringBuilder url, String paramKey, Date paramValue, boolean includeTime) {
+ if (paramValue != null) {
+ String format = (includeTime ? "yyyy-MM-dd'T'HH:mm:ssZ" : "yyyy-MM-dd");
+ url.append(paramKey)
+ .append('=')
+ .append(WSUtils.getINSTANCE().encodeUrl(WSUtils.getINSTANCE().format(paramValue, format)))
+ .append('&');
+ }
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/CreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/CreateQuery.java
new file mode 100644
index 00000000000..f43200604d8
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/CreateQuery.java
@@ -0,0 +1,31 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * POST HTTP request
+ *
+ * @since 2.2
+ */
+public abstract class CreateQuery<MODEL extends Model> extends AbstractQuery<MODEL> {
+
+ public abstract Class<MODEL> getModelClass();
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DeleteQuery.java
new file mode 100644
index 00000000000..0126452bfa7
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DeleteQuery.java
@@ -0,0 +1,29 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * DELETE HTTP request
+ *
+ * @since 2.2
+ */
+public abstract class DeleteQuery<MODEL extends Model> extends AbstractQuery<MODEL> {
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Dependency.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Dependency.java
new file mode 100644
index 00000000000..e6d84d6a1f1
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Dependency.java
@@ -0,0 +1,159 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class Dependency extends Model {
+
+ private String id;
+ private long fromId;
+ private long toId;
+ private String usage;
+ private int weight;
+ private String fromKey;
+ private String fromName;
+ private String fromQualifier;
+ private String toKey;
+ private String toName;
+ private String toQualifier;
+
+ public String getId() {
+ return id;
+ }
+
+ public Dependency setId(String id) {
+ this.id = id;
+ return this;
+ }
+
+ public long getFromId() {
+ return fromId;
+ }
+
+ public Dependency setFromId(long fromId) {
+ this.fromId = fromId;
+ return this;
+ }
+
+ public long getToId() {
+ return toId;
+ }
+
+ public Dependency setToId(long toId) {
+ this.toId = toId;
+ return this;
+ }
+
+ public String getFromKey() {
+ return fromKey;
+ }
+
+ public Dependency setFromKey(String fromKey) {
+ this.fromKey = fromKey;
+ return this;
+ }
+
+ public String getToKey() {
+ return toKey;
+ }
+
+ public Dependency setToKey(String toKey) {
+ this.toKey = toKey;
+ return this;
+ }
+
+ public String getUsage() {
+ return usage;
+ }
+
+ public Dependency setUsage(String usage) {
+ this.usage = usage;
+ return this;
+ }
+
+ public Integer getWeight() {
+ return weight;
+ }
+
+ public Dependency setWeight(Integer weight) {
+ this.weight = weight;
+ return this;
+ }
+
+ public String getFromName() {
+ return fromName;
+ }
+
+ public Dependency setFromName(String fromName) {
+ this.fromName = fromName;
+ return this;
+ }
+
+ public String getFromQualifier() {
+ return fromQualifier;
+ }
+
+ public Dependency setFromQualifier(String fromQualifier) {
+ this.fromQualifier = fromQualifier;
+ return this;
+ }
+
+ public String getToName() {
+ return toName;
+ }
+
+ public Dependency setToName(String toName) {
+ this.toName = toName;
+ return this;
+ }
+
+ public String getToQualifier() {
+ return toQualifier;
+ }
+
+ public Dependency setToQualifier(String toQualifier) {
+ this.toQualifier = toQualifier;
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Dependency that = (Dependency) o;
+ return id.equals(that.id);
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder()
+ .append(fromKey)
+ .append(" -> ")
+ .append(toKey)
+ .toString();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java
new file mode 100644
index 00000000000..7d5f10601d5
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java
@@ -0,0 +1,153 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * The web service "dependency" is since Sonar 2.0
+ */
+public class DependencyQuery extends Query<Dependency> {
+ public static final String BASE_URL = "/api/dependencies";
+
+ private String resourceIdOrKey = null;
+ private String direction = null;
+ private String parentId = null;
+ private String id = null;
+ public static final String INCOMING_DIRECTION = "in";
+ public static final String OUTGOING_DIRECTION = "out";
+
+ public String getResourceIdOrKey() {
+ return resourceIdOrKey;
+ }
+
+ public DependencyQuery setResourceIdOrKey(String resourceIdOrKey) {
+ this.resourceIdOrKey = resourceIdOrKey;
+ return this;
+ }
+
+ public DependencyQuery setResourceId(long resourceId) {
+ this.resourceIdOrKey = String.valueOf(resourceId);
+ return this;
+ }
+
+ public String getDirection() {
+ return direction;
+ }
+
+ public DependencyQuery setDirection(String direction) {
+ this.direction = direction;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ url.append('?');
+ if (resourceIdOrKey != null) {
+ url.append("resource=").append(resourceIdOrKey).append('&');
+ }
+ if (direction != null) {
+ url.append("dir=").append(direction).append('&');
+ }
+ if (parentId !=null) {
+ url.append("parent=").append(parentId).append('&');
+ }
+ if (id !=null) {
+ url.append("id=").append(id).append('&');
+ }
+ return url.toString();
+ }
+
+ public String getParentId() {
+ return parentId;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public DependencyQuery setId(String id) {
+ this.id = id;
+ return this;
+ }
+
+ public DependencyQuery setParentId(String parentId) {
+ this.parentId = parentId;
+ return this;
+ }
+
+ @Override
+ public Class<Dependency> getModelClass() {
+ return Dependency.class;
+ }
+
+ /**
+ * Resources that depend upon a resource
+ *
+ * @param resourceIdOrKey the target resource. Can be the primary key (a number) or the logical key (String)
+ */
+ public static DependencyQuery createForIncomingDependencies(String resourceIdOrKey) {
+ DependencyQuery query = new DependencyQuery();
+ query.setResourceIdOrKey(resourceIdOrKey);
+ query.setDirection(INCOMING_DIRECTION);
+ return query;
+ }
+
+ /**
+ * Resources that are depended upon a resource = all the resources that a resource depends upon
+ *
+ * @param resourceIdOrKey the target resource. Can be the primary key (an integer) or the logical key (String)
+ */
+ public static DependencyQuery createForOutgoingDependencies(String resourceIdOrKey) {
+ DependencyQuery query = new DependencyQuery();
+ query.setResourceIdOrKey(resourceIdOrKey);
+ query.setDirection(OUTGOING_DIRECTION);
+ return query;
+ }
+
+ /**
+ * Resources that depend upon or are depended upon a resource. It equals the merge of createForIncomingDependencies(resourceIdOrKey)
+ * and createForOutgoingDependencies(resourceIdOrKey)
+ *
+ * @param resourceIdOrKey the target resource. Can be the primary key (an integer) or the logical key (String)
+ */
+ public static DependencyQuery createForResource(String resourceIdOrKey) {
+ DependencyQuery query = new DependencyQuery();
+ query.setResourceIdOrKey(resourceIdOrKey);
+ return query;
+ }
+
+ public static DependencyQuery createForResource(long resourceId) {
+ DependencyQuery query = new DependencyQuery();
+ query.setResourceId(resourceId);
+ return query;
+ }
+
+ public static DependencyQuery createForSubDependencies(String dependencyId) {
+ DependencyQuery query = new DependencyQuery();
+ query.setParentId(dependencyId);
+ return query;
+ }
+
+ public static DependencyQuery createForId(String id) {
+ DependencyQuery query = new DependencyQuery();
+ query.setId(id);
+ return query;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTree.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTree.java
new file mode 100644
index 00000000000..86c3eb377a4
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTree.java
@@ -0,0 +1,128 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.List;
+
+/**
+ * Experimental
+ */
+public class DependencyTree extends Model {
+ private String depId;
+ private String resourceId;
+ private String resourceKey;
+ private String resourceName;
+ private String usage;
+ private String resourceScope;
+ private String resourceQualifier;
+ private String resourceVersion;
+ private int weight;
+ private List<DependencyTree> to;
+
+ public String getDepId() {
+ return depId;
+ }
+
+ public DependencyTree setDepId(String depId) {
+ this.depId = depId;
+ return this;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public DependencyTree setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ return this;
+ }
+
+ public String getResourceKey() {
+ return resourceKey;
+ }
+
+ public DependencyTree setResourceKey(String resourceKey) {
+ this.resourceKey = resourceKey;
+ return this;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public DependencyTree setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ return this;
+ }
+
+ public String getUsage() {
+ return usage;
+ }
+
+ public DependencyTree setUsage(String usage) {
+ this.usage = usage;
+ return this;
+ }
+
+ public String getResourceScope() {
+ return resourceScope;
+ }
+
+ public DependencyTree setResourceScope(String resourceScope) {
+ this.resourceScope = resourceScope;
+ return this;
+ }
+
+ public String getResourceQualifier() {
+ return resourceQualifier;
+ }
+
+ public DependencyTree setResourceQualifier(String resourceQualifier) {
+ this.resourceQualifier = resourceQualifier;
+ return this;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public DependencyTree setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ return this;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public DependencyTree setWeight(int weight) {
+ this.weight = weight;
+ return this;
+ }
+
+ public List<DependencyTree> getTo() {
+ return to;
+ }
+
+ public DependencyTree setTo(List<DependencyTree> to) {
+ this.to = to;
+ return this;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java
new file mode 100644
index 00000000000..b5dad433259
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java
@@ -0,0 +1,88 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.1
+ */
+public class DependencyTreeQuery extends Query<DependencyTree> {
+ private static final String BASE_URL = "/api/dependency_tree";
+
+ private String resourceId;
+ private String[] scopes;
+
+ public DependencyTreeQuery(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public String[] getScopes() {
+ return scopes;
+ }
+
+ public DependencyTreeQuery setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ return this;
+ }
+
+ public DependencyTreeQuery setScopes(String... scopes) {
+ this.scopes = scopes;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ url.append("?resource=")
+ .append(resourceId)
+ .append("&");
+ if (scopes != null) {
+ url.append("scopes=");
+ if (scopes != null) {
+ for (int index = 0; index < scopes.length; index++) {
+ if (index > 0) {
+ url.append(',');
+ }
+ if (scopes[index] != null) {
+ url.append(scopes[index]);
+ }
+ }
+ url.append('&');
+ }
+ }
+ return url.toString();
+ }
+
+ @Override
+ public Class<DependencyTree> getModelClass() {
+ return DependencyTree.class;
+ }
+
+ public static DependencyTreeQuery createForResource(String resourceIdOrKey) {
+ return new DependencyTreeQuery(resourceIdOrKey);
+ }
+
+ public static DependencyTreeQuery createForProject(String projectIdOrKey) {
+ return new DependencyTreeQuery(projectIdOrKey).setScopes(Resource.SCOPE_SET);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Event.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Event.java
new file mode 100644
index 00000000000..e2181170655
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Event.java
@@ -0,0 +1,114 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.Date;
+
+public class Event extends Model {
+
+ private String id;
+ private String name;
+ private String category;
+ private String description;
+ private String resourceKey;
+ private Date date;
+ private String data;
+
+ public String getId() {
+ return id;
+ }
+
+ public Event setId(String id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Event setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public Event setCategory(String category) {
+ this.category = category;
+ return this;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Event setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public Event setDate(Date date) {
+ this.date = date;
+ return this;
+ }
+
+ public String getResourceKey() {
+ return resourceKey;
+ }
+
+ public Event setResourceKey(String resourceKey) {
+ this.resourceKey = resourceKey;
+ return this;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public Event setData(String data) {
+ this.data = data;
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Event event = (Event) o;
+ return !(id != null ? !id.equals(event.id) : event.id != null);
+ }
+
+ @Override
+ public int hashCode() {
+ return id != null ? id.hashCode() : 0;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/EventCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/EventCreateQuery.java
new file mode 100644
index 00000000000..9c3e1e3231a
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/EventCreateQuery.java
@@ -0,0 +1,49 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @author Evgeny Mandrikov
+ * @since 2.2
+ */
+public class EventCreateQuery extends CreateQuery<Event> {
+ private Event event;
+
+ public EventCreateQuery(Event event) {
+ this.event = event;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(EventQuery.BASE_URL);
+ url.append('?');
+ appendUrlParameter(url, "resource", event.getResourceKey());
+ appendUrlParameter(url, "category", event.getCategory());
+ appendUrlParameter(url, "name", event.getName());
+ appendUrlParameter(url, "description", event.getDescription());
+ appendUrlParameter(url, "data", event.getData());
+ return url.toString();
+ }
+
+ @Override
+ public Class<Event> getModelClass() {
+ return Event.class;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/EventQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/EventQuery.java
new file mode 100644
index 00000000000..3e7dfdbe809
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/EventQuery.java
@@ -0,0 +1,114 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.Date;
+
+public class EventQuery extends Query<Event> {
+ public static final String BASE_URL = "/api/events";
+
+ private String resourceKey;
+ private String[] categories;
+ private Date fromDate;
+ private boolean includeFromTime;
+ private Date toDate;
+ private boolean includeToTime;
+
+ public EventQuery() {
+ }
+
+ public EventQuery(String resourceKey) {
+ this.resourceKey = resourceKey;
+ }
+
+ public Date getFrom() {
+ return fromDate;
+ }
+
+ public EventQuery setFrom(Date fromDate, boolean includeTime) {
+ this.fromDate = fromDate;
+ this.includeFromTime = includeTime;
+ return this;
+ }
+
+ public boolean isIncludeFromTime() {
+ return includeFromTime;
+ }
+
+ public Date getTo() {
+ return toDate;
+ }
+
+ public EventQuery setTo(Date toDate, boolean includeTime) {
+ this.toDate = toDate;
+ this.includeToTime = includeTime;
+ return this;
+ }
+
+ public boolean isIncludeToTime() {
+ return includeToTime;
+ }
+
+ public String getResourceKey() {
+ return resourceKey;
+ }
+
+ public EventQuery setResourceKey(String resourceKey) {
+ this.resourceKey = resourceKey;
+ return this;
+ }
+
+ public String[] getCategories() {
+ return categories;
+ }
+
+ public EventQuery setCategories(String[] categories) {
+ this.categories = categories;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKey);
+ appendUrlParameter(url, "categories", categories);
+ if (fromDate != null) {
+ if (includeFromTime) {
+ appendUrlParameter(url, "fromDateTime", fromDate, true);
+ } else {
+ appendUrlParameter(url, "fromDate", fromDate, false);
+ }
+ }
+ if (toDate != null) {
+ if (includeToTime) {
+ appendUrlParameter(url, "toDateTime", toDate, true);
+ } else {
+ appendUrlParameter(url, "toDate", toDate, false);
+ }
+ }
+ return url.toString();
+ }
+
+ @Override
+ public Class<Event> getModelClass() {
+ return Event.class;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Favourite.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Favourite.java
new file mode 100644
index 00000000000..67917846984
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Favourite.java
@@ -0,0 +1,84 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class Favourite extends Model {
+
+ private Integer id;
+ private String key;
+ private String name;
+ private String scope;
+ private String qualifier;
+ private String language;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public Favourite setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public Favourite setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Favourite setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public Favourite setScope(String scope) {
+ this.scope = scope;
+ return this;
+ }
+
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ public Favourite setQualifier(String qualifier) {
+ this.qualifier = qualifier;
+ return this;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public Favourite setLanguage(String language) {
+ this.language = language;
+ return this;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java
new file mode 100644
index 00000000000..62484b1c17e
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java
@@ -0,0 +1,39 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class FavouriteCreateQuery extends CreateQuery<Favourite> {
+
+ private String idOrKey;
+
+ public FavouriteCreateQuery(String idOrKey) {
+ this.idOrKey = idOrKey;
+ }
+
+ @Override
+ public String getUrl() {
+ return new StringBuilder().append(FavouriteQuery.BASE_URL).append("?key=").append(idOrKey).toString();
+ }
+
+ @Override
+ public Class<Favourite> getModelClass() {
+ return Favourite.class;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java
new file mode 100644
index 00000000000..00af7895cd3
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java
@@ -0,0 +1,38 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class FavouriteDeleteQuery extends DeleteQuery {
+
+ private String idOrKey;
+
+ public FavouriteDeleteQuery(String idOrKey) {
+ this.idOrKey = idOrKey;
+ }
+
+ public String getIdOrKey() {
+ return idOrKey;
+ }
+
+ @Override
+ public String getUrl() {
+ return new StringBuilder().append(FavouriteQuery.BASE_URL).append('/').append(idOrKey).toString();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteQuery.java
new file mode 100644
index 00000000000..314389e8fa4
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteQuery.java
@@ -0,0 +1,35 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class FavouriteQuery extends Query<Favourite> {
+
+ public static final String BASE_URL = "/api/favourites";
+
+ @Override
+ public Class<Favourite> getModelClass() {
+ return Favourite.class;
+ }
+
+ @Override
+ public String getUrl() {
+ return BASE_URL;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Measure.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Measure.java
new file mode 100644
index 00000000000..eb3cae9b9f6
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Measure.java
@@ -0,0 +1,190 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class Measure extends Model {
+
+ private String metricKey;
+ private String metricName;
+ private Double value;
+ private String formattedValue;
+ private String data;
+ private String characteristicKey;
+ private String characteristicName;
+
+ private Integer trend;
+ private Integer var;
+
+ private String ruleKey;
+ private String ruleName;
+ private String ruleCategory;
+ private String rulePriority;
+
+ public String getMetricKey() {
+ return metricKey;
+ }
+
+ public Measure setMetricKey(String metricKey) {
+ this.metricKey = metricKey;
+ return this;
+ }
+
+ public String getMetricName() {
+ return metricName;
+ }
+
+ public Measure setMetricName(String metricName) {
+ this.metricName = metricName;
+ return this;
+ }
+
+ public Double getValue() {
+ return value;
+ }
+
+ public Integer getIntValue() {
+ if (value==null) {
+ return null;
+ }
+ return value.intValue();
+ }
+
+ public Measure setValue(Double value) {
+ this.value = value;
+ return this;
+ }
+
+ public String getFormattedValue() {
+ return formattedValue;
+ }
+
+ public String getFormattedValue(String defaultValue) {
+ if (formattedValue==null) {
+ return defaultValue;
+ }
+ return formattedValue;
+ }
+
+ public Measure setFormattedValue(String formattedValue) {
+ this.formattedValue = formattedValue;
+ return this;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public Map<String,String> getDataAsMap() {
+ return getDataAsMap(",");
+ }
+
+ public Map<String,String> getDataAsMap(String separator) {
+ if (data==null) {
+ return null;
+ }
+ Map<String,String> map = new LinkedHashMap<String,String>();
+ String[] parts = data.split(separator);
+ for (String part : parts) {
+ String[] kv = part.split("=");
+ map.put(kv[0], kv[1]);
+ }
+ return map;
+ }
+
+ public Measure setData(String data) {
+ this.data = data;
+ return this;
+ }
+
+ public Integer getTrend() {
+ return trend;
+ }
+
+ public Measure setTrend(Integer trend) {
+ this.trend = trend;
+ return this;
+ }
+
+ public Integer getVar() {
+ return var;
+ }
+
+ public Measure setVar(Integer var) {
+ this.var = var;
+ return this;
+ }
+
+ public String getRuleKey() {
+ return ruleKey;
+ }
+
+ public Measure setRuleKey(String ruleKey) {
+ this.ruleKey = ruleKey;
+ return this;
+ }
+
+ public String getRuleName() {
+ return ruleName;
+ }
+
+ public Measure setRuleName(String ruleName) {
+ this.ruleName = ruleName;
+ return this;
+ }
+
+ public String getRuleCategory() {
+ return ruleCategory;
+ }
+
+ public Measure setRuleCategory(String ruleCategory) {
+ this.ruleCategory = ruleCategory;
+ return this;
+ }
+
+ public String getRulePriority() {
+ return rulePriority;
+ }
+
+ public Measure setRulePriority(String rulePriority) {
+ this.rulePriority = rulePriority;
+ return this;
+ }
+
+ public String getCharacteristicKey() {
+ return characteristicKey;
+ }
+
+ public String getCharacteristicName() {
+ return characteristicName;
+ }
+
+ public Measure setCharacteristicKey(String s) {
+ this.characteristicKey = s;
+ return this;
+ }
+
+ public Measure setCharacteristicName(String s) {
+ this.characteristicName = s;
+ return this;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Metric.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Metric.java
new file mode 100644
index 00000000000..07ede19e5db
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Metric.java
@@ -0,0 +1,114 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class Metric extends Model {
+
+ private String key;
+ private String name;
+ private int direction;
+ private String domain;
+ private String description;
+ private String type;
+ private Boolean userManaged;
+ private Boolean hidden;
+
+ public String getKey() {
+ return key;
+ }
+
+ public Metric setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Metric setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public int getDirection() {
+ return direction;
+ }
+
+ public Metric setDirection(int direction) {
+ this.direction = direction;
+ return this;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public Metric setDomain(String domain) {
+ this.domain = domain;
+ return this;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Metric setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public Metric setType(String type) {
+ this.type = type;
+ return this;
+ }
+
+ public Boolean getHidden() {
+ return hidden;
+ }
+
+ public Metric setHidden(Boolean hidden) {
+ this.hidden = hidden;
+ return this;
+ }
+
+ public Boolean getUserManaged() {
+ return userManaged;
+ }
+
+ public Metric setUserManaged(Boolean userManaged) {
+ this.userManaged = userManaged;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder()
+ .append(name)
+ .append("(")
+ .append(key)
+ .append(")")
+ .toString();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java
new file mode 100644
index 00000000000..6870cde0da8
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java
@@ -0,0 +1,57 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public final class MetricQuery extends Query<Metric> {
+ public static final String BASE_URL = "/api/metrics";
+
+ private String key;
+
+ private MetricQuery() {
+ }
+
+ private MetricQuery(String key) {
+ this.key = key;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder sb = new StringBuilder(BASE_URL);
+ if (key != null && !"".equals(key)) {
+ sb.append("/");
+ sb.append(key);
+ }
+ sb.append("?");
+ return sb.toString();
+ }
+
+ @Override
+ public Class<Metric> getModelClass() {
+ return Metric.class;
+ }
+
+ public static MetricQuery all() {
+ return new MetricQuery();
+ }
+
+ public static MetricQuery byKey(String metricKey) {
+ return new MetricQuery(metricKey);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Model.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Model.java
new file mode 100644
index 00000000000..3f864877549
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Model.java
@@ -0,0 +1,23 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public abstract class Model {
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Property.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Property.java
new file mode 100644
index 00000000000..fd86599c106
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Property.java
@@ -0,0 +1,63 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class Property extends Model {
+
+ private String key;
+ private String value;
+
+ public Property(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public Property() {
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public Property setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public Property setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder()
+ .append('[')
+ .append(key)
+ .append(':')
+ .append(value)
+ .append(']')
+ .toString();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java
new file mode 100644
index 00000000000..1e005cac291
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java
@@ -0,0 +1,57 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class PropertyQuery extends Query<Property> {
+ public static final String BASE_URL = "/api/properties";
+
+ private String key = null;
+
+ public String getKey() {
+ return key;
+ }
+
+ public PropertyQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ String url = BASE_URL;
+ if (key != null) {
+ url += "/" + key;
+ }
+ return url + "?";
+ }
+
+ @Override
+ public Class<Property> getModelClass() {
+ return Property.class;
+ }
+
+ public static PropertyQuery createForAll() {
+ return new PropertyQuery();
+ }
+
+ public static PropertyQuery createForKey(String key) {
+ return new PropertyQuery().setKey(key);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Query.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Query.java
new file mode 100644
index 00000000000..345fc109cc3
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Query.java
@@ -0,0 +1,31 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * GET HTTP request
+ *
+ * @since 2.1
+ */
+public abstract class Query<MODEL extends Model> extends AbstractQuery<MODEL> {
+
+ public abstract Class<MODEL> getModelClass();
+
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Resource.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Resource.java
new file mode 100644
index 00000000000..9c0db8178e2
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Resource.java
@@ -0,0 +1,210 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.Collections;
+import java.util.List;
+
+public class Resource extends Model {
+
+ /* SCOPES */
+ public static final String SCOPE_SET = "PRJ";
+ public static final String SCOPE_SPACE = "DIR";
+ public static final String SCOPE_ENTITY = "FIL";
+
+ /* QUALIFIERS */
+ public static final String QUALIFIER_VIEW = "VW";
+ public static final String QUALIFIER_SUBVIEW = "SVW";
+ public static final String QUALIFIER_LIB = "LIB";
+ public static final String QUALIFIER_PROJECT = "TRK";
+ public static final String QUALIFIER_MODULE = "BRC";
+ public static final String QUALIFIER_PACKAGE = "PAC";
+ public static final String QUALIFIER_DIRECTORY = "DIR";
+ public static final String QUALIFIER_FILE = "FIL";
+ public static final String QUALIFIER_CLASS = "CLA";
+ public static final String QUALIFIER_UNIT_TEST_CLASS = "UTS";
+
+ /* LANGUAGES */
+ public static final String LANGUAGE_JAVA = "java";
+
+ private Integer id;
+ private String key;
+ private String name;
+ private String longName;
+ private String scope;
+ private String qualifier;
+ private String language;
+ private String version;
+ private Integer copy;
+ private String description;
+ private List<Measure> measures;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public Resource setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public Resource setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Resource setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getName(boolean longFormatIfDefined) {
+ if (longFormatIfDefined && longName != null && !"".equals(longName)) {
+ return longName;
+ }
+ return name;
+ }
+
+ public String getLongName() {
+ return longName;
+ }
+
+ public Resource setLongName(String longName) {
+ this.longName = longName;
+ return this;
+ }
+
+ public Resource setName(String s) {
+ this.name = s;
+ return this;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public Resource setScope(String scope) {
+ this.scope = scope;
+ return this;
+ }
+
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ public Resource setQualifier(String qualifier) {
+ this.qualifier = qualifier;
+ return this;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public Resource setLanguage(String language) {
+ this.language = language;
+ return this;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public Resource setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ public Integer getCopy() {
+ return copy;
+ }
+
+ public Resource setCopy(Integer copy) {
+ this.copy = copy;
+ return this;
+ }
+
+ public List<Measure> getMeasures() {
+ if (measures == null) {
+ return Collections.emptyList();
+ }
+ return measures;
+ }
+
+ public Measure getMeasure(String metricKey) {
+ for (Measure measure : getMeasures()) {
+ if (metricKey.equals(measure.getMetricKey())) {
+ return measure;
+ }
+ }
+ return null;
+ }
+
+ public Double getMeasureValue(String metricKey) {
+ Measure measure = getMeasure(metricKey);
+ if (measure != null) {
+ return measure.getValue();
+ }
+ return null;
+ }
+
+ public Integer getMeasureIntValue(String metricKey) {
+ Double d = getMeasureValue(metricKey);
+ if (d != null) {
+ return d.intValue();
+ }
+ return null;
+ }
+
+ public String getMeasureFormattedValue(String metricKey, String defaultValue) {
+ Measure measure = getMeasure(metricKey);
+ if (measure != null) {
+ return measure.getFormattedValue(defaultValue);
+ }
+ return defaultValue;
+ }
+
+ public void setMeasures(List<Measure> measures) {
+ this.measures = measures;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder()
+ .append("[id=")
+ .append(id)
+ .append(",key=")
+ .append(key)
+ .append("]")
+ .toString();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceQuery.java
new file mode 100644
index 00000000000..8836b9f2bb0
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceQuery.java
@@ -0,0 +1,250 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class ResourceQuery extends Query<Resource> {
+ public static final String BASE_URL = "/api/resources";
+
+ public final static int DEPTH_UNLIMITED = -1;
+
+ private Integer depth;
+ private String resourceKeyOrId;
+ private Integer limit;
+ private String[] scopes;
+ private String[] qualifiers;
+ private String[] metrics;
+ private String[] rules;
+ private String[] ruleCategories;
+ private String[] rulePriorities;
+ private String[] characteristicKeys;
+ private String model;
+ private boolean excludeRules = true;
+ private boolean excludeRuleCategories = true;
+ private boolean excludeRulePriorities = true;
+ private Boolean includeTrends = null;
+ private Boolean verbose = Boolean.FALSE;
+
+ public ResourceQuery() {
+ }
+
+ public ResourceQuery(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public ResourceQuery(long resourceId) {
+ this.resourceKeyOrId = String.valueOf(resourceId);
+ }
+
+ public Integer getDepth() {
+ return depth;
+ }
+
+ public ResourceQuery setDepth(Integer depth) {
+ this.depth = depth;
+ return this;
+ }
+
+ public ResourceQuery setAllDepths() {
+ return setDepth(DEPTH_UNLIMITED);
+ }
+
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public ResourceQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
+ public ResourceQuery setResourceId(int resourceId) {
+ this.resourceKeyOrId = Integer.toString(resourceId);
+ return this;
+ }
+
+ public ResourceQuery setCharacteristicKeys(String model, String... keys) {
+ this.model=model;
+ this.characteristicKeys = keys;
+ return this;
+ }
+
+
+ public Integer getLimit() {
+ return limit;
+ }
+
+ public ResourceQuery setLimit(Integer limit) {
+ this.limit = limit;
+ return this;
+ }
+
+ public String[] getScopes() {
+ return scopes;
+ }
+
+ public ResourceQuery setScopes(String... scopes) {
+ this.scopes = scopes;
+ return this;
+ }
+
+ public String[] getQualifiers() {
+ return qualifiers;
+ }
+
+ public ResourceQuery setQualifiers(String... qualifiers) {
+ this.qualifiers = qualifiers;
+ return this;
+ }
+
+ public String[] getMetrics() {
+ return metrics;
+ }
+
+ public ResourceQuery setMetrics(String... metrics) {
+ this.metrics = metrics;
+ return this;
+ }
+
+ public String[] getRules() {
+ return rules;
+ }
+
+ public ResourceQuery setRules(String... rules) {
+ this.rules = rules;
+ this.excludeRules = false;
+ return this;
+ }
+
+ public String[] getRuleCategories() {
+ return ruleCategories;
+ }
+
+ /**
+ * @param ruleCategories values: Maintainability, Usability, Reliability, Efficiency, Portability
+ */
+ public ResourceQuery setRuleCategories(String... ruleCategories) {
+ this.ruleCategories = ruleCategories;
+ this.excludeRuleCategories = false;
+ return this;
+ }
+
+ public String[] getRulePriorities() {
+ return rulePriorities;
+ }
+
+ /**
+ * @param rulePriorities values: BLOCKER, CRITICAL, MAJOR, MINOR, INFO
+ */
+ public ResourceQuery setRulePriorities(String... rulePriorities) {
+ this.rulePriorities = rulePriorities;
+ this.excludeRulePriorities = false;
+ return this;
+ }
+
+ public boolean isExcludeRules() {
+ return excludeRules;
+ }
+
+ public ResourceQuery setExcludeRules(boolean excludeRules) {
+ this.excludeRules = excludeRules;
+ return this;
+ }
+
+ public boolean isExcludeRuleCategories() {
+ return excludeRuleCategories;
+ }
+
+ public ResourceQuery setExcludeRuleCategories(boolean excludeRuleCategories) {
+ this.excludeRuleCategories = excludeRuleCategories;
+ return this;
+ }
+
+ public boolean isExcludeRulePriorities() {
+ return excludeRulePriorities;
+ }
+
+ public ResourceQuery setExcludeRulePriorities(boolean excludeRulePriorities) {
+ this.excludeRulePriorities = excludeRulePriorities;
+ return this;
+ }
+
+ public Boolean isVerbose() {
+ return verbose;
+ }
+
+ public ResourceQuery setVerbose(Boolean verbose) {
+ this.verbose = verbose;
+ return this;
+ }
+
+ public Boolean isIncludeTrends() {
+ return includeTrends;
+ }
+
+ public ResourceQuery setIncludeTrends(Boolean includeTrends) {
+ this.includeTrends = includeTrends;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ appendUrlParameter(url, "metrics", metrics);
+ appendUrlParameter(url, "scopes", scopes);
+ appendUrlParameter(url, "qualifiers", qualifiers);
+ appendUrlParameter(url, "depth", depth);
+ appendUrlParameter(url, "limit", limit);
+ appendRuleField(url, "rules", excludeRules, rules);
+ appendRuleField(url, "rule_categories", excludeRuleCategories, ruleCategories);
+ appendRuleField(url, "rule_priorities", excludeRulePriorities, rulePriorities);
+ appendUrlParameter(url, "includetrends", includeTrends);
+ appendUrlParameter(url, "model", model);
+ appendUrlParameter(url, "characteristics", characteristicKeys);
+ appendUrlParameter(url, "verbose", verbose);
+ return url.toString();
+ }
+
+ private void appendRuleField(StringBuilder url, String field, boolean excludeField, String[] list) {
+ if (!excludeField) {
+ if (list == null || list.length == 0) {
+ appendUrlParameter(url, field, true);
+ } else {
+ appendUrlParameter(url, field, list);
+ }
+ }
+ }
+
+ @Override
+ public final Class<Resource> getModelClass() {
+ return Resource.class;
+ }
+
+ public static ResourceQuery createForMetrics(String resourceKeyOrId, String... metricKeys) {
+ return new ResourceQuery(resourceKeyOrId)
+ .setMetrics(metricKeys);
+ }
+
+ public static ResourceQuery createForResource(Resource resource, String... metricKeys) {
+ return new ResourceQuery(resource.getId().toString())
+ .setMetrics(metricKeys);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java
new file mode 100644
index 00000000000..4919fbb123d
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java
@@ -0,0 +1,46 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @author Evgeny Mandrikov
+ */
+public class Server extends Model {
+ private String id;
+ private String version;
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public Server setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ public Server setId(String id) {
+ this.id = id;
+ return this;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ServerQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ServerQuery.java
new file mode 100644
index 00000000000..ef88ed16df6
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ServerQuery.java
@@ -0,0 +1,37 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @author Evgeny Mandrikov
+ */
+public class ServerQuery extends Query<Server> {
+ public static final String BASE_URL = "/api/server/index";
+
+ @Override
+ public String getUrl() {
+ return BASE_URL;
+ }
+
+ @Override
+ public Class<Server> getModelClass() {
+ return Server.class;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Source.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Source.java
new file mode 100644
index 00000000000..b703f725c89
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Source.java
@@ -0,0 +1,51 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.Collection;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+public class Source extends Model {
+
+ private SortedMap<Integer, String> lines = new TreeMap<Integer, String>();
+
+ public Collection<String> getLines() {
+ return lines.values();
+ }
+
+ public SortedMap<Integer, String> getLinesById() {
+ return lines;
+ }
+
+ public String getLine(int index) {
+ return lines.get(index);
+ }
+
+ public int size() {
+ return lines.size();
+ }
+
+ public Source addLine(int index, String line) {
+ lines.put(index, line);
+ return this;
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java
new file mode 100644
index 00000000000..2d79d662640
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java
@@ -0,0 +1,105 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class SourceQuery extends Query<Source> {
+ public static final String BASE_URL = "/api/sources";
+
+ private String resourceKeyOrId;
+ private int from = 0;
+ private int to = 0;
+ private boolean highlightedSyntax = false;
+
+ public SourceQuery(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public SourceQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
+ public int getFrom() {
+ return from;
+ }
+
+ /**
+ * Get only a few lines
+ *
+ * @param from Index of the first line, starts to 1
+ * @param excludedTo Index of the last line (excluded).
+ */
+ public SourceQuery setFromLineToLine(int from, int excludedTo) {
+ this.from = from;
+ this.to = excludedTo;
+ return this;
+ }
+
+ public SourceQuery setLinesFromLine(int from, int length) {
+ this.from = from;
+ this.to = from + length;
+ return this;
+ }
+
+ public int getTo() {
+ return to;
+ }
+
+ public boolean isHighlightedSyntax() {
+ return highlightedSyntax;
+ }
+
+ public SourceQuery setHighlightedSyntax(boolean b) {
+ this.highlightedSyntax = b;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ url.append("?resource=")
+ .append(resourceKeyOrId)
+ .append("&");
+ if (from > 0 && to > 0) {
+ url.append("from=").append(from).append("&to=").append(to).append("&");
+ }
+ if (highlightedSyntax) {
+ url.append("color=true&");
+ }
+ return url.toString();
+ }
+
+ @Override
+ public Class<Source> getModelClass() {
+ return Source.class;
+ }
+
+ public static SourceQuery create(String resourceKeyOrId) {
+ return new SourceQuery(resourceKeyOrId);
+ }
+
+ public static SourceQuery createWithHighlightedSyntax(String resourceKeyOrId) {
+ return new SourceQuery(resourceKeyOrId).setHighlightedSyntax(true);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyCreateQuery.java
new file mode 100644
index 00000000000..baeba6806f7
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyCreateQuery.java
@@ -0,0 +1,75 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.2
+ */
+public class UserPropertyCreateQuery extends CreateQuery<Property> {
+
+ private String key;
+ private String value;
+
+ public UserPropertyCreateQuery() {
+ }
+
+ public UserPropertyCreateQuery(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public UserPropertyCreateQuery(Property property) {
+ this.key = property.getKey();
+ this.value = property.getValue();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public UserPropertyCreateQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public UserPropertyCreateQuery setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(UserPropertyQuery.BASE_URL);
+ sb.append('?');
+ appendUrlParameter(sb, "key", key);
+ appendUrlParameter(sb, "value", value);
+ return sb.toString();
+ }
+
+ @Override
+ public Class<Property> getModelClass() {
+ return Property.class;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java
new file mode 100644
index 00000000000..1f4defd58b2
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java
@@ -0,0 +1,50 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.2
+ */
+public class UserPropertyDeleteQuery extends DeleteQuery {
+
+ private String key;
+
+ public UserPropertyDeleteQuery(String key) {
+ this.key = key;
+ }
+
+ public UserPropertyDeleteQuery(Property property) {
+ this.key = property.getKey();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public UserPropertyDeleteQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ return new StringBuilder().append(UserPropertyQuery.BASE_URL).append('/').append(key).toString();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java
new file mode 100644
index 00000000000..d52b08f3fcf
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java
@@ -0,0 +1,67 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * Get properties of the authenticated user.
+ *
+ * @since 2.2
+ */
+public class UserPropertyQuery extends Query<Property> {
+ public static final String BASE_URL = "/api/user_properties";
+
+ private String key = null;
+
+ /**
+ * Get all user properties
+ */
+ public UserPropertyQuery() {
+ }
+
+ /**
+ * Get only one specific user property
+ */
+ public UserPropertyQuery(String key) {
+ this.key = key;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public UserPropertyQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ String url = BASE_URL;
+ if (key != null) {
+ url += "/" + key;
+ }
+ return url + "?";
+ }
+
+ @Override
+ public Class<Property> getModelClass() {
+ return Property.class;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
new file mode 100644
index 00000000000..4bbf784e3ee
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
@@ -0,0 +1,110 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class Violation extends Model {
+
+ private String message = null;
+ private String priority = null;
+ private Integer line = null;
+ private String ruleKey = null;
+ private String ruleName = null;
+ private String resourceKey = null;
+ private String resourceName = null;
+ private String resourceScope = null;
+ private String resourceQualifier = null;
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getPriority() {
+ return priority;
+ }
+
+ public void setPriority(String priority) {
+ this.priority = priority;
+ }
+
+ public Integer getLine() {
+ return line;
+ }
+
+ public void setLine(Integer line) {
+ this.line = line;
+ }
+
+ public String getResourceKey() {
+ return resourceKey;
+ }
+
+ public void setResourceKey(String resourceKey) {
+ this.resourceKey = resourceKey;
+ }
+
+ public String getRuleKey() {
+ return ruleKey;
+ }
+
+ public Violation setRuleKey(String s) {
+ this.ruleKey = s;
+ return this;
+ }
+
+ public String getRuleName() {
+ return ruleName;
+ }
+
+ public Violation setRuleName(String ruleName) {
+ this.ruleName = ruleName;
+ return this;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public Violation setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ return this;
+ }
+
+ public String getResourceScope() {
+ return resourceScope;
+ }
+
+ public Violation setResourceScope(String resourceScope) {
+ this.resourceScope = resourceScope;
+ return this;
+ }
+
+ public String getResourceQualifier() {
+ return resourceQualifier;
+ }
+
+ public Violation setResourceQualifier(String resourceQualifier) {
+ this.resourceQualifier = resourceQualifier;
+ return this;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
new file mode 100644
index 00000000000..9cfddcfb3b4
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
@@ -0,0 +1,134 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+public class ViolationQuery extends Query<Violation> {
+ public static final String BASE_URL = "/api/violations";
+
+ private String[] scopes;
+ private String[] qualifiers;
+ private String[] ruleKeys;
+ private String[] categories;
+ private String[] priorities;
+ private int depth = 0;
+ private String resourceKeyOrId;
+
+ public ViolationQuery(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public String[] getScopes() {
+ return scopes;
+ }
+
+ public ViolationQuery setScopes(String... scopes) {
+ this.scopes = scopes;
+ return this;
+ }
+
+ public String[] getQualifiers() {
+ return qualifiers;
+ }
+
+ public ViolationQuery setQualifiers(String... qualifiers) {
+ this.qualifiers = qualifiers;
+ return this;
+ }
+
+ public String[] getRuleKeys() {
+ return ruleKeys;
+ }
+
+ public ViolationQuery setRuleKeys(String... ruleKeys) {
+ this.ruleKeys = ruleKeys;
+ return this;
+ }
+
+ public String[] getCategories() {
+ return categories;
+ }
+
+ public ViolationQuery setCategories(String... categories) {
+ this.categories = categories;
+ return this;
+ }
+
+ public String[] getPriorities() {
+ return priorities;
+ }
+
+ public ViolationQuery setPriorities(String... priorities) {
+ this.priorities = priorities;
+ return this;
+ }
+
+ public int getDepth() {
+ return depth;
+ }
+
+ public ViolationQuery setDepth(int depth) {
+ this.depth = depth;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ url.append("?resource=")
+ .append(resourceKeyOrId)
+ .append("&");
+
+ if (depth != 0) {
+ url.append("depth").append(depth).append("&");
+ }
+ append(url, "scopes", scopes);
+ append(url, "qualifiers", qualifiers);
+ append(url, "rules", ruleKeys);
+ append(url, "categories", categories);
+ append(url, "priorities", priorities);
+ return url.toString();
+ }
+
+ private void append(StringBuilder url, String paramKey, Object[] paramValues) {
+ if (paramValues != null && paramValues.length > 0) {
+ url.append(paramKey).append('=');
+ for (int index = 0; index < paramValues.length; index++) {
+ if (index > 0) {
+ url.append(',');
+ }
+ url.append(paramValues[index]);
+ }
+ url.append('&');
+ }
+ }
+
+ @Override
+ public Class<Violation> getModelClass() {
+ return Violation.class;
+ }
+
+ public static ViolationQuery createForResource(Resource resource) {
+ return new ViolationQuery(resource.getId().toString());
+ }
+
+ public static ViolationQuery createForResource(String resourceIdOrKey) {
+ return new ViolationQuery(resourceIdOrKey);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java
new file mode 100644
index 00000000000..61e5940cb0f
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/WSUtils.java
@@ -0,0 +1,20 @@
+package org.sonar.wsclient.services;
+
+import java.util.Date;
+
+public abstract class WSUtils {
+
+ private static WSUtils INSTANCE = null;
+
+ public static void setInstance(WSUtils utils) {
+ INSTANCE = utils;
+ }
+
+ public static WSUtils getINSTANCE() {
+ return INSTANCE;
+ }
+
+ public abstract String format(Date date, String format);
+
+ public abstract String encodeUrl(String url);
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AbstractUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AbstractUnmarshaller.java
new file mode 100644
index 00000000000..d906f4ad9d8
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AbstractUnmarshaller.java
@@ -0,0 +1,58 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+import org.sonar.wsclient.services.Model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractUnmarshaller<MODEL extends Model> implements Unmarshaller<MODEL> {
+
+ public final MODEL toModel(String json) {
+ MODEL result = null;
+ JSONArray array = (JSONArray) JSONValue.parse(json);
+ if (array.size() >= 1) {
+ JSONObject elt = (JSONObject) array.get(0);
+ if (elt != null) {
+ result = parse(elt);
+ }
+ }
+ return result;
+
+ }
+
+ public final List<MODEL> toModels(String json) {
+ List<MODEL> result = new ArrayList<MODEL>();
+ JSONArray array = (JSONArray) JSONValue.parse(json);
+ for (Object anArray : array) {
+ JSONObject elt = (JSONObject) anArray;
+ if (elt != null) {
+ result.add(parse(elt));
+ }
+ }
+ return result;
+ }
+
+ protected abstract MODEL parse(JSONObject elt);
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshaller.java
new file mode 100644
index 00000000000..f326ba02176
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshaller.java
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.DependencyTree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DependencyTreeUnmarshaller extends AbstractUnmarshaller<DependencyTree> {
+ @Override
+ protected DependencyTree parse(JSONObject json) {
+ DependencyTree tree = new DependencyTree()
+ .setDepId(JsonUtils.getString(json, "did"))
+ .setResourceId(JsonUtils.getString(json, "rid"))
+ .setResourceKey(JsonUtils.getString(json, "k"))
+ .setResourceName(JsonUtils.getString(json, "n"))
+ .setResourceScope(JsonUtils.getString(json, "s"))
+ .setResourceQualifier(JsonUtils.getString(json, "q"))
+ .setResourceVersion(JsonUtils.getString(json, "v"))
+ .setUsage(JsonUtils.getString(json, "u"))
+ .setWeight(JsonUtils.getInteger(json, "w"));
+
+ List<DependencyTree> to = new ArrayList<DependencyTree>();
+ tree.setTo(to);
+
+ JSONArray toJson = (JSONArray) json.get("to");
+ if (toJson != null) {
+ for (Object aToJson : toJson) {
+ to.add(parse((JSONObject) aToJson));
+ }
+ }
+ return tree;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshaller.java
new file mode 100644
index 00000000000..803753aede7
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshaller.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Dependency;
+
+public class DependencyUnmarshaller extends AbstractUnmarshaller<Dependency> {
+
+ @Override
+ protected Dependency parse(JSONObject json) {
+ return new Dependency()
+ .setId(JsonUtils.getString(json, "id"))
+ .setFromId(JsonUtils.getLong(json, "fi"))
+ .setToId(JsonUtils.getLong(json, "ti"))
+ .setFromKey(JsonUtils.getString(json, "fk"))
+ .setToKey(JsonUtils.getString(json, "tk"))
+ .setUsage(JsonUtils.getString(json, "u"))
+ .setWeight(JsonUtils.getInteger(json, "w"))
+ .setFromName(JsonUtils.getString(json, "fn"))
+ .setFromQualifier(JsonUtils.getString(json, "fq"))
+ .setToName(JsonUtils.getString(json, "tn"))
+ .setToQualifier(JsonUtils.getString(json, "tq"));
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/EventUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/EventUnmarshaller.java
new file mode 100644
index 00000000000..2f7878e55ef
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/EventUnmarshaller.java
@@ -0,0 +1,38 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Event;
+
+public class EventUnmarshaller extends AbstractUnmarshaller<Event> {
+
+ @Override
+ protected Event parse(JSONObject json) {
+ return new Event()
+ .setId(JsonUtils.getString(json, "id"))
+ .setResourceKey(JsonUtils.getString(json, "rk"))
+ .setName(JsonUtils.getString(json, "n"))
+ .setCategory(JsonUtils.getString(json, "c"))
+ .setDate(JsonUtils.getDateTime(json, "dt"))
+ .setDescription(JsonUtils.getString(json, "ds"))
+ .setData(JsonUtils.getString(json, "data"));
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/FavouriteUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/FavouriteUnmarshaller.java
new file mode 100644
index 00000000000..ab93ef28082
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/FavouriteUnmarshaller.java
@@ -0,0 +1,37 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Favourite;
+
+public class FavouriteUnmarshaller extends AbstractUnmarshaller<Favourite> {
+
+ @Override
+ protected Favourite parse(JSONObject json) {
+ return new Favourite()
+ .setId(JsonUtils.getInteger(json, "id"))
+ .setKey(JsonUtils.getString(json, "key"))
+ .setName(JsonUtils.getString(json, "name"))
+ .setScope(JsonUtils.getString(json, "scope"))
+ .setQualifier(JsonUtils.getString(json, "qualifier"))
+ .setLanguage(JsonUtils.getString(json, "lang"));
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/JsonUtils.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/JsonUtils.java
new file mode 100644
index 00000000000..598812dc7e7
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/JsonUtils.java
@@ -0,0 +1,94 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+
+public final class JsonUtils {
+
+ private JsonUtils() {
+ // only static methods
+ }
+
+ public static String getString(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return (String) value;
+ }
+ return null;
+ }
+
+ public static Integer getInteger(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return ((Long) value).intValue();
+ }
+ return null;
+ }
+
+ public static Boolean getBoolean(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return (Boolean)value;
+ }
+ return null;
+ }
+
+ public static Long getLong(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return (Long) value;
+ }
+ return null;
+ }
+
+ public static Double getDouble(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return (Double) value;
+ }
+ return null;
+ }
+
+ public static Date getDateTime(Map obj, String field) {
+ return parseDate(obj, field, "yyyy-MM-dd'T'HH:mm:ssZ");
+ }
+
+ public static Date getDate(Map obj, String field) {
+ return parseDate(obj, field, "yyyy-MM-dd");
+ }
+
+ private static Date parseDate(Map obj, String field, String format) {
+ String value = getString(obj, field);
+ if (value != null) {
+ try {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(format);
+ return dateFormat.parse(value);
+
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return null;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/MetricUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/MetricUnmarshaller.java
new file mode 100644
index 00000000000..d90101b833d
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/MetricUnmarshaller.java
@@ -0,0 +1,39 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Metric;
+
+public class MetricUnmarshaller extends AbstractUnmarshaller<Metric> {
+
+ @Override
+ protected Metric parse(JSONObject json) {
+ return new Metric()
+ .setKey((String) json.get("key"))
+ .setName((String) json.get("name"))
+ .setDomain((String) json.get("domain"))
+ .setDescription((String) json.get("description"))
+ .setDirection(JsonUtils.getInteger(json, "direction"))
+ .setType(JsonUtils.getString(json, "val_type"))
+ .setUserManaged(JsonUtils.getBoolean(json, "user_managed"))
+ .setHidden(JsonUtils.getBoolean(json, "hidden"));
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshaller.java
new file mode 100644
index 00000000000..cf71b47c32b
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshaller.java
@@ -0,0 +1,33 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Property;
+
+public class PropertyUnmarshaller extends AbstractUnmarshaller<Property> {
+
+ @Override
+ protected Property parse(JSONObject json) {
+ return new Property()
+ .setKey((String) json.get("key"))
+ .setValue((String) json.get("value"));
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshaller.java
new file mode 100644
index 00000000000..87a31147a9f
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshaller.java
@@ -0,0 +1,90 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Measure;
+import org.sonar.wsclient.services.Resource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ResourceUnmarshaller extends AbstractUnmarshaller<Resource> {
+
+ @Override
+ protected Resource parse(JSONObject json) {
+ Resource resource = new Resource();
+ parseResourceFields(json, resource);
+ parseMeasures(json, resource);
+ return resource;
+ }
+
+ private void parseResourceFields(JSONObject json, Resource resource) {
+ resource.setId(JsonUtils.getInteger(json, "id"))
+ .setKey(JsonUtils.getString(json, "key"))
+ .setName(JsonUtils.getString(json, "name"))
+ .setLongName(JsonUtils.getString(json, "lname"))
+ .setScope(JsonUtils.getString(json, "scope"))
+ .setQualifier(JsonUtils.getString(json, "qualifier"))
+ .setLanguage(JsonUtils.getString(json, "lang"))
+ .setDescription(JsonUtils.getString(json, "description"))
+ .setVersion(JsonUtils.getString(json, "version"));
+ }
+
+ private void parseMeasures(JSONObject json, Resource resource) {
+ JSONArray measuresJson = (JSONArray) json.get("msr");
+ if (measuresJson != null) {
+ resource.setMeasures(parseMeasures(measuresJson));
+ }
+ }
+
+ private List<Measure> parseMeasures(JSONArray measuresJson) {
+ List<Measure> projectMeasures = new ArrayList<Measure>();
+ int len = measuresJson.size();
+ for (int i = 0; i < len; i++) {
+ JSONObject measureJson = (JSONObject) measuresJson.get(i);
+ if (measureJson != null) {
+ Measure measure = parseMeasure(measureJson);
+ projectMeasures.add(measure);
+ }
+ }
+ return projectMeasures;
+ }
+
+ private Measure parseMeasure(JSONObject json) {
+ Measure measure = new Measure();
+ measure
+ .setMetricKey(JsonUtils.getString(json, "key"))
+ .setMetricName(JsonUtils.getString(json, "name"))
+ .setValue(JsonUtils.getDouble(json, "val"))
+ .setFormattedValue(JsonUtils.getString(json, "frmt_val"))
+ .setTrend(JsonUtils.getInteger(json, "trend"))
+ .setVar(JsonUtils.getInteger(json, "var"))
+ .setData(JsonUtils.getString(json, "data"))
+ .setRuleKey(JsonUtils.getString(json, "rule_key"))
+ .setRuleName(JsonUtils.getString(json, "rule_name"))
+ .setRuleCategory(JsonUtils.getString(json, "rule_category"))
+ .setRulePriority(JsonUtils.getString(json, "rule_priority"))
+ .setCharacteristicKey(JsonUtils.getString(json, "ctic_key"))
+ .setCharacteristicName(JsonUtils.getString(json, "ctic_name"));
+ return measure;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java
new file mode 100644
index 00000000000..d980876e3f8
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+import org.sonar.wsclient.services.Server;
+
+import java.util.List;
+
+/**
+ * @author Evgeny Mandrikov
+ */
+public class ServerUnmarshaller implements Unmarshaller<Server> {
+ public Server toModel(String json) {
+ JSONObject map = (JSONObject) JSONValue.parse(json);
+ return new Server()
+ .setId(JsonUtils.getString(map, "id"))
+ .setVersion(JsonUtils.getString(map, "version"));
+ }
+
+ public List<Server> toModels(String json) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/SourceUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/SourceUnmarshaller.java
new file mode 100644
index 00000000000..cbda6b4c5d0
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/SourceUnmarshaller.java
@@ -0,0 +1,40 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Source;
+
+import java.util.Map;
+
+public class SourceUnmarshaller extends AbstractUnmarshaller<Source> {
+
+ @Override
+ protected Source parse(JSONObject json) {
+ Source source = new Source();
+
+ for (Object o : json.entrySet()) {
+ Map.Entry<String, String> entry = (Map.Entry<String, String>) o;
+ source.addLine(Integer.parseInt(entry.getKey()), entry.getValue());
+ }
+
+ return source;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshaller.java
new file mode 100644
index 00000000000..bed74add09a
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshaller.java
@@ -0,0 +1,32 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.sonar.wsclient.services.Model;
+
+import java.util.List;
+
+public interface Unmarshaller<MODEL extends Model> {
+
+ MODEL toModel(String json);
+
+ List<MODEL> toModels(String json);
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
new file mode 100644
index 00000000000..3523f1ce836
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
@@ -0,0 +1,50 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.sonar.wsclient.services.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public final class Unmarshallers {
+ private Unmarshallers() {
+ }
+
+ private static Map<Class, Unmarshaller> unmarshallers;
+
+ static {
+ unmarshallers = new HashMap<Class, Unmarshaller>();
+ unmarshallers.put(Metric.class, new MetricUnmarshaller());
+ unmarshallers.put(Dependency.class, new DependencyUnmarshaller());
+ unmarshallers.put(Resource.class, new ResourceUnmarshaller());
+ unmarshallers.put(Property.class, new PropertyUnmarshaller());
+ unmarshallers.put(Source.class, new SourceUnmarshaller());
+ unmarshallers.put(Violation.class, new ViolationUnmarshaller());
+ unmarshallers.put(Server.class, new ServerUnmarshaller());
+ unmarshallers.put(DependencyTree.class, new DependencyTreeUnmarshaller());
+ unmarshallers.put(Event.class, new EventUnmarshaller());
+ unmarshallers.put(Favourite.class, new FavouriteUnmarshaller());
+ }
+
+ public static <MODEL extends Model> Unmarshaller<MODEL> forModel(Class<MODEL> modelClass) {
+ return unmarshallers.get(modelClass);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
new file mode 100644
index 00000000000..ab8a91fa96a
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
@@ -0,0 +1,49 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Violation;
+
+public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
+
+ @Override
+ protected Violation parse(JSONObject json) {
+ Violation violation = new Violation();
+ violation.setMessage(JsonUtils.getString(json, "message"));
+ violation.setLine(JsonUtils.getInteger(json, "line"));
+ violation.setPriority(JsonUtils.getString(json, "priority"));
+
+ JSONObject rule = (JSONObject)json.get("rule");
+ if (rule!=null) {
+ violation.setRuleKey(JsonUtils.getString(rule, "key"));
+ violation.setRuleName(JsonUtils.getString(rule, "name"));
+ }
+
+ JSONObject resource = (JSONObject)json.get("resource");
+ if (resource!=null) {
+ violation.setResourceKey(JsonUtils.getString(resource, "key"));
+ violation.setResourceName(JsonUtils.getString(resource, "name"));
+ violation.setResourceQualifier(JsonUtils.getString(resource, "qualifier"));
+ violation.setResourceScope(JsonUtils.getString(resource, "scope"));
+ }
+ return violation;
+ }
+}