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;
private final SystemService systemService;
private final CeService ceService;
private final RulesService rulesService;
+ private final ProjectsService projectsService;
DefaultWsClient(WsConnector wsConnector) {
this.wsConnector = wsConnector;
this.systemService = new SystemService(wsConnector);
this.ceService = new CeService(wsConnector);
this.rulesService = new RulesService(wsConnector);
+ this.projectsService = new ProjectsService(wsConnector);
}
@Override
public RulesService rules() {
return rulesService;
}
+
+ @Override
+ public ProjectsService projects() {
+ return projectsService;
+ }
}
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;
RulesService rules();
WsConnector wsConnector();
+
+ /**
+ * @since 5.5
+ */
+ ProjectsService projects();
}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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()));
+ }
+}
--- /dev/null
+/*
+ * 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;
+
--- /dev/null
+/*
+ * 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"));
+ }
+}