You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectsService.java 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarqube.ws.client.projects;
  21. import java.util.stream.Collectors;
  22. import javax.annotation.Generated;
  23. import org.sonarqube.ws.MediaTypes;
  24. import org.sonarqube.ws.Projects.CreateWsResponse;
  25. import org.sonarqube.ws.Projects.SearchMyProjectsWsResponse;
  26. import org.sonarqube.ws.Projects.SearchWsResponse;
  27. import org.sonarqube.ws.client.BaseService;
  28. import org.sonarqube.ws.client.GetRequest;
  29. import org.sonarqube.ws.client.PostRequest;
  30. import org.sonarqube.ws.client.WsConnector;
  31. import org.sonarqube.ws.client.WsResponse;
  32. /**
  33. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects">Further information about this web service online</a>
  34. */
  35. @Generated("sonar-ws-generator")
  36. public class ProjectsService extends BaseService {
  37. public ProjectsService(WsConnector wsConnector) {
  38. super(wsConnector, "api/projects");
  39. }
  40. /**
  41. *
  42. * This is part of the internal API.
  43. * This is a POST request.
  44. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/bulk_delete">Further information about this action online (including a response example)</a>
  45. * @since 5.2
  46. */
  47. public void bulkDelete(BulkDeleteRequest request) {
  48. call(
  49. new PostRequest(path("bulk_delete"))
  50. .setParam("analyzedBefore", request.getAnalyzedBefore())
  51. .setParam("onProvisionedOnly", request.getOnProvisionedOnly())
  52. .setParam("projects", request.getProjects() == null ? null : request.getProjects().stream().collect(Collectors.joining(",")))
  53. .setParam("q", request.getQ())
  54. .setParam("qualifiers", request.getQualifiers() == null ? null : request.getQualifiers().stream().collect(Collectors.joining(",")))
  55. .setParam("visibility", request.getVisibility())
  56. .setMediaType(MediaTypes.JSON)
  57. ).content();
  58. }
  59. /**
  60. *
  61. * This is part of the internal API.
  62. * This is a POST request.
  63. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/create">Further information about this action online (including a response example)</a>
  64. * @since 4.0
  65. */
  66. public CreateWsResponse create(CreateRequest request) {
  67. return call(
  68. new PostRequest(path("create"))
  69. .setParam("mainBranch", request.getMainBranch())
  70. .setParam("name", request.getName())
  71. .setParam("project", request.getProject())
  72. .setParam("visibility", request.getVisibility()),
  73. CreateWsResponse.parser());
  74. }
  75. /**
  76. *
  77. * This is part of the internal API.
  78. * This is a POST request.
  79. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/delete">Further information about this action online (including a response example)</a>
  80. * @since 5.2
  81. */
  82. public void delete(DeleteRequest request) {
  83. call(
  84. new PostRequest(path("delete"))
  85. .setParam("project", request.getProject())
  86. .setMediaType(MediaTypes.JSON)
  87. ).content();
  88. }
  89. /**
  90. *
  91. * This is part of the internal API.
  92. * This is a GET request.
  93. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/license_usage">Further information about this action online (including a response example)</a>
  94. * @since 9.4
  95. */
  96. public WsResponse licenseUsage() {
  97. GetRequest getRequest = new GetRequest(path("license_usage"))
  98. .setMediaType(MediaTypes.JSON);
  99. return call(getRequest);
  100. }
  101. /**
  102. *
  103. * This is part of the internal API.
  104. * This is a GET request.
  105. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/search">Further information about this action online (including a response example)</a>
  106. * @since 6.3
  107. */
  108. public SearchWsResponse search(SearchRequest request) {
  109. return call(
  110. new GetRequest(path("search"))
  111. .setParam("analyzedBefore", request.getAnalyzedBefore())
  112. .setParam("onProvisionedOnly", request.getOnProvisionedOnly())
  113. .setParam("p", request.getP())
  114. .setParam("projects", request.getProjects() == null ? null : request.getProjects().stream().collect(Collectors.joining(",")))
  115. .setParam("ps", request.getPs())
  116. .setParam("q", request.getQ())
  117. .setParam("qualifiers", request.getQualifiers() == null ? null : request.getQualifiers().stream().collect(Collectors.joining(",")))
  118. .setParam("visibility", request.getVisibility()),
  119. SearchWsResponse.parser());
  120. }
  121. /**
  122. *
  123. * This is a GET request.
  124. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/export_findings">Further information about this action online (including a response example)</a>
  125. * @since 9.1
  126. */
  127. public WsResponse exportFindings(ExportFindingsRequest request) {
  128. GetRequest getRequest = new GetRequest(path("export_findings"))
  129. .setParam("project", request.getProjectKey());
  130. if (request.getBranchKey() != null) {
  131. getRequest.setParam("branch", request.getBranchKey());
  132. }
  133. return call(getRequest);
  134. }
  135. /**
  136. *
  137. * This is part of the internal API.
  138. * This is a GET request.
  139. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/search_my_projects">Further information about this action online (including a response example)</a>
  140. * @since 6.0
  141. */
  142. public SearchMyProjectsWsResponse searchMyProjects(SearchMyProjectsRequest request) {
  143. return call(
  144. new GetRequest(path("search_my_projects"))
  145. .setParam("p", request.getP())
  146. .setParam("ps", request.getPs()),
  147. SearchMyProjectsWsResponse.parser());
  148. }
  149. /**
  150. *
  151. * This is part of the internal API.
  152. * This is a POST request.
  153. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/update_key">Further information about this action online (including a response example)</a>
  154. * @since 6.1
  155. */
  156. public void updateKey(UpdateKeyRequest request) {
  157. call(
  158. new PostRequest(path("update_key"))
  159. .setParam("from", request.getFrom())
  160. .setParam("to", request.getTo())
  161. .setMediaType(MediaTypes.JSON)
  162. ).content();
  163. }
  164. /**
  165. *
  166. * This is part of the internal API.
  167. * This is a POST request.
  168. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/update_visibility">Further information about this action online (including a response example)</a>
  169. * @since 6.4
  170. */
  171. public void updateVisibility(UpdateVisibilityRequest request) {
  172. call(
  173. new PostRequest(path("update_visibility"))
  174. .setParam("project", request.getProject())
  175. .setParam("visibility", request.getVisibility())
  176. .setMediaType(MediaTypes.JSON)
  177. ).content();
  178. }
  179. /**
  180. *
  181. * This is part of the internal API.
  182. * This is a POST request.
  183. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/update_default_visibility">Further information about this action online (including a response example)</a>
  184. * @since 6.4
  185. */
  186. public void updateDefaultVisibility(UpdateDefaultVisibilityRequest request) {
  187. call(
  188. new PostRequest(path("update_default_visibility"))
  189. .setParam("projectVisibility", request.getProjectVisibility())
  190. .setMediaType(MediaTypes.JSON)
  191. ).content();
  192. }
  193. }