From 74b540c99a26394cc39f363cf27170a49aba8a5b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 14 Apr 2016 13:43:42 +0200 Subject: SONAR-7427 Remove "effort_to_reach_reliability_rating_a" and "effort_to_reach_security_rating_a" from js --- .../sonar-web/src/main/js/apps/component-measures/config/domains.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/component-measures/config/domains.js b/server/sonar-web/src/main/js/apps/component-measures/config/domains.js index 08d97febd27..d7e52100202 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/config/domains.js +++ b/server/sonar-web/src/main/js/apps/component-measures/config/domains.js @@ -24,8 +24,7 @@ export const domains = { 'new_bugs', 'reliability_rating', 'reliability_remediation_effort', - 'new_reliability_remediation_effort', - 'effort_to_reach_reliability_rating_a' + 'new_reliability_remediation_effort' ] }, @@ -35,8 +34,7 @@ export const domains = { 'new_vulnerabilities', 'security_rating', 'security_remediation_effort', - 'new_security_remediation_effort', - 'effort_to_reach_security_rating_a' + 'new_security_remediation_effort' ] }, -- cgit v1.2.3 From e0da0f210c26738ef7c18809a507d46d6eb09610 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 14 Apr 2016 10:50:20 +0200 Subject: Add partial support of api/projects to sonar-ws --- .../org/sonarqube/ws/client/DefaultWsClient.java | 8 +++ .../java/org/sonarqube/ws/client/WsClient.java | 6 ++ .../sonarqube/ws/client/project/CreateRequest.java | 84 ++++++++++++++++++++++ .../sonarqube/ws/client/project/DeleteRequest.java | 73 +++++++++++++++++++ .../ws/client/project/ProjectsService.java | 58 +++++++++++++++ .../sonarqube/ws/client/project/package-info.java | 25 +++++++ .../ws/client/project/ProjectsServiceTest.java | 81 +++++++++++++++++++++ 7 files changed, 335 insertions(+) create mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/project/CreateRequest.java create mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/project/DeleteRequest.java create mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java create mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/project/package-info.java create mode 100644 sonar-ws/src/test/java/org/sonarqube/ws/client/project/ProjectsServiceTest.java 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/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/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 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")); + } +} -- cgit v1.2.3 From 21ce21cce54dbeaa40ee9ff3d57d4256e9e5cc3d Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 14 Apr 2016 10:52:35 +0200 Subject: Add support of WS api/ce/task to sonar-ws --- .../src/main/java/org/sonarqube/ws/client/ce/CeService.java | 13 +++++++++++++ .../test/java/org/sonarqube/ws/client/ce/CeServiceTest.java | 9 +++++++++ 2 files changed, 22 insertions(+) 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/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")); + } } -- cgit v1.2.3 From d19b4f0f976a97c6428c8f5fdf7d2c383bf2e760 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 14 Apr 2016 11:06:49 +0200 Subject: SONAR-7187 Fix perf issue in selectByQuery Replace usage of RowBounds by SQL pagination --- .../main/java/org/sonar/db/ce/CeActivityDao.java | 2 +- .../java/org/sonar/db/ce/CeActivityMapper.java | 2 +- .../resources/org/sonar/db/ce/CeActivityMapper.xml | 28 ++++++++++++++++-- .../java/org/sonar/db/ce/CeActivityDaoTest.java | 33 +++++++++++++++++++++- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java index 050389c8858..e32a1be1535 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java @@ -69,7 +69,7 @@ public class CeActivityDao implements Dao { return Collections.emptyList(); } - return mapper(dbSession).selectByQuery(query, new RowBounds(offset, pageSize)); + return mapper(dbSession).selectByQuery(query, offset, pageSize); } public int countByQuery(DbSession dbSession, CeTaskQuery query) { diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java index a59254827ed..ea4652d4185 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java @@ -33,7 +33,7 @@ public interface CeActivityMapper { List selectByComponentUuid(@Param("componentUuid") String componentUuid); - List selectByQuery(@Param("query") CeTaskQuery query, RowBounds rowBounds); + List selectByQuery(@Param("query") CeTaskQuery query, @Param("offset") int offset, @Param("pageSize") int pageSize); List selectOlderThan(@Param("beforeDate") long beforeDate); diff --git a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml index d86c8f73212..08247b4faa1 100644 --- a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml @@ -4,6 +4,7 @@ + ca.id, ca.uuid, ca.task_type as taskType, ca.component_uuid as componentUuid, @@ -44,10 +45,33 @@ + + + +