aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorJulien HENRY <henryju@yahoo.fr>2011-01-19 02:44:34 +0800
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-01-20 05:24:23 +0800
commit1fbdcfbd155563691ded8f80d4fe2d03f754c897 (patch)
treefda45b0a815197a5882aaded09670b6726be6368 /sonar-ws-client
parent94c86319caf6c3a1fd3d6c617f8f702b5c0c4fcb (diff)
downloadsonarqube-1fbdcfbd155563691ded8f80d4fe2d03f754c897.tar.gz
sonarqube-1fbdcfbd155563691ded8f80d4fe2d03f754c897.zip
SONAR-1664: Add access to project settings/properties
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java101
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java70
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java22
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java100
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java42
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java40
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java6
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java2
8 files changed, 379 insertions, 4 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java
new file mode 100644
index 00000000000..d1d2921d10c
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java
@@ -0,0 +1,101 @@
+/*
+ * 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.6
+ */
+public class PropertyCreateQuery extends CreateQuery<Property> {
+
+ private String key;
+ private String value;
+ private String resourceKeyOrId;
+
+ public PropertyCreateQuery() {
+ }
+
+ public PropertyCreateQuery(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public PropertyCreateQuery(String key, String value, String resourceKeyOrId) {
+ this.key = key;
+ this.value = value;
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public PropertyCreateQuery(Property property) {
+ this.key = property.getKey();
+ this.value = property.getValue();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public PropertyCreateQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public PropertyCreateQuery setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public PropertyCreateQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder();
+ url.append(PropertyQuery.BASE_URL);
+ url.append("/").append(key);
+ url.append('?');
+ appendUrlParameter(url, "value", value);
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ return url.toString();
+ }
+
+ /**
+ * Property value is transmitted through request body as content may
+ * exceed URL size allowed by the server.
+ */
+ @Override
+ public String getBody() {
+ return value;
+ }
+
+ @Override
+ public Class<Property> getModelClass() {
+ return Property.class;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java
new file mode 100644
index 00000000000..07c6a193f10
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java
@@ -0,0 +1,70 @@
+/*
+ * 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.6
+ */
+public class PropertyDeleteQuery extends DeleteQuery<Property> {
+
+ private String key;
+ private String resourceKeyOrId;
+
+ public PropertyDeleteQuery(String key) {
+ this.key = key;
+ }
+
+ public PropertyDeleteQuery(String key, String resourceKeyOrId) {
+ this.key = key;
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public PropertyDeleteQuery(Property property) {
+ this.key = property.getKey();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public PropertyDeleteQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public PropertyDeleteQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder();
+ url.append(PropertyQuery.BASE_URL);
+ url.append("/").append(key);
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ return url.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
index 1e005cac291..8fa3a95ea9d 100644
--- 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
@@ -23,6 +23,7 @@ public class PropertyQuery extends Query<Property> {
public static final String BASE_URL = "/api/properties";
private String key = null;
+ private String resourceKeyOrId = null;
public String getKey() {
return key;
@@ -33,13 +34,24 @@ public class PropertyQuery extends Query<Property> {
return this;
}
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public PropertyQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
@Override
public String getUrl() {
- String url = BASE_URL;
+ StringBuilder url = new StringBuilder(BASE_URL);
if (key != null) {
- url += "/" + key;
+ url.append("/").append(key);
}
- return url + "?";
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ return url.toString();
}
@Override
@@ -54,4 +66,8 @@ public class PropertyQuery extends Query<Property> {
public static PropertyQuery createForKey(String key) {
return new PropertyQuery().setKey(key);
}
+
+ public static PropertyQuery createForResource(String key, String resourceKeyOrId) {
+ return new PropertyQuery().setKey(key).setResourceKeyOrId(resourceKeyOrId);
+ }
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java
new file mode 100644
index 00000000000..f66583fbe9f
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java
@@ -0,0 +1,100 @@
+/*
+ * 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.6
+ */
+public class PropertyUpdateQuery extends UpdateQuery<Property> {
+
+ private String key;
+ private String value;
+ private String resourceKeyOrId;
+
+ public PropertyUpdateQuery() {
+ }
+
+ public PropertyUpdateQuery(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public PropertyUpdateQuery(String key, String value, String resourceKeyOrId) {
+ this.key = key;
+ this.value = value;
+ this.resourceKeyOrId = resourceKeyOrId;
+ }
+
+ public PropertyUpdateQuery(Property property) {
+ this.key = property.getKey();
+ this.value = property.getValue();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public PropertyUpdateQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public PropertyUpdateQuery setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+ public String getResourceKeyOrId() {
+ return resourceKeyOrId;
+ }
+
+ public PropertyUpdateQuery setResourceKeyOrId(String resourceKeyOrId) {
+ this.resourceKeyOrId = resourceKeyOrId;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder();
+ url.append(PropertyQuery.BASE_URL);
+ url.append("/").append(key);
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
+ return url.toString();
+ }
+
+ /**
+ * Property value is transmitted through request body as content may
+ * exceed URL size allowed by the server.
+ */
+ @Override
+ public String getBody() {
+ return value;
+ }
+
+ @Override
+ public Class<Property> getModelClass() {
+ return Property.class;
+ }
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java
new file mode 100644
index 00000000000..c465af21b5e
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.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.services;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class PropertyCreateQueryTest {
+
+ @Test
+ public void create() {
+ PropertyCreateQuery query = new PropertyCreateQuery("foo", "bar");
+ assertThat(query.getUrl(), is("/api/properties/foo?value=bar&"));
+ assertThat(query.getModelClass().getName(), is(Property.class.getName()));
+ }
+
+ @Test
+ public void createForResource() {
+ PropertyCreateQuery query = new PropertyCreateQuery("foo", "bar", "my:resource");
+ assertThat(query.getUrl(), is("/api/properties/foo?value=bar&resource=my:resource&"));
+ assertThat(query.getModelClass().getName(), is(Property.class.getName()));
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java
new file mode 100644
index 00000000000..d55babe0831
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.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.services;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class PropertyDeleteQueryTest {
+
+ @Test
+ public void delete() {
+ PropertyDeleteQuery query = new PropertyDeleteQuery("foo");
+ assertThat(query.getUrl(), is("/api/properties/foo?"));
+ }
+
+ @Test
+ public void deleteResourceProp() {
+ PropertyDeleteQuery query = new PropertyDeleteQuery("foo", "my:resource");
+ assertThat(query.getUrl(), is("/api/properties/foo?resource=my:resource&"));
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
index 8becf06df5a..66e6f6e3b29 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
@@ -37,4 +37,10 @@ public class PropertyQueryTest {
assertThat(PropertyQuery.createForKey("myprop").getUrl(), is("/api/properties/myprop?"));
assertThat(PropertyQuery.createForKey("myprop").getModelClass().getName(), is(Property.class.getName()));
}
+
+ @Test
+ public void byKeyAndResource() {
+ assertThat(PropertyQuery.createForResource("myprop", "my:resource").getUrl(), is("/api/properties/myprop?resource=my:resource&"));
+ assertThat(PropertyQuery.createForResource("myprop", "my:resource").getModelClass().getName(), is(Property.class.getName()));
+ }
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
index 3d4b5df474b..f29462123d6 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertThat;
public class UserPropertyDeleteQueryTest {
@Test
- public void create() {
+ public void delete() {
UserPropertyDeleteQuery query = new UserPropertyDeleteQuery("foo");
assertThat(query.getUrl(), is("/api/user_properties/foo"));
}