diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-15 17:13:50 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-15 17:13:50 +0200 |
commit | 0dbee87afa49c3c5f75f045e1ac5bf1ec171e5b7 (patch) | |
tree | 1ad2a7d2801c79d68020fe58593f31260856672c /sonar-ws-client | |
parent | 566165328097c397e3217d31bff122001700ea85 (diff) | |
download | sonarqube-0dbee87afa49c3c5f75f045e1ac5bf1ec171e5b7.tar.gz sonarqube-0dbee87afa49c3c5f75f045e1ac5bf1ec171e5b7.zip |
SONAR-2412 add support of project deletion from the Java web service client
Diffstat (limited to 'sonar-ws-client')
11 files changed, 96 insertions, 11 deletions
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 index e6a2dc855b6..c19254963c0 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/Sonar.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/Sonar.java @@ -93,7 +93,7 @@ public class Sonar { connector.execute(query); } - public void delete(DeleteQuery<?> query) { + public void delete(DeleteQuery query) { connector.execute(query); } 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 index cf874703859..711aa9726a8 100644 --- 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 @@ -45,7 +45,7 @@ public abstract class Connector { * @return JSON response or null if 404 NOT FOUND error * @since 2.2 */ - public abstract String execute(DeleteQuery<?> query); + public abstract String execute(DeleteQuery query); /** * @return JSON response or null if 404 NOT FOUND error 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 index cb720320d7c..7632eedd000 100644 --- 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 @@ -81,7 +81,7 @@ public class HttpClient3Connector extends Connector { return executeRequest(newPutRequest(query)); } - public String execute(DeleteQuery<?> query) { + public String execute(DeleteQuery query) { return executeRequest(newDeleteRequest(query)); } @@ -117,7 +117,7 @@ public class HttpClient3Connector extends Connector { return method; } - private HttpMethodBase newDeleteRequest(DeleteQuery<?> query) { + private HttpMethodBase newDeleteRequest(DeleteQuery query) { HttpMethodBase method = new DeleteMethod(server.getHost() + query.getUrl()); initRequest(method, query); return method; 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 index e1aebfd175e..cd1a31cb969 100644 --- 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 @@ -82,7 +82,7 @@ public class HttpClient4Connector extends Connector { return executeRequest(newPutMethod(query)); } - public String execute(DeleteQuery<?> query) { + public String execute(DeleteQuery query) { return executeRequest(newDeleteMethod(query)); } @@ -146,7 +146,7 @@ public class HttpClient4Connector extends Connector { return get; } - private HttpDelete newDeleteMethod(DeleteQuery<?> query) { + private HttpDelete newDeleteMethod(DeleteQuery query) { HttpDelete delete = new HttpDelete(server.getHost() + query.getUrl()); initRequest(delete, query); return delete; 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 index 5a3df918436..91249db4ae6 100644 --- 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 @@ -24,6 +24,6 @@ package org.sonar.wsclient.services; * * @since 2.2 */ -public abstract class DeleteQuery<MODEL extends Model> extends AbstractQuery<MODEL> { +public abstract class DeleteQuery extends AbstractQuery { } 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 index 40ac6d21e79..99065b5e3f4 100644 --- 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 @@ -19,7 +19,7 @@ */ package org.sonar.wsclient.services; -public class FavouriteDeleteQuery extends DeleteQuery<Favourite> { +public class FavouriteDeleteQuery extends DeleteQuery { private String idOrKey; diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasureDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasureDeleteQuery.java index 74b3e591136..eb7e50349b2 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasureDeleteQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ManualMeasureDeleteQuery.java @@ -22,7 +22,7 @@ package org.sonar.wsclient.services; /** * @since 2.10 */ -public final class ManualMeasureDeleteQuery extends DeleteQuery<ManualMeasure> { +public final class ManualMeasureDeleteQuery extends DeleteQuery { private String resourceKey; private String metricKey; diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProjectDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProjectDeleteQuery.java new file mode 100644 index 00000000000..47c1127aa9e --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ProjectDeleteQuery.java @@ -0,0 +1,49 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * 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.11 + */ +public final class ProjectDeleteQuery extends DeleteQuery { + + private String key; + private static final String BASE_URL = "/api/projects/"; + + private ProjectDeleteQuery(String key) { + this.key = key; + } + + public String getKey() { + return key; + } + + @Override + public String getUrl() { + StringBuilder url = new StringBuilder(); + url.append(BASE_URL); + url.append(encode(key)); + return url.toString(); + } + + public static ProjectDeleteQuery create(String projectKeyOrId) { + return new ProjectDeleteQuery(projectKeyOrId); + } +} 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 index 8e6b7b119dd..1775bcf2360 100644 --- 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 @@ -22,7 +22,7 @@ package org.sonar.wsclient.services; /** * @since 2.6 */ -public class PropertyDeleteQuery extends DeleteQuery<Property> { +public class PropertyDeleteQuery extends DeleteQuery { private String key; private String resourceKeyOrId; 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 index 81f1e182134..cebcf9f1a8b 100644 --- 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 @@ -22,7 +22,7 @@ package org.sonar.wsclient.services; /** * @since 2.2 */ -public class UserPropertyDeleteQuery extends DeleteQuery<Property> { +public class UserPropertyDeleteQuery extends DeleteQuery { private String key; diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java new file mode 100644 index 00000000000..8957381dd5b --- /dev/null +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java @@ -0,0 +1,36 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * 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 org.sonar.wsclient.Sonar; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class ProjectDeleteQueryTest extends QueryTestCase { + + @Test + public void testUrl() { + ProjectDeleteQuery query = ProjectDeleteQuery.create("my:project"); + assertThat(query.getUrl(), is("/api/projects/my%3Aproject")); + } + +}
\ No newline at end of file |