aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorJenkins CI <ci@sonarsource.com>2016-04-14 22:26:08 +0200
committerJenkins CI <ci@sonarsource.com>2016-04-14 22:26:08 +0200
commit8a49482fc8b942ea75ddab4fee58d75a5c6eee9a (patch)
treeef347ae401089ec4c09f21287c7e605a21058634 /sonar-ws
parentbf79ed11bd311395aaf01a0d17f72a835ef0d7fb (diff)
parentec0c9c265fed27964480ce51edc8a191b5234be7 (diff)
downloadsonarqube-8a49482fc8b942ea75ddab4fee58d75a5c6eee9a.tar.gz
sonarqube-8a49482fc8b942ea75ddab4fee58d75a5c6eee9a.zip
Automatic merge from branch-5.5
* origin/branch-5.5: SONAR-7429 defaults of HTTPS proxy are values of HTTP proxy Add context when failing to map a db measure to a ws measure SONAR-7187 Fix perf issue in selectByQuery Add support of WS api/ce/task to sonar-ws Add partial support of api/projects to sonar-ws SONAR-7427 Remove "effort_to_reach_reliability_rating_a" and "effort_to_reach_security_rating_a" from js
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java8
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java6
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java13
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/project/CreateRequest.java84
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/project/DeleteRequest.java73
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java58
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/project/package-info.java25
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java9
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/project/ProjectsServiceTest.java81
9 files changed, 357 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
index 1c0d8278ee9..110c8d0377a 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
@@ -24,6 +24,7 @@ import org.sonarqube.ws.client.component.ComponentsService;
import org.sonarqube.ws.client.issue.IssuesService;
import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.permission.PermissionsService;
+import org.sonarqube.ws.client.project.ProjectsService;
import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
import org.sonarqube.ws.client.rule.RulesService;
@@ -49,6 +50,7 @@ class DefaultWsClient implements WsClient {
private final SystemService systemService;
private final CeService ceService;
private final RulesService rulesService;
+ private final ProjectsService projectsService;
DefaultWsClient(WsConnector wsConnector) {
this.wsConnector = wsConnector;
@@ -62,6 +64,7 @@ class DefaultWsClient implements WsClient {
this.systemService = new SystemService(wsConnector);
this.ceService = new CeService(wsConnector);
this.rulesService = new RulesService(wsConnector);
+ this.projectsService = new ProjectsService(wsConnector);
}
@Override
@@ -118,4 +121,9 @@ class DefaultWsClient implements WsClient {
public RulesService rules() {
return rulesService;
}
+
+ @Override
+ public ProjectsService projects() {
+ return projectsService;
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
index fc79d58e695..36369c45e5c 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
@@ -24,6 +24,7 @@ import org.sonarqube.ws.client.component.ComponentsService;
import org.sonarqube.ws.client.issue.IssuesService;
import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.permission.PermissionsService;
+import org.sonarqube.ws.client.project.ProjectsService;
import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
import org.sonarqube.ws.client.rule.RulesService;
@@ -70,4 +71,9 @@ public interface WsClient {
RulesService rules();
WsConnector wsConnector();
+
+ /**
+ * @since 5.5
+ */
+ ProjectsService projects();
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
index a05d383c67d..1871cd800d9 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
@@ -20,6 +20,7 @@
package org.sonarqube.ws.client.ce;
+import org.sonarqube.ws.WsCe;
import org.sonarqube.ws.WsCe.ActivityResponse;
import org.sonarqube.ws.WsCe.TaskTypesWsResponse;
import org.sonarqube.ws.client.BaseService;
@@ -33,6 +34,9 @@ import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_ONLY_CURRENTS;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_STATUS;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_TYPE;
+/**
+ * Maps web service {@code api/ce} (Compute Engine).
+ */
public class CeService extends BaseService {
public CeService(WsConnector wsConnector) {
@@ -58,4 +62,13 @@ public class CeService extends BaseService {
return call(new GetRequest(path("task_types")), TaskTypesWsResponse.parser());
}
+ /**
+ * Gets details of a Compute Engine task.
+ *
+ * @throws org.sonarqube.ws.client.HttpException if HTTP status code is not 2xx.
+ * @since 5.5
+ */
+ public WsCe.TaskResponse task(String id) {
+ return call(new GetRequest(path("task")).setParam("id", id), WsCe.TaskResponse.parser());
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/project/CreateRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/CreateRequest.java
new file mode 100644
index 00000000000..698d7666904
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/CreateRequest.java
@@ -0,0 +1,84 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarqube.ws.client.project;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+/**
+ * @since 5.5
+ */
+public class CreateRequest {
+
+ private final String key;
+ private final String name;
+ private final String branch;
+
+ private CreateRequest(Builder builder) {
+ this.key = builder.key;
+ this.name = builder.name;
+ this.branch = builder.branch;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @CheckForNull
+ public String getBranch() {
+ return branch;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String key;
+ private String name;
+ private String branch;
+
+ private Builder() {
+ }
+
+ public Builder setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public Builder setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder setBranch(@Nullable String branch) {
+ this.branch = branch;
+ return this;
+ }
+
+ public CreateRequest build() {
+ return new CreateRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/project/DeleteRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/DeleteRequest.java
new file mode 100644
index 00000000000..5a0df28686a
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/DeleteRequest.java
@@ -0,0 +1,73 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarqube.ws.client.project;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+/**
+ * @since 5.5
+ */
+public class DeleteRequest {
+
+ private final String id;
+ private final String key;
+
+ private DeleteRequest(Builder builder) {
+ this.id = builder.id;
+ this.key = builder.key;
+ }
+
+ @CheckForNull
+ public String getKey() {
+ return key;
+ }
+
+ @CheckForNull
+ public String getId() {
+ return id;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String id;
+ private String key;
+
+ private Builder() {
+ }
+
+ public Builder setId(@Nullable String id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder setKey(@Nullable String key) {
+ this.key = key;
+ return this;
+ }
+
+ public DeleteRequest build() {
+ return new DeleteRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java
new file mode 100644
index 00000000000..2eb5ae1af0b
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonarqube.ws.client.project;
+
+import org.sonarqube.ws.client.BaseService;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.WsConnector;
+
+/**
+ * Maps web service {@code api/projects}.
+ * @since 5.5
+ */
+public class ProjectsService extends BaseService {
+
+ public ProjectsService(WsConnector wsConnector) {
+ super(wsConnector, "api/projects");
+ }
+
+ /**
+ * Provisions a new project.
+ *
+ * @throws org.sonarqube.ws.client.HttpException if HTTP status code is not 2xx.
+ */
+ public void create(CreateRequest project) {
+ PostRequest request = new PostRequest(path("create"))
+ .setParam("key", project.getKey())
+ .setParam("name", project.getName())
+ .setParam("branch", project.getBranch());
+ call(request);
+ }
+
+ /**
+ * @throws org.sonarqube.ws.client.HttpException if HTTP status code is not 2xx.
+ */
+ public void delete(DeleteRequest request) {
+ call(new PostRequest(path("delete"))
+ .setParam("id", request.getId())
+ .setParam("key", request.getKey()));
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/project/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/package-info.java
new file mode 100644
index 00000000000..041d5d4da2f
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonarqube.ws.client.project;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
index 1125072b933..51cc5293bc6 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
@@ -30,6 +30,7 @@ import org.sonarqube.ws.client.ServiceTester;
import org.sonarqube.ws.client.WsConnector;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.data.MapEntry.entry;
import static org.mockito.Mockito.mock;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MAX_EXECUTED_AT;
@@ -94,4 +95,12 @@ public class CeServiceTest {
assertThat(serviceTester.getGetParser()).isSameAs(WsCe.TaskTypesWsResponse.parser());
}
+
+ @Test
+ public void task() {
+ underTest.task("task_id");
+
+ assertThat(serviceTester.getGetRequest().getPath()).isEqualTo("api/ce/task");
+ assertThat(serviceTester.getGetRequest().getParams()).containsOnly(entry("id", "task_id"));
+ }
}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/project/ProjectsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/project/ProjectsServiceTest.java
new file mode 100644
index 00000000000..ccb720b00fd
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/project/ProjectsServiceTest.java
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarqube.ws.client.project;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.data.MapEntry.entry;
+import static org.mockito.Mockito.mock;
+
+public class ProjectsServiceTest {
+
+ @Rule
+ public ServiceTester<ProjectsService> serviceTester = new ServiceTester<>(new ProjectsService(mock(WsConnector.class)));
+
+ private ProjectsService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void creates_project() {
+ underTest.create(CreateRequest.builder()
+ .setKey("project_key")
+ .setName("Project Name")
+ .build());
+
+ assertThat(serviceTester.getPostRequest().getPath()).isEqualTo("api/projects/create");
+ assertThat(serviceTester.getPostRequest().getParams()).containsOnly(
+ entry("key", "project_key"),
+ entry("name", "Project Name"));
+ }
+
+ @Test
+ public void creates_project_on_branch() {
+ underTest.create(CreateRequest.builder()
+ .setKey("project_key")
+ .setName("Project Name")
+ .setBranch("the_branch")
+ .build());
+
+ assertThat(serviceTester.getPostRequest().getPath()).isEqualTo("api/projects/create");
+ assertThat(serviceTester.getPostRequest().getParams()).containsOnly(
+ entry("key", "project_key"),
+ entry("name", "Project Name"),
+ entry("branch", "the_branch"));
+ }
+
+ @Test
+ public void deletes_project_by_id() {
+ underTest.delete(DeleteRequest.builder().setId("abc").build());
+
+ assertThat(serviceTester.getPostRequest().getPath()).isEqualTo("api/projects/delete");
+ assertThat(serviceTester.getPostRequest().getParams()).containsOnly(entry("id", "abc"));
+ }
+
+ @Test
+ public void deletes_project_by_key() {
+ underTest.delete(DeleteRequest.builder().setKey("project_key").build());
+
+ assertThat(serviceTester.getPostRequest().getPath()).isEqualTo("api/projects/delete");
+ assertThat(serviceTester.getPostRequest().getParams()).containsOnly(entry("key", "project_key"));
+ }
+}