From 7bf35a666c4c577bc8fa72a07b0e06ee7153dc08 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 15 Oct 2019 13:43:22 -0500 Subject: [PATCH] SONAR-11869 Remove deprecated parameters in measures WS --- .../component/ws/MeasuresWsParameters.java | 4 - .../server/measure/ws/ComponentAction.java | 57 ++------------ .../measure/ws/ComponentTreeAction.java | 18 +---- .../measure/ws/ComponentTreeRequest.java | 22 ------ .../ws/MeasuresWsParametersBuilder.java | 13 ---- .../measure/ws/ComponentActionTest.java | 78 ++----------------- 6 files changed, 16 insertions(+), 176 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java index da4f72fdbd5..1dc236821fc 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java @@ -44,11 +44,7 @@ public class MeasuresWsParameters { public static final String PARAM_METRIC_PERIOD_SORT = "metricPeriodSort"; public static final String PARAM_METRIC_SORT_FILTER = "metricSortFilter"; public static final String PARAM_ADDITIONAL_FIELDS = "additionalFields"; - public static final String DEPRECATED_PARAM_COMPONENT_ID = "componentId"; - public static final String DEPRECATED_PARAM_COMPONENT_KEY = "componentKey"; public static final String PARAM_PROJECT_KEYS = "projectKeys"; - public static final String PARAM_DEVELOPER_ID = "developerId"; - public static final String PARAM_DEVELOPER_KEY = "developerKey"; public static final String PARAM_FROM = "from"; public static final String PARAM_TO = "to"; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index a34da0fdb0f..8ccd6eb5013 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -53,35 +53,27 @@ import org.sonar.server.user.UserSession; import org.sonarqube.ws.Measures; import org.sonarqube.ws.Measures.ComponentWsResponse; -import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; -import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_KEY; import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_COMPONENT; import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_METRICS; import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIODS; -import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; -import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; -import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID; -import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.measure.ws.ComponentDtoToWsComponent.componentDtoToWsComponent; import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAdditionalFieldsParameter; -import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createDeveloperParameters; import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter; import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric; import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeriods; 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.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class ComponentAction implements MeasuresWsAction { @@ -100,9 +92,8 @@ public class ComponentAction implements MeasuresWsAction { @Override public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_COMPONENT) - .setDescription(format("Return component with specified measures. The %s or the %s parameter must be provided.
" + - "Requires the following permission: 'Browse' on the project of specified component.", - DEPRECATED_PARAM_COMPONENT_ID, PARAM_COMPONENT)) + .setDescription(format("Return component with specified measures.
" + + "Requires the following permission: 'Browse' on the project of specified component.")) .setResponseExample(getClass().getResource("component-example.json")) .setSince("5.4") .setChangelog( @@ -113,13 +104,8 @@ public class ComponentAction implements MeasuresWsAction { action.createParam(PARAM_COMPONENT) .setDescription("Component key") - .setExampleValue(KEY_PROJECT_EXAMPLE_001) - .setDeprecatedKey(DEPRECATED_PARAM_COMPONENT_KEY, "6.6"); - - action.createParam(DEPRECATED_PARAM_COMPONENT_ID) - .setDescription("Component id") - .setExampleValue(UUID_EXAMPLE_01) - .setDeprecatedSince("6.6"); + .setRequired(true) + .setExampleValue(KEY_PROJECT_EXAMPLE_001); action.createParam(PARAM_BRANCH) .setDescription("Branch key") @@ -135,15 +121,10 @@ public class ComponentAction implements MeasuresWsAction { createMetricKeysParameter(action); createAdditionalFieldsParameter(action); - createDeveloperParameters(action); } @Override public void handle(Request request, Response response) throws Exception { - if (request.param(PARAM_DEVELOPER_ID) != null || request.param(PARAM_DEVELOPER_KEY) != null) { - throw new NotFoundException("The Developer Cockpit feature has been dropped. The specified developer cannot be found."); - } - ComponentWsResponse componentWsResponse = doHandle(toComponentWsRequest(request)); writeProtobuf(componentWsResponse, request, response); } @@ -243,12 +224,9 @@ public class ComponentAction implements MeasuresWsAction { private ComponentDto loadComponent(DbSession dbSession, ComponentRequest request, @Nullable String branch, @Nullable String pullRequest) { String componentKey = request.getComponent(); - String componentId = request.getComponentId(); - checkArgument(componentId == null || (branch == null && pullRequest == null), "Parameter '%s' cannot be used at the same time as '%s' or '%s'", - DEPRECATED_PARAM_COMPONENT_ID, PARAM_BRANCH, PARAM_PULL_REQUEST); if (branch == null && pullRequest == null) { - return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_KEY); + return componentFinder.getByKey(dbSession, componentKey); } checkRequest(componentKey != null, "The '%s' parameter is missing", PARAM_COMPONENT); @@ -290,8 +268,7 @@ public class ComponentAction implements MeasuresWsAction { private static ComponentRequest toComponentWsRequest(Request request) { ComponentRequest componentRequest = new ComponentRequest() - .setComponentId(request.param(DEPRECATED_PARAM_COMPONENT_ID)) - .setComponent(request.param(PARAM_COMPONENT)) + .setComponent(request.mandatoryParam(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)) .setAdditionalFields(request.paramAsStrings(PARAM_ADDITIONAL_FIELDS)) @@ -305,32 +282,12 @@ public class ComponentAction implements MeasuresWsAction { } private static class ComponentRequest { - private String componentId; private String component; private String branch; private String pullRequest; private List metricKeys; private List additionalFields; - /** - * @deprecated since 6.6, please use {@link #getComponent()} instead - */ - @Deprecated - @CheckForNull - private String getComponentId() { - return componentId; - } - - /** - * @deprecated since 6.6, please use {@link #setComponent(String)} instead - */ - @Deprecated - private ComponentRequest setComponentId(@Nullable String componentId) { - this.componentId = componentId; - return this; - } - - @CheckForNull private String getComponent() { return component; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java index fb843ebe1b3..818ed85da1e 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java @@ -92,8 +92,6 @@ import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARA import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; -import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID; -import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SORT; @@ -101,19 +99,18 @@ import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SO import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_QUALIFIERS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_STRATEGY; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.measure.ws.ComponentDtoToWsComponent.componentDtoToWsComponent; import static org.sonar.server.measure.ws.MeasureDtoToWsMeasure.updateMeasureBuilder; import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAdditionalFieldsParameter; -import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createDeveloperParameters; import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter; import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric; import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeriods; 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.exceptions.BadRequestException.checkRequest; +import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; import static org.sonar.server.ws.WsUtils.writeProtobuf; /** @@ -177,8 +174,8 @@ public class ComponentTreeAction implements MeasuresWsAction { public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_COMPONENT_TREE) .setDescription(format("Navigate through components based on the chosen strategy with specified measures. The %s or the %s parameter must be provided.
" + - "Requires the following permission: 'Browse' on the specified project.
" + - "When limiting search with the %s parameter, directories are not returned.", + "Requires the following permission: 'Browse' on the specified project.
" + + "When limiting search with the %s parameter, directories are not returned.", DEPRECATED_PARAM_BASE_COMPONENT_ID, PARAM_COMPONENT, Param.TEXT_QUERY)) .setResponseExample(getClass().getResource("component_tree-example.json")) .setSince("5.4") @@ -249,7 +246,6 @@ public class ComponentTreeAction implements MeasuresWsAction { .setDescription("Comma-separated list of metric keys. Types %s are not allowed.", COMMA_JOINER.join(FORBIDDEN_METRIC_TYPES)) .setMaxValuesAllowed(MAX_METRIC_KEYS); createAdditionalFieldsParameter(action); - createDeveloperParameters(action); createQualifiersParameter(action, newQualifierParameterContext(i18n, resourceTypes)); action.createParam(PARAM_STRATEGY) @@ -270,10 +266,6 @@ public class ComponentTreeAction implements MeasuresWsAction { } private ComponentTreeWsResponse doHandle(ComponentTreeRequest request) { - if (request.getDeveloperId() != null || request.getDeveloperKey() != null) { - return emptyResponse(null, request); - } - ComponentTreeData data = load(request); if (data.getComponents() == null) { return emptyResponse(data.getBaseComponent(), request); @@ -362,8 +354,6 @@ public class ComponentTreeAction implements MeasuresWsAction { .setMetricSort(request.param(PARAM_METRIC_SORT)) .setMetricSortFilter(request.mandatoryParam(PARAM_METRIC_SORT_FILTER)) .setMetricPeriodSort(request.paramAsInt(PARAM_METRIC_PERIOD_SORT)) - .setDeveloperId(request.param(PARAM_DEVELOPER_ID)) - .setDeveloperKey(request.param(PARAM_DEVELOPER_KEY)) .setPage(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)) .setQuery(request.param(Param.TEXT_QUERY)); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeRequest.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeRequest.java index b0fb303bd48..c0c44378150 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeRequest.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeRequest.java @@ -41,8 +41,6 @@ class ComponentTreeRequest { private List metricKeys; private Integer page; private Integer pageSize; - private String developerId; - private String developerKey; /** * @deprecated since 6.6, please use {@link #getComponent()} instead @@ -211,24 +209,4 @@ class ComponentTreeRequest { this.metricPeriodSort = metricPeriodSort; return this; } - - @CheckForNull - public String getDeveloperId() { - return developerId; - } - - public ComponentTreeRequest setDeveloperId(@Nullable String developerId) { - this.developerId = developerId; - return this; - } - - @CheckForNull - public String getDeveloperKey() { - return developerKey; - } - - public ComponentTreeRequest setDeveloperKey(@Nullable String developerKey) { - this.developerKey = developerKey; - return this; - } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java index e7604c38cf0..d3d8768662a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java @@ -24,8 +24,6 @@ import org.sonar.api.server.ws.WebService.NewParam; import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_FIELDS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; -import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID; -import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; class MeasuresWsParametersBuilder { @@ -47,15 +45,4 @@ class MeasuresWsParametersBuilder { .setRequired(true) .setExampleValue("ncloc,complexity,violations"); } - - static void createDeveloperParameters(NewAction action) { - deprecateDeveloperParameter(action, PARAM_DEVELOPER_ID); - deprecateDeveloperParameter(action, PARAM_DEVELOPER_KEY); - } - - private static void deprecateDeveloperParameter(NewAction action, String key) { - action.createParam(key) - .setDeprecatedSince("6.4") - .setDescription("Deprecated parameter, used previously with the Developer Cockpit plugin. No measures are returned if parameter is set."); - } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index 780cfc9333d..7e166ecb97b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -53,11 +53,9 @@ import static org.sonar.api.web.UserRole.USER; import static org.sonar.db.component.BranchType.PULL_REQUEST; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newProjectCopy; -import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; -import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST; import static org.sonar.test.JsonAssert.assertJson; @@ -79,10 +77,10 @@ public class ComponentActionTest { assertThat(def.since()).isEqualTo("5.4"); assertThat(def.params()).extracting(Param::key) - .containsExactlyInAnyOrder("componentId", "component", "branch", "pullRequest", "metricKeys", "additionalFields", "developerId", "developerKey"); - assertThat(def.param("developerId").deprecatedSince()).isEqualTo("6.4"); - assertThat(def.param("developerKey").deprecatedSince()).isEqualTo("6.4"); - assertThat(def.param("componentId").deprecatedSince()).isEqualTo("6.6"); + .containsExactlyInAnyOrder("component", "branch", "pullRequest", "metricKeys", "additionalFields"); + + WebService.Param component = def.param(PARAM_COMPONENT); + assertThat(component.isRequired()).isTrue(); WebService.Param branch = def.param("branch"); assertThat(branch.since()).isEqualTo("6.6"); @@ -261,22 +259,7 @@ public class ComponentActionTest { MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); ComponentWsResponse response = ws.newRequest() - .setParam("componentId", project.uuid()) - .setParam(PARAM_METRIC_KEYS, metric.getKey()) - .executeProtobuf(ComponentWsResponse.class); - - assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); - } - - @Test - public void use_deprecated_component_key_parameter() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(UserRole.USER, project); - userSession.addProjectPermission(USER, project); - MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); - - ComponentWsResponse response = ws.newRequest() - .setParam("componentKey", project.getKey()) + .setParam("component", project.getDbKey()) .setParam(PARAM_METRIC_KEYS, metric.getKey()) .executeProtobuf(ComponentWsResponse.class); @@ -326,23 +309,6 @@ public class ComponentActionTest { .containsExactly(tuple(metric.getKey(), "7", true)); } - @Test - public void fail_when_developer_is_not_found() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(UserRole.USER, project); - db.components().insertSnapshot(project); - - MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); - - expectedException.expect(NotFoundException.class); - expectedException.expectMessage("The Developer Cockpit feature has been dropped. The specified developer cannot be found."); - - ws.newRequest() - .setParam(PARAM_COMPONENT, project.getKey()) - .setParam(PARAM_METRIC_KEYS, metric.getKey()) - .setParam(PARAM_DEVELOPER_ID, "unknown-developer-id").executeProtobuf(ComponentWsResponse.class); - } - @Test public void fail_when_a_metric_is_not_found() { ComponentDto project = db.components().insertPrivateProject(); @@ -427,23 +393,6 @@ public class ComponentActionTest { .execute(); } - @Test - public void fail_when_componentId_and_branch_params_are_used_together() { - ComponentDto project = db.components().insertPrivateProject(); - ComponentDto file = db.components().insertComponent(newFileDto(project)); - userSession.addProjectPermission(UserRole.USER, project); - 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(DEPRECATED_PARAM_COMPONENT_ID, file.uuid()) - .setParam(PARAM_BRANCH, "my_branch") - .setParam(PARAM_METRIC_KEYS, "ncloc") - .execute(); - } - @Test public void fail_when_using_branch_db_key() throws Exception { OrganizationDto organization = db.organizations().insert(); @@ -461,23 +410,6 @@ public class ComponentActionTest { .execute(); } - @Test - public void fail_when_using_branch_uuid() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertMainBranch(organization); - userSession.logIn().addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); - - expectedException.expect(NotFoundException.class); - expectedException.expectMessage(format("Component id '%s' not found", branch.uuid())); - - ws.newRequest() - .setParam(DEPRECATED_PARAM_COMPONENT_ID, branch.uuid()) - .setParam(PARAM_METRIC_KEYS, metric.getKey()) - .execute(); - } - @Test public void json_example() { ComponentDto project = db.components().insertPrivateProject(); -- 2.39.5