From 12bfa39dec602d97178c9c9967bb2a367dc2c5fc Mon Sep 17 00:00:00 2001 From: Jacek <52388493+jacek-poreda-sonarsource@users.noreply.github.com> Date: Mon, 22 Jul 2019 17:17:18 +0200 Subject: [PATCH] SONAR-8776 remove deprecated params, fields from api/components (#1894) * remove componentId, uuid params and associated documentation * remove deprecated params from api/components/search_projects * remove deprecated params from api/components/show * remove request parameters: key, componentId, id * remove deprecated params from api/components/suggestions * remove deprecated params from api/components/tree * remove deprecated request parameters: baseComponentKey, componentId, baseComponentId * remove `id` field response from api/components/search, api/components/search_projects * fix description in api/components/show --- .../sonar/server/component/ws/AppAction.java | 42 +++---- .../ws/ComponentDtoToWsComponent.java | 1 - .../server/component/ws/SearchAction.java | 6 +- .../component/ws/SearchProjectsAction.java | 11 +- .../sonar/server/component/ws/ShowAction.java | 61 ++-------- .../component/ws/SuggestionsAction.java | 3 +- .../sonar/server/component/ws/TreeAction.java | 51 +-------- .../ws/search-components-example.json | 3 - .../component/ws/search_projects-example.json | 3 - .../server/component/ws/show-example.json | 3 - .../server/component/ws/tree-example.json | 10 +- .../server/component/ws/AppActionTest.java | 92 ++++++++++++--- .../server/component/ws/SearchActionTest.java | 7 +- .../ws/SearchProjectsActionTest.java | 12 +- .../server/component/ws/ShowActionTest.java | 106 ++++------------- .../component/ws/SuggestionsActionTest.java | 3 +- .../server/component/ws/TreeActionTest.java | 107 +++++++----------- .../server/issue/ws/SearchActionTest.java | 2 +- .../org/sonar/api/server/ws/WebService.java | 1 - .../component/ComponentsWsParameters.java | 1 - .../src/main/protobuf/ws-components.proto | 1 - 21 files changed, 197 insertions(+), 329 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java index e103e19e1b9..d761a1cd9af 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java @@ -31,9 +31,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.user.UserSession; -import static com.google.common.base.Preconditions.checkArgument; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; -import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST; import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; @@ -41,8 +38,7 @@ import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; public class AppAction implements ComponentsWsAction { - private static final String PARAM_COMPONENT_ID = "componentId"; - private static final String PARAM_COMPONENT = "component"; + static final String PARAM_COMPONENT = "component"; private final DbClient dbClient; @@ -61,6 +57,7 @@ public class AppAction implements ComponentsWsAction { public void define(WebService.NewController controller) { WebService.NewAction action = controller.createAction("app") .setDescription("Coverage data required for rendering the component viewer.
" + + "Either branch or pull request can be provided, not both
" + "Requires the following permission: 'Browse'.") .setResponseExample(getClass().getResource("app-example.json")) .setSince("4.4") @@ -68,16 +65,10 @@ public class AppAction implements ComponentsWsAction { .setInternal(true) .setHandler(this); - action - .createParam(PARAM_COMPONENT_ID) - .setDescription("Component ID") - .setDeprecatedSince("6.4") - .setDeprecatedKey("uuid", "6.4") - .setExampleValue(UUID_EXAMPLE_01); - action.createParam(PARAM_COMPONENT) .setDescription("Component key") .setExampleValue(KEY_PROJECT_EXAMPLE_001) + .setRequired(true) .setSince("6.4"); action.createParam(PARAM_BRANCH) @@ -98,27 +89,26 @@ public class AppAction implements ComponentsWsAction { try (DbSession session = dbClient.openSession(false)) { ComponentDto component = loadComponent(session, request); userSession.checkComponentPermission(UserRole.USER, component); - - JsonWriter json = response.newJsonWriter(); - json.beginObject(); - componentViewerJsonWriter.writeComponent(json, component, userSession, session); - appendPermissions(json, userSession); - componentViewerJsonWriter.writeMeasures(json, component, session); - json.endObject(); - json.close(); + writeJsonResponse(response, session, component); } } private ComponentDto loadComponent(DbSession dbSession, Request request) { - String componentUuid = request.param(PARAM_COMPONENT_ID); String branch = request.param(PARAM_BRANCH); String pullRequest = request.param(PARAM_PULL_REQUEST); - checkArgument(componentUuid == null || (branch == null && pullRequest == null), "Parameter '%s' cannot be used at the same time as '%s' or '%s'", PARAM_COMPONENT_ID, - PARAM_BRANCH, PARAM_PULL_REQUEST); - if (branch == null && pullRequest == null) { - return componentFinder.getByUuidOrKey(dbSession, componentUuid, request.param(PARAM_COMPONENT), COMPONENT_ID_AND_COMPONENT); + String componentKey = request.mandatoryParam(PARAM_COMPONENT); + + return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest); + } + + private void writeJsonResponse(Response response, DbSession session, ComponentDto component) { + try (JsonWriter json = response.newJsonWriter()) { + json.beginObject(); + componentViewerJsonWriter.writeComponent(json, component, userSession, session); + appendPermissions(json, userSession); + componentViewerJsonWriter.writeMeasures(json, component, session); + json.endObject(); } - return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, request.mandatoryParam(PARAM_COMPONENT), branch, pullRequest); } private static void appendPermissions(JsonWriter json, UserSession userSession) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java index 6f83c3c7441..df6d5fe1f86 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java @@ -57,7 +57,6 @@ class ComponentDtoToWsComponent { private static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, String organizationDtoKey, Optional lastAnalysis) { Components.Component.Builder wsComponent = Components.Component.newBuilder() .setOrganization(organizationDtoKey) - .setId(dto.uuid()) .setKey(dto.getKey()) .setName(dto.name()) .setQualifier(dto.qualifier()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java index 25217de313b..f695b3e1472 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java @@ -88,7 +88,10 @@ public class SearchAction implements ComponentsWsAction { .setSince("6.3") .setDescription("Search for components") .addPagingParams(100, MAX_LIMIT) - .setChangelog(new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS))) + .setChangelog( + new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS)), + new Change("8.0", "Field 'id' from response has been removed") + ) .setResponseExample(getClass().getResource("search-components-example.json")) .setHandler(this); @@ -198,7 +201,6 @@ public class SearchAction implements ComponentsWsAction { Components.Component.Builder builder = Components.Component.newBuilder() .setOrganization(organization.getKey()) - .setId(dto.uuid()) .setKey(dto.getDbKey()) .setProject(projectKey) .setName(dto.name()) diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 3091a1780c2..72491ccf7c7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -89,6 +89,7 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH_PROJECTS; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES; import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS; @@ -121,13 +122,10 @@ public class SearchProjectsAction implements ComponentsWsAction { .setDescription("Search for projects") .addPagingParams(DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE) .setInternal(true) - .setResponseExample(getClass().getResource("search_projects-example.json")) .setChangelog( - new Change("6.4", format("The '%s' parameter accepts '%s' to filter by language", FILTER_LANGUAGES, PARAM_FILTER)), - new Change("6.4", "The 'visibility' field is added"), - new Change("6.5", "The 'filter' parameter now allows 'NO_DATA' as value for numeric metrics"), - new Change("6.5", "Added the option 'analysisDate' for the 'sort' parameter"), - new Change("6.5", format("Value '%s' is added to parameter '%s'", LEAK_PERIOD_DATE, FIELDS))) + new Change("8.0", "Field 'id' from response has been removed") + ) + .setResponseExample(getClass().getResource("search_projects-example.json")) .setHandler(this); action.createFieldsParam(POSSIBLE_FIELDS) @@ -456,7 +454,6 @@ public class SearchProjectsAction implements ComponentsWsAction { wsComponent .clear() .setOrganization(organizationDto.getKey()) - .setId(dbComponent.uuid()) .setKey(dbComponent.getDbKey()) .setName(dbComponent.name()) .setVisibility(Visibility.getLabel(dbComponent.isPrivate())); diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java index 5fa70c2056a..47b4710e511 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java @@ -37,21 +37,15 @@ import org.sonar.server.component.ComponentFinder; import org.sonar.server.user.UserSession; import org.sonarqube.ws.Components.ShowWsResponse; -import static com.google.common.base.Preconditions.checkArgument; -import static java.lang.String.format; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; -import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT; import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST; import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SHOW; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID; public class ShowAction implements ComponentsWsAction { private final UserSession userSession; @@ -67,32 +61,18 @@ public class ShowAction implements ComponentsWsAction { @Override public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_SHOW) - .setDescription(format("Returns a component (file, directory, project, view…) and its ancestors. " + + .setDescription("Returns a component (file, directory, project, portfolio…) and its ancestors. " + "The ancestors are ordered from the parent to the root project. " + - "The '%s' or '%s' parameter must be provided.
" + - "Requires the following permission: 'Browse' on the project of the specified component.", - PARAM_COMPONENT_ID, PARAM_COMPONENT)) + "Requires the following permission: 'Browse' on the project of the specified component.") .setResponseExample(getClass().getResource("show-example.json")) .setSince("5.4") .setChangelog( - new Change("6.4", "Analysis date has been added to the response"), - new Change("6.4", "The field 'id' is deprecated in the response"), - new Change("6.4", "The 'visibility' field is added to the response"), - new Change("6.5", "Leak period date is added to the response"), - new Change("6.6", "'branch' is added to the response"), - new Change("6.6", "'version' is added to the response"), new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT))) .setHandler(this); - action.createParam(PARAM_COMPONENT_ID) - .setDescription("Component id") - .setDeprecatedKey("id", "6.4") - .setDeprecatedSince("6.4") - .setExampleValue(UUID_EXAMPLE_01); - action.createParam(PARAM_COMPONENT) .setDescription("Component key") - .setDeprecatedKey("key", "6.4") + .setRequired(true) .setExampleValue(KEY_PROJECT_EXAMPLE_001); action.createParam(PARAM_BRANCH) @@ -128,16 +108,10 @@ public class ShowAction implements ComponentsWsAction { } private ComponentDto loadComponent(DbSession dbSession, Request request) { - String componentId = request.getId(); - String componentKey = request.getKey(); + String componentKey = request.getComponentKey(); String branch = request.getBranch(); String pullRequest = request.getPullRequest(); - checkArgument(componentId == null || (branch == null && pullRequest == null), "Parameter '%s' cannot be used at the same time as '%s' or '%s'", PARAM_COMPONENT_ID, - PARAM_BRANCH, PARAM_PULL_REQUEST); - if (branch == null && pullRequest == null) { - return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_COMPONENT); - } - checkRequest(componentKey != null, "The '%s' parameter is missing", PARAM_COMPONENT); + return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest); } @@ -154,35 +128,22 @@ public class ShowAction implements ComponentsWsAction { private static Request toShowWsRequest(org.sonar.api.server.ws.Request request) { return new Request() - .setId(request.param(PARAM_COMPONENT_ID)) - .setKey(request.param(PARAM_COMPONENT)) + .setComponentKey(request.mandatoryParam(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)); } private static class Request { - private String id; - private String key; + private String componentKey; private String branch; private String pullRequest; - @CheckForNull - public String getId() { - return id; - } - - public Request setId(@Nullable String id) { - this.id = id; - return this; - } - - @CheckForNull - public String getKey() { - return key; + public String getComponentKey() { + return componentKey; } - public Request setKey(@Nullable String key) { - this.key = key; + public Request setComponentKey(String componentKey) { + this.componentKey = componentKey; return this; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java index c7f8dbbddd5..372f3284159 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java @@ -119,8 +119,7 @@ public class SuggestionsAction implements ComponentsWsAction { .setHandler(this) .setResponseExample(Resources.getResource(this.getClass(), "suggestions-example.json")) .setChangelog( - new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_MORE)), - new Change("6.4", "Parameter 's' is optional")); + new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_MORE))); action.createParam(PARAM_QUERY) .setRequired(false) diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java index 7102a79d933..b5d14616f04 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java @@ -53,28 +53,23 @@ import org.sonar.server.user.UserSession; import org.sonarqube.ws.Components; import org.sonarqube.ws.Components.TreeWsResponse; -import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.CASE_INSENSITIVE_ORDER; import static java.lang.String.format; import static java.util.Collections.emptyMap; import static org.sonar.api.utils.Paging.offset; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; import static org.sonar.core.util.stream.MoreCollectors.toList; import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN; import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES; -import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT; import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent; import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; -import static org.sonar.server.ws.WsUtils.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PULL_REQUEST; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY; @@ -113,28 +108,21 @@ public class TreeAction implements ComponentsWsAction { @Override public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_TREE) - .setDescription(format("Navigate through components based on the chosen strategy. The %s or the %s parameter must be provided.
" + + .setDescription(format("Navigate through components based on the chosen strategy.
" + "Requires the following permission: 'Browse' on the specified project.
" + "When limiting search with the %s parameter, directories are not returned.", - PARAM_COMPONENT_ID, PARAM_COMPONENT, Param.TEXT_QUERY)) + Param.TEXT_QUERY)) .setSince("5.4") .setResponseExample(getClass().getResource("tree-example.json")) .setChangelog( new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS)), - new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), - new Change("6.4", "The field 'id' is deprecated in the response")) + new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT))) .setHandler(this) .addPagingParams(100, MAX_SIZE); - action.createParam(PARAM_COMPONENT_ID) - .setDescription("Base component id. The search is based on this component.") - .setDeprecatedKey("baseComponentId", "6.4") - .setDeprecatedSince("6.4") - .setExampleValue(UUID_EXAMPLE_02); - action.createParam(PARAM_COMPONENT) .setDescription("Base component key. The search is based on this component.") - .setDeprecatedKey("baseComponentKey", "6.4") + .setRequired(true) .setExampleValue(KEY_PROJECT_EXAMPLE_001); action.createParam(PARAM_BRANCH) @@ -200,16 +188,9 @@ public class TreeAction implements ComponentsWsAction { } private ComponentDto loadComponent(DbSession dbSession, Request request) { - String componentId = request.getBaseComponentId(); String componentKey = request.getComponent(); String branch = request.getBranch(); String pullRequest = request.getPullRequest(); - checkArgument(componentId == null || (branch == null && pullRequest == null), "Parameter '%s' cannot be used at the same time as '%s' or '%s'", PARAM_COMPONENT_ID, - PARAM_BRANCH, PARAM_PULL_REQUEST); - if (branch == null && pullRequest == null) { - return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_COMPONENT); - } - checkRequest(componentKey != null, "The '%s' parameter is missing", PARAM_COMPONENT); return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest); } @@ -299,8 +280,7 @@ public class TreeAction implements ComponentsWsAction { private static Request toTreeWsRequest(org.sonar.api.server.ws.Request request) { return new Request() - .setBaseComponentId(request.param(PARAM_COMPONENT_ID)) - .setComponent(request.param(PARAM_COMPONENT)) + .setComponent(request.mandatoryParam(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)) .setStrategy(request.mandatoryParam(PARAM_STRATEGY)) @@ -350,7 +330,6 @@ public class TreeAction implements ComponentsWsAction { } private static class Request { - private String baseComponentId; private String component; private String branch; private String pullRequest; @@ -362,25 +341,7 @@ public class TreeAction implements ComponentsWsAction { private Integer page; private Integer pageSize; - /** - * @deprecated since 6.4, please use {@link #getComponent()} instead - */ - @Deprecated - @CheckForNull - private String getBaseComponentId() { - return baseComponentId; - } - - /** - * @deprecated since 6.4, please use {@link #setComponent(String)} instead - */ - @Deprecated - private Request setBaseComponentId(@Nullable String baseComponentId) { - this.baseComponentId = baseComponentId; - return this; - } - - public Request setComponent(@Nullable String component) { + public Request setComponent(String component) { this.component = component; return this; } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search-components-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search-components-example.json index c717cc3631e..0eb71aa1f14 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search-components-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search-components-example.json @@ -7,7 +7,6 @@ "components": [ { "organization": "my-org-1", - "id": "directory-uuid", "key": "directory-key", "qualifier": "DIR", "name": "Directory Name", @@ -15,7 +14,6 @@ }, { "organization": "my-org-1", - "id": "file-uuid", "key": "file-key", "qualifier": "FIL", "name": "File Name", @@ -24,7 +22,6 @@ }, { "organization": "my-org-1", - "id": "project-uuid", "key": "project-key", "qualifier": "TRK", "name": "Project Name", diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search_projects-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search_projects-example.json index 942f218e1c5..ca957b47819 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search_projects-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search_projects-example.json @@ -17,7 +17,6 @@ "components": [ { "organization": "my-org-key-1", - "id": "AU-Tpxb--iU5OvuD2FLy", "key": "my_project", "name": "My Project 1", "isFavorite": true, @@ -29,7 +28,6 @@ }, { "organization": "my-org-key-1", - "id": "AU-TpxcA-iU5OvuD2FLz", "key": "another_project", "name": "My Project 2", "isFavorite": false, @@ -38,7 +36,6 @@ }, { "organization": "my-org-key-2", - "id": "AU-TpxcA-iU5OvuD2FL0", "key": "third_project", "name": "My Project 3", "isFavorite": false, diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/show-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/show-example.json index 6b54b493c10..835b437f6c2 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/show-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/show-example.json @@ -1,7 +1,6 @@ { "component": { "organization": "my-org-1", - "id": "AVIF-FffA3Ax6PH2efPD", "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java", "name": "Rule.java", "qualifier": "FIL", @@ -14,7 +13,6 @@ "ancestors": [ { "organization": "my-org-1", - "id": "AVIF-FfgA3Ax6PH2efPF", "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl", "name": "src/main/java/com/sonarsource/markdown/impl", "qualifier": "DIR", @@ -24,7 +22,6 @@ }, { "organization": "my-org-1", - "id": "AVIF98jgA3Ax6PH2efOW", "key": "com.sonarsource:java-markdown", "name": "Java Markdown", "description": "Java Markdown Project", diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json index 51a4d73b414..522daffccc0 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json @@ -6,15 +6,15 @@ }, "baseComponent": { "organization": "my-org-1", - "id": "MY_PROJECT_ID", "key": "MY_PROJECT_KEY", - "name": "Project Name", - "qualifier": "TRK" + "description": "DESCRIPTION_MY_PROJECT_ID", + "qualifier": "TRK", + "tags": [], + "visibility": "private" }, "components": [ { "organization": "my-org-1", - "id": "AVHE6Jo2EplJjXTo0Rzw", "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/BasicMarkdownParser.java", "name": "BasicMarkdownParser.java", "qualifier": "UTS", @@ -23,7 +23,6 @@ }, { "organization": "my-org-1", - "id": "AVHE6Jo3EplJjXTo0Rzx", "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/BasicMarkdownParserTest.java", "name": "BasicMarkdownParserTest.java", "qualifier": "UTS", @@ -32,7 +31,6 @@ }, { "organization": "my-org-1", - "id": "AVHE6Jo1EplJjXTo0Rzj", "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown", "name": "src/main/java/com/sonarsource/markdown", "qualifier": "DIR", diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java index 647eca99f4f..b9a26f11ae0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java @@ -169,7 +169,7 @@ public class AppActionTest { } @Test - public void get_by_uuid() { + public void get_by_component() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, project)); MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY)); @@ -177,7 +177,7 @@ public class AppActionTest { userSession.logIn("john").addProjectPermission(USER, project); String result = ws.newRequest() - .setParam("uuid", file.uuid()) + .setParam("component", file.getDbKey()) .execute() .getInput(); @@ -291,39 +291,85 @@ public class AppActionTest { @Test public void fail_if_no_parameter_provided() { expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Either 'componentId' or 'component' must be provided"); + expectedException.expectMessage("The 'component' parameter is missing"); ws.newRequest().execute(); } @Test - public void fail_if_both_componentId_and_branch_parameters_provided() { + public void component_and_branch_parameters_provided() { ComponentDto project = db.components().insertMainBranch(); + userSession.logIn("john").addProjectPermission(USER, project); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto file = db.components().insertComponent(newFileDto(branch)); - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'"); - - ws.newRequest() - .setParam("uuid", file.uuid()) + String result = ws.newRequest() + .setParam("component", file.getDbKey()) .setParam("branch", file.getBranch()) - .execute(); + .execute() + .getInput(); + + assertJson(result).isSimilarTo("{\n" + + " \"key\": \"" + file.getKey() + "\",\n" + + " \"branch\": \"" + file.getBranch() + "\",\n" + + " \"uuid\": \"" + file.uuid() + "\",\n" + + " \"path\": \"" + file.path() + "\",\n" + + " \"name\": \"" + file.name() + "\",\n" + + " \"longName\": \"" + file.longName() + "\",\n" + + " \"q\": \"" + file.qualifier() + "\",\n" + + " \"project\": \"" + project.getKey() + "\",\n" + + " \"projectName\": \"" + project.longName() + "\",\n" + + " \"fav\": false,\n" + + " \"canMarkAsFavorite\": true,\n" + + " \"measures\": {}\n" + + "}\n"); + } + + @Test + public void component_and_pull_request_parameters_provided() { + ComponentDto project = db.components().insertMainBranch(); + userSession.logIn("john").addProjectPermission(USER, project); + ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); + ComponentDto file = db.components().insertComponent(newFileDto(branch)); + + String result = ws.newRequest() + .setParam("component", file.getDbKey()) + .setParam("pullRequest", file.getPullRequest()) + .execute() + .getInput(); + + assertJson(result).isSimilarTo("{\n" + + " \"key\": \"" + file.getKey() + "\",\n" + + " \"uuid\": \"" + file.uuid() + "\",\n" + + " \"path\": \"" + file.path() + "\",\n" + + " \"name\": \"" + file.name() + "\",\n" + + " \"longName\": \"" + file.longName() + "\",\n" + + " \"q\": \"" + file.qualifier() + "\",\n" + + " \"project\": \"" + project.getKey() + "\",\n" + + " \"projectName\": \"" + project.longName() + "\",\n" + + " \"pullRequest\": \"" + file.getPullRequest() + "\",\n" + + " \"fav\": false,\n" + + " \"canMarkAsFavorite\": true,\n" + + " \"measures\": {}\n" + + "}\n"); } @Test - public void fail_if_both_componentId_and_pull_request_parameters_provided() { + public void fail_if_component_and_pull_request_and_branch_parameters_provided() { ComponentDto project = db.components().insertMainBranch(); + userSession.logIn("john").addProjectPermission(USER, project); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); ComponentDto file = db.components().insertComponent(newFileDto(branch)); expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'"); + expectedException.expectMessage("Either branch or pull request can be provided, not both"); ws.newRequest() - .setParam("uuid", file.uuid()) - .setParam("pullRequest", file.getPullRequest()) - .execute(); + .setParam("component", file.getDbKey()) + .setParam("branch", "unknown_branch") + .setParam("pullRequest", "unknown_component") + .execute() + .getInput(); } @Test @@ -371,7 +417,21 @@ public class AppActionTest { assertThat(action.isInternal()).isTrue(); assertThat(action.isPost()).isFalse(); assertThat(action.handler()).isNotNull(); - assertThat(action.params()).hasSize(4); + assertThat(action.responseExampleAsString()).isNotNull(); + + assertThat(action.params()).hasSize(3); + + WebService.Param paramComponent = action.param(AppAction.PARAM_COMPONENT); + assertThat(paramComponent).isNotNull(); + assertThat(paramComponent.isRequired()).isTrue(); + + WebService.Param paramBranch = action.param(MeasuresWsParameters.PARAM_BRANCH); + assertThat(paramBranch).isNotNull(); + assertThat(paramBranch.isRequired()).isFalse(); + + WebService.Param paramPullRequest = action.param(MeasuresWsParameters.PARAM_PULL_REQUEST); + assertThat(paramPullRequest).isNotNull(); + assertThat(paramPullRequest.isRequired()).isFalse(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java index 49262c18750..f7825ddc42d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java @@ -117,8 +117,11 @@ public class SearchActionTest { assertThat(action.since()).isEqualTo("6.3"); assertThat(action.isPost()).isFalse(); assertThat(action.isInternal()).isFalse(); - assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( - tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated")); + assertThat(action.changelog()) + .extracting(Change::getVersion, Change::getDescription) + .containsExactlyInAnyOrder( + tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"), + tuple("8.0", "Field 'id' from response has been removed")); assertThat(action.responseExampleAsString()).isNotEmpty(); assertThat(action.params()).hasSize(6); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index c1c13f64918..2fb20536bf0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -35,7 +35,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.sonar.api.measures.Metric; -import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.WebService; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.System2; @@ -153,12 +152,7 @@ public class SearchProjectsActionTest { assertThat(def.isPost()).isFalse(); assertThat(def.responseExampleAsString()).isNotEmpty(); assertThat(def.params().stream().map(Param::key).collect(toList())).containsOnly("organization", "filter", "facets", "s", "asc", "ps", "p", "f"); - assertThat(def.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( - tuple("6.4", "The 'languages' parameter accepts 'filter' to filter by language"), - tuple("6.4", "The 'visibility' field is added"), - tuple("6.5", "The 'filter' parameter now allows 'NO_DATA' as value for numeric metrics"), - tuple("6.5", "Added the option 'analysisDate' for the 'sort' parameter"), - tuple("6.5", "Value 'leakPeriodDate' is added to parameter 'f'")); + assertThat(def.changelog()).hasSize(1); Param organization = def.param("organization"); assertThat(organization.isRequired()).isFalse(); @@ -235,8 +229,8 @@ public class SearchProjectsActionTest { .setParam(FACETS, COVERAGE) .executeProtobuf(SearchProjectsWsResponse.class); - assertThat(protobufResult.getComponentsList()).extracting(Component::getId) - .containsExactly(project1.uuid(), project2.uuid(), project3.uuid()); + assertThat(protobufResult.getComponentsList()).extracting(Component::getKey) + .containsExactly(project1.getDbKey(), project2.getDbKey(), project3.getDbKey()); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java index 7a49308d9f0..9b8a0b48bc1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java @@ -55,7 +55,6 @@ import static org.sonar.db.component.SnapshotTesting.newAnalysis; import static org.sonar.test.JsonAssert.assertJson; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PULL_REQUEST; public class ShowActionTest { @@ -76,29 +75,13 @@ public class ShowActionTest { assertThat(action.description()).isNotNull(); assertThat(action.responseExample()).isNotNull(); assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( - tuple("6.4", "Analysis date has been added to the response"), - tuple("6.4", "The field 'id' is deprecated in the response"), - tuple("6.4", "The 'visibility' field is added to the response"), - tuple("6.5", "Leak period date is added to the response"), - tuple("6.6", "'branch' is added to the response"), - tuple("6.6", "'version' is added to the response"), tuple("7.6", "The use of module keys in parameter 'component' is deprecated")); - assertThat(action.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("component", "componentId", "branch", "pullRequest"); - - WebService.Param componentId = action.param(PARAM_COMPONENT_ID); - assertThat(componentId.isRequired()).isFalse(); - assertThat(componentId.description()).isNotNull(); - assertThat(componentId.exampleValue()).isNotNull(); - assertThat(componentId.deprecatedSince()).isEqualTo("6.4"); - assertThat(componentId.deprecatedKey()).isEqualTo("id"); - assertThat(componentId.deprecatedKeySince()).isEqualTo("6.4"); + assertThat(action.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("component", "branch", "pullRequest"); WebService.Param component = action.param(PARAM_COMPONENT); - assertThat(component.isRequired()).isFalse(); + assertThat(component.isRequired()).isTrue(); assertThat(component.description()).isNotNull(); assertThat(component.exampleValue()).isNotNull(); - assertThat(component.deprecatedKey()).isEqualTo("key"); - assertThat(component.deprecatedKeySince()).isEqualTo("6.4"); WebService.Param branch = action.param(PARAM_BRANCH); assertThat(branch.isInternal()).isTrue(); @@ -117,7 +100,7 @@ public class ShowActionTest { insertJsonExampleComponentsAndSnapshots(); String response = ws.newRequest() - .setParam("id", "AVIF-FffA3Ax6PH2efPD") + .setParam("component", "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java") .execute() .getInput(); @@ -130,7 +113,7 @@ public class ShowActionTest { insertJsonExampleComponentsAndSnapshots(); String response = ws.newRequest() - .setParam("id", "AVIF-FffA3Ax6PH2efPD") + .setParam(PARAM_COMPONENT, "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java") .execute() .getInput(); @@ -143,21 +126,9 @@ public class ShowActionTest { db.components().insertProjectAndSnapshot(project); userSession.logIn().addProjectPermission(USER, project); - ShowWsResponse response = newRequest("project-uuid", null); - - assertThat(response.getComponent().getId()).isEqualTo("project-uuid"); - } - - @Test - public void show_provided_project() { - userSession.logIn().setRoot(); - db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid")); + ShowWsResponse response = newRequest(project.getDbKey()); - ShowWsResponse response = newRequest("project-uuid", null); - - assertThat(response.getComponent().getId()).isEqualTo("project-uuid"); - assertThat(response.getComponent().hasAnalysisDate()).isFalse(); - assertThat(response.getComponent().hasLeakPeriodDate()).isFalse(); + assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); } @Test @@ -168,7 +139,7 @@ public class ShowActionTest { ComponentDto file = db.components().insertComponent(newFileDto(directory)); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(null, file.getDbKey()); + ShowWsResponse response = newRequest(file.getDbKey()); assertThat(response.getComponent().getKey()).isEqualTo(file.getDbKey()); assertThat(response.getAncestorsList()).extracting(Component::getKey).containsOnly(directory.getDbKey(), module.getDbKey(), project.getDbKey()); @@ -180,7 +151,7 @@ public class ShowActionTest { db.components().insertComponent(newModuleDto(project)); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(null, project.getDbKey()); + ShowWsResponse response = newRequest(project.getDbKey()); assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); assertThat(response.getAncestorsList()).isEmpty(); @@ -195,7 +166,7 @@ public class ShowActionTest { newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true)); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(null, project.getDbKey()); + ShowWsResponse response = newRequest(project.getDbKey()); assertThat(response.getComponent().getAnalysisDate()).isNotEmpty().isEqualTo(formatDateTime(new Date(3_000_000_000L))); } @@ -210,7 +181,7 @@ public class ShowActionTest { userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(null, project.getDbKey()); + ShowWsResponse response = newRequest(project.getDbKey()); assertThat(response.getComponent().getLeakPeriodDate()).isNotEmpty().isEqualTo(formatDateTime(new Date(3_000_000_000L))); } @@ -224,7 +195,7 @@ public class ShowActionTest { ComponentDto file = db.components().insertComponent(newFileDto(directory)); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(null, file.getDbKey()); + ShowWsResponse response = newRequest(file.getDbKey()); String expectedDate = formatDateTime(new Date(3_000_000_000L)); assertThat(response.getAncestorsList()).extracting(Component::getAnalysisDate) @@ -236,7 +207,7 @@ public class ShowActionTest { userSession.logIn().setRoot(); ComponentDto privateProject = db.components().insertPrivateProject(); - ShowWsResponse result = newRequest(null, privateProject.getDbKey()); + ShowWsResponse result = newRequest(privateProject.getDbKey()); assertThat(result.getComponent().hasVisibility()).isTrue(); assertThat(result.getComponent().getVisibility()).isEqualTo("private"); } @@ -246,7 +217,7 @@ public class ShowActionTest { userSession.logIn().setRoot(); ComponentDto publicProject = db.components().insertPublicProject(); - ShowWsResponse result = newRequest(null, publicProject.getDbKey()); + ShowWsResponse result = newRequest(publicProject.getDbKey()); assertThat(result.getComponent().hasVisibility()).isTrue(); assertThat(result.getComponent().getVisibility()).isEqualTo("public"); } @@ -256,7 +227,7 @@ public class ShowActionTest { userSession.logIn().setRoot(); ComponentDto view = db.components().insertView(); - ShowWsResponse result = newRequest(null, view.getDbKey()); + ShowWsResponse result = newRequest(view.getDbKey()); assertThat(result.getComponent().hasVisibility()).isTrue(); } @@ -266,7 +237,7 @@ public class ShowActionTest { ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(privateProject)); - ShowWsResponse result = newRequest(null, module.getDbKey()); + ShowWsResponse result = newRequest(module.getDbKey()); assertThat(result.getComponent().hasVisibility()).isFalse(); } @@ -279,7 +250,7 @@ public class ShowActionTest { db.components().insertSnapshot(project, s -> s.setProjectVersion("1.1")); userSession.addProjectPermission(USER, project); - ShowWsResponse response = newRequest(null, file.getDbKey()); + ShowWsResponse response = newRequest(file.getDbKey()); assertThat(response.getComponent().getVersion()).isEqualTo("1.1"); assertThat(response.getAncestorsList()) @@ -344,17 +315,18 @@ public class ShowActionTest { userSession.logIn(); expectedException.expect(ForbiddenException.class); - db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), "project-uuid")); + ComponentDto componentDto = newPrivateProjectDto(db.organizations().insert(), "project-uuid"); + db.components().insertProjectAndSnapshot(componentDto); - newRequest("project-uuid", null); + newRequest(componentDto.getDbKey()); } @Test public void fail_if_component_does_not_exist() { expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Component id 'unknown-uuid' not found"); + expectedException.expectMessage("Component key 'unknown-key' not found"); - newRequest("unknown-uuid", null); + newRequest("unknown-key"); } @Test @@ -366,22 +338,7 @@ public class ShowActionTest { expectedException.expect(NotFoundException.class); expectedException.expectMessage("Component key 'file-key' not found"); - newRequest(null, "file-key"); - } - - @Test - public void fail_when_componentId_and_branch_params_are_used_together() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'"); - - ws.newRequest() - .setParam(PARAM_COMPONENT_ID, branch.uuid()) - .setParam(PARAM_BRANCH, "my_branch") - .execute(); + newRequest("file-key"); } @Test @@ -414,25 +371,8 @@ public class ShowActionTest { .executeProtobuf(ShowWsResponse.class); } - @Test - public void fail_when_using_branch_uuid() { - ComponentDto project = db.components().insertMainBranch(); - userSession.addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - expectedException.expect(NotFoundException.class); - expectedException.expectMessage(String.format("Component id '%s' not found", branch.uuid())); - - ws.newRequest() - .setParam(PARAM_COMPONENT_ID, branch.uuid()) - .executeProtobuf(ShowWsResponse.class); - } - - private ShowWsResponse newRequest(@Nullable String uuid, @Nullable String key) { + private ShowWsResponse newRequest(@Nullable String key) { TestRequest request = ws.newRequest(); - if (uuid != null) { - request.setParam(PARAM_COMPONENT_ID, uuid); - } if (key != null) { request.setParam(PARAM_COMPONENT, key); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java index ac53fa54511..4e220848654 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java @@ -120,8 +120,7 @@ public class SuggestionsActionTest { PARAM_QUERY, PARAM_RECENTLY_BROWSED); assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( - tuple("7.6", "The use of 'BRC' as value for parameter 'more' is deprecated"), - tuple("6.4", "Parameter 's' is optional")); + tuple("7.6", "The use of 'BRC' as value for parameter 'more' is deprecated")); WebService.Param recentlyBrowsed = action.param(PARAM_RECENTLY_BROWSED); assertThat(recentlyBrowsed.since()).isEqualTo("6.4"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index 1355a1e0dbb..8c5d67906f6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -72,7 +72,6 @@ import static org.sonar.db.component.ComponentTesting.newSubView; import static org.sonar.db.component.ComponentTesting.newView; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PULL_REQUEST; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY; @@ -101,25 +100,14 @@ public class TreeActionTest { assertThat(action.responseExample()).isNotNull(); assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"), - tuple("7.6", "The use of module keys in parameter 'component' is deprecated"), - tuple("6.4", "The field 'id' is deprecated in the response")); - assertThat(action.params()).extracting(Param::key).containsExactlyInAnyOrder("component", "componentId", "branch", "pullRequest", "qualifiers", "strategy", + tuple("7.6", "The use of module keys in parameter 'component' is deprecated")); + assertThat(action.params()).extracting(Param::key).containsExactlyInAnyOrder("component", "branch", "pullRequest", "qualifiers", "strategy", "q", "s", "p", "asc", "ps"); - Param componentId = action.param(PARAM_COMPONENT_ID); - assertThat(componentId.isRequired()).isFalse(); - assertThat(componentId.description()).isNotNull(); - assertThat(componentId.exampleValue()).isNotNull(); - assertThat(componentId.deprecatedSince()).isEqualTo("6.4"); - assertThat(componentId.deprecatedKey()).isEqualTo("baseComponentId"); - assertThat(componentId.deprecatedKeySince()).isEqualTo("6.4"); - Param component = action.param(PARAM_COMPONENT); - assertThat(component.isRequired()).isFalse(); + assertThat(component.isRequired()).isTrue(); assertThat(component.description()).isNotNull(); assertThat(component.exampleValue()).isNotNull(); - assertThat(component.deprecatedKey()).isEqualTo("baseComponentKey"); - assertThat(component.deprecatedKeySince()).isEqualTo("6.4"); Param branch = action.param(PARAM_BRANCH); assertThat(branch.isInternal()).isTrue(); @@ -133,8 +121,9 @@ public class TreeActionTest { logInWithBrowsePermission(project); String response = ws.newRequest() - .setParam(PARAM_COMPONENT_ID, project.uuid()) - .execute().getInput(); + .setParam(PARAM_COMPONENT, project.getDbKey()) + .execute() + .getInput(); JsonAssert.assertJson(response) .withStrictArrayOrder() @@ -159,7 +148,7 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "children") - .setParam(PARAM_COMPONENT_ID, "module-uuid-1") + .setParam(PARAM_COMPONENT, module.getDbKey()) .setParam(Param.PAGE, "2") .setParam(Param.PAGE_SIZE, "3") .setParam(Param.TEXT_QUERY, "file-name") @@ -168,7 +157,7 @@ public class TreeActionTest { assertThat(response.getComponentsCount()).isEqualTo(3); assertThat(response.getPaging().getTotal()).isEqualTo(8); - assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-6", "file-uuid-5", "file-uuid-4"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-6", "file-key-5", "file-key-4"); } @Test @@ -189,7 +178,7 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "all") - .setParam(PARAM_COMPONENT_ID, "module-uuid-1") + .setParam(PARAM_COMPONENT, module.getDbKey()) .setParam(Param.PAGE, "2") .setParam(Param.PAGE_SIZE, "3") .setParam(Param.TEXT_QUERY, "file-name") @@ -198,7 +187,7 @@ public class TreeActionTest { assertThat(response.getComponentsCount()).isEqualTo(3); assertThat(response.getPaging().getTotal()).isEqualTo(9); - assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-4", "file-uuid-5", "file-uuid-6"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-4", "file-key-5", "file-key-6"); } @Test @@ -214,9 +203,9 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "all") .setParam(PARAM_QUALIFIERS, FILE) - .setParam(PARAM_COMPONENT_ID, "project-uuid").executeProtobuf(TreeWsResponse.class); + .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-1", "file-key-2"); } @Test @@ -235,12 +224,12 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "leaves") - .setParam(PARAM_COMPONENT_ID, "project-uuid") + .setParam(PARAM_COMPONENT, project.getDbKey()) .setParam(PARAM_QUALIFIERS, FILE).executeProtobuf(TreeWsResponse.class); assertThat(response.getComponentsCount()).isEqualTo(3); assertThat(response.getPaging().getTotal()).isEqualTo(3); - assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-1", "file-key-2", "file-key-3"); } @Test @@ -258,9 +247,9 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "all") .setParam(Param.SORT, "qualifier, name") - .setParam(PARAM_COMPONENT_ID, "project-uuid").executeProtobuf(TreeWsResponse.class); + .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id").containsExactly("module-uuid-1", "path/directory/", "file-uuid-1", "file-uuid-2"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("MODULE_KEY_module-uuid-1", "KEY_project-uuid:directory-uuid-1", "file-key-1", "file-key-2"); } @Test @@ -278,10 +267,10 @@ public class TreeActionTest { TreeWsResponse response = ws.newRequest() .setParam(PARAM_STRATEGY, "children") - .setParam(PARAM_COMPONENT_ID, "view-uuid") + .setParam(PARAM_COMPONENT, view.getDbKey()) .setParam(Param.TEXT_QUERY, "name").executeProtobuf(TreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id").containsExactly("project-uuid-1-copy", "sub-view-uuid"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("KEY_view-uuidproject-key-1", "sub-view-key"); assertThat(response.getComponentsList()).extracting("refId").containsExactly("project-uuid-1", ""); assertThat(response.getComponentsList()).extracting("refKey").containsExactly("project-key-1", ""); } @@ -315,9 +304,9 @@ public class TreeActionTest { logInWithBrowsePermission(project); TreeWsResponse response = ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "project-uuid").executeProtobuf(TreeWsResponse.class); + .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class); - assertThat(response.getBaseComponent().getId()).isEqualTo("project-uuid"); + assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getDbKey()); assertThat(response.getComponentsList()).isEmpty(); assertThat(response.getPaging().getTotal()).isEqualTo(0); assertThat(response.getPaging().getPageSize()).isEqualTo(100); @@ -330,16 +319,18 @@ public class TreeActionTest { db.components().insertProjectAndSnapshot(project); ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid"); db.components().insertViewAndSnapshot(view); - db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view)); + ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view)); userSession.logIn() .registerComponents(project, view); - TreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT_ID, view.uuid()).executeProtobuf(TreeWsResponse.class); + TreeWsResponse response = ws.newRequest() + .setParam(PARAM_COMPONENT, view.getDbKey()) + .executeProtobuf(TreeWsResponse.class); - assertThat(response.getBaseComponent().getId()).isEqualTo(view.uuid()); + assertThat(response.getBaseComponent().getKey()).isEqualTo(view.getDbKey()); assertThat(response.getComponentsCount()).isEqualTo(1); - assertThat(response.getComponents(0).getId()).isEqualTo("project-copy-uuid"); - assertThat(response.getComponents(0).getRefId()).isEqualTo("project-uuid"); + assertThat(response.getComponents(0).getKey()).isEqualTo(projectCopy.getDbKey()); + assertThat(response.getComponents(0).getRefKey()).isEqualTo(project.getDbKey()); } @Test @@ -403,16 +394,16 @@ public class TreeActionTest { } @Test - public void fail_when_using_branch_uuid() { + public void fail_when_using_branch_key() { ComponentDto project = db.components().insertMainBranch(); userSession.addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); - expectedException.expectMessage(String.format("Component id '%s' not found", branch.uuid())); + expectedException.expectMessage(String.format("Component key '%s' not found", branch.getDbKey())); ws.newRequest() - .setParam(PARAM_COMPONENT_ID, branch.uuid()) + .setParam(PARAM_COMPONENT, branch.getDbKey()) .executeProtobuf(Components.ShowWsResponse.class); } @@ -426,7 +417,7 @@ public class TreeActionTest { expectedException.expect(ForbiddenException.class); ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "project-uuid") + .setParam(PARAM_COMPONENT, project.getDbKey()) .execute(); } @@ -434,11 +425,11 @@ public class TreeActionTest { public void fail_when_page_size_above_500() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'ps' value (501) must be less than 500"); - db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid")); + ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid")); db.commit(); ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "project-uuid") + .setParam(PARAM_COMPONENT, project.getDbKey()) .setParam(Param.PAGE_SIZE, "501") .execute(); } @@ -447,11 +438,11 @@ public class TreeActionTest { public void fail_when_search_query_has_less_than_3_characters() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'q' length (2) is shorter than the minimum authorized (3)"); - db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid")); + ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid")); db.commit(); ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "project-uuid") + .setParam(PARAM_COMPONENT, project.getDbKey()) .setParam(Param.TEXT_QUERY, "fi") .execute(); } @@ -463,7 +454,7 @@ public class TreeActionTest { db.commit(); ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "project-uuid") + .setParam(PARAM_COMPONENT, "project-key") .setParam(Param.SORT, "unknown-sort") .execute(); } @@ -475,7 +466,7 @@ public class TreeActionTest { db.commit(); ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "project-uuid") + .setParam(PARAM_COMPONENT, "project-key") .setParam(PARAM_STRATEGY, "unknown-strategy") .execute(); } @@ -485,7 +476,7 @@ public class TreeActionTest { expectedException.expect(NotFoundException.class); ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "project-uuid") + .setParam(PARAM_COMPONENT, "project-key") .execute(); } @@ -506,26 +497,11 @@ public class TreeActionTest { @Test public void fail_when_no_base_component_parameter() { expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Either 'componentId' or 'component' must be provided"); + expectedException.expectMessage("The 'component' parameter is missing"); ws.newRequest().execute(); } - @Test - public void fail_when_componentId_and_branch_params_are_used_together() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'"); - - ws.newRequest() - .setParam(PARAM_COMPONENT_ID, branch.uuid()) - .setParam(PARAM_BRANCH, "my_branch") - .execute(); - } - @Test public void fail_if_branch_does_not_exist() { ComponentDto project = db.components().insertPrivateProject(); @@ -562,9 +538,10 @@ public class TreeActionTest { JsonParser jsonParser = new JsonParser(); JsonElement jsonTree = jsonParser.parse(IOUtils.toString(getClass().getResource("tree-example.json"), UTF_8)); JsonArray components = jsonTree.getAsJsonObject().getAsJsonArray("components"); - for (JsonElement componentAsJsonElement : components) { + for (int i = 0; i < components.size(); i++) { + JsonElement componentAsJsonElement = components.get(i); JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject(); - String uuid = getJsonField(componentAsJsonObject, "id"); + String uuid = String.format("child-component-uuid-%d", i); db.components().insertComponent(newChildComponent(uuid, project, project) .setDbKey(getJsonField(componentAsJsonObject, "key")) .setName(getJsonField(componentAsJsonObject, "name")) diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index b6258df983e..2c6fc63e0db 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -671,7 +671,7 @@ public class SearchActionTest { indexIssues(); TestResponse response = ws.newRequest() - .setParam("sort", IssueQuery.SORT_BY_UPDATE_DATE) + .setParam("s", IssueQuery.SORT_BY_UPDATE_DATE) .setParam("asc", "false") .execute(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java index 50dcfa8bb46..528a86d9cd9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java @@ -470,7 +470,6 @@ public interface WebService extends Definable { return createParam(Param.SORT) .setDescription("Sort field") - .setDeprecatedKey("sort", "5.4") .setDefaultValue(defaultValue) .setPossibleValues(possibleValues); } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java index 1b91780bfd0..524f01383dc 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java @@ -36,7 +36,6 @@ public class ComponentsWsParameters { public static final String PARAM_LANGUAGE = "language"; public static final String PARAM_STRATEGY = "strategy"; public static final String PARAM_FILTER = "filter"; - public static final String PARAM_COMPONENT_ID = "componentId"; public static final String PARAM_COMPONENT = "component"; public static final String PARAM_BRANCH = "branch"; public static final String PARAM_PULL_REQUEST = "pullRequest"; diff --git a/sonar-ws/src/main/protobuf/ws-components.proto b/sonar-ws/src/main/protobuf/ws-components.proto index bd1fbefd23f..da476e7957f 100644 --- a/sonar-ws/src/main/protobuf/ws-components.proto +++ b/sonar-ws/src/main/protobuf/ws-components.proto @@ -99,7 +99,6 @@ message ProvisionedWsResponse { message Component { optional string organization = 12; - optional string id = 1; optional string key = 2; optional string refId = 3; optional string refKey = 4; -- 2.39.5