From: Michal Duda Date: Wed, 24 Feb 2021 14:24:31 +0000 (+0100) Subject: SONAR-13848 remove deprecations from api/measure/* WS X-Git-Tag: 8.8.0.42792~97 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=62f567aab40464bd3cbdf0f143cd454ceb92516f;p=sonarqube.git SONAR-13848 remove deprecations from api/measure/* WS --- 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 7f9e57d7a34..d00bd5adf6c 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 @@ -31,8 +31,6 @@ public class MeasuresWsParameters { public static final String ACTION_SEARCH_HISTORY = "search_history"; // parameters - public static final String DEPRECATED_PARAM_BASE_COMPONENT_ID = "baseComponentId"; - public static final String DEPRECATED_PARAM_BASE_COMPONENT_KEY = "baseComponentKey"; 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/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 56fb4b43c33..383de3a2800 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 @@ -96,11 +96,13 @@ public class ComponentAction implements MeasuresWsAction { .setResponseExample(getClass().getResource("component-example.json")) .setSince("5.4") .setChangelog( + new Change("8.8", "deprecated response field 'id' has been removed"), + new Change("8.8", "deprecated response field 'refId' has been removed."), new Change("8.1", "the response field periods under measures field is deprecated. Use period instead."), new Change("8.1", "the response field periods is deprecated. Use period instead."), new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), - new Change("6.6", "the response field id is deprecated. Use key instead."), - new Change("6.6", "the response field refId is deprecated. Use refKey instead.")) + new Change("6.6", "the response field 'id' is deprecated. Use 'key' instead."), + new Change("6.6", "the response field 'refId' is deprecated. Use 'refKey' instead.")) .setHandler(this); action.createParam(PARAM_COMPONENT) @@ -237,7 +239,7 @@ public class ComponentAction implements MeasuresWsAction { } private static ComponentWsResponse buildResponse(ComponentRequest request, ComponentDto component, Optional refComponent, - Map measuresByMetric, Collection metrics, Optional period) { + Map measuresByMetric, Collection metrics, Optional period) { ComponentWsResponse.Builder response = ComponentWsResponse.newBuilder(); if (refComponent.isPresent()) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java index 19d6095c741..c2df3e2d68a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java @@ -34,12 +34,11 @@ class ComponentDtoToWsComponent { } static Component.Builder componentDtoToWsComponent(ComponentDto component, Map measuresByMetric, - Map referenceComponentsByUuid) { + Map referenceComponentsByUuid) { Component.Builder wsComponent = componentDtoToWsComponent(component); ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid()); if (referenceComponent != null) { - wsComponent.setRefId(referenceComponent.uuid()); wsComponent.setRefKey(referenceComponent.getDbKey()); } @@ -55,7 +54,6 @@ class ComponentDtoToWsComponent { static Component.Builder componentDtoToWsComponent(ComponentDto component) { Component.Builder wsComponent = Component.newBuilder() - .setId(component.uuid()) .setKey(component.getKey()) .setName(component.name()) .setQualifier(component.qualifier()); 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 bee959acf91..cbd139a13b7 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 @@ -79,16 +79,12 @@ import static java.util.Collections.emptyMap; import static org.sonar.api.measures.Metric.ValueType.DATA; import static org.sonar.api.measures.Metric.ValueType.DISTRIB; import static org.sonar.api.utils.Paging.offset; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; 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.BASE_COMPONENT_ID_AND_KEY; import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_COMPONENT_TREE; import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_METRICS; import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIOD; import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_ADDITIONAL_PERIODS; -import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; -import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_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; @@ -109,8 +105,8 @@ import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeri 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.WsParameterBuilder.createQualifiersParameter; import static org.sonar.server.ws.WsUtils.writeProtobuf; /** @@ -162,7 +158,7 @@ public class ComponentTreeAction implements MeasuresWsAction { private final ResourceTypes resourceTypes; public ComponentTreeAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, I18n i18n, - ResourceTypes resourceTypes) { + ResourceTypes resourceTypes) { this.dbClient = dbClient; this.componentFinder = componentFinder; this.userSession = userSession; @@ -173,22 +169,26 @@ public class ComponentTreeAction implements MeasuresWsAction { @Override 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.
" + + .setDescription(format("Navigate through components based on the chosen strategy with specified measures.
" + "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)) + "When limiting search with the %s parameter, directories are not returned.", Param.TEXT_QUERY)) .setResponseExample(getClass().getResource("component_tree-example.json")) .setSince("5.4") .setHandler(this) .addPagingParams(100, MAX_SIZE) .setChangelog( + new Change("8.8", "parameter 'component' is now required"), + new Change("8.8", "deprecated parameter 'baseComponentId' has been removed"), + new Change("8.8", "deprecated parameter 'baseComponentKey' has been removed."), + new Change("8.8", "deprecated response field 'id' has been removed"), + new Change("8.8", "deprecated response field 'refId' has been removed."), new Change("8.1", "the response field periods under measures field is deprecated. Use period instead."), new Change("8.1", "the response field periods is deprecated. Use period instead."), new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), new Change("7.2", "field 'bestValue' is added to the response"), new Change("6.3", format("Number of metric keys is limited to %s", MAX_METRIC_KEYS)), - new Change("6.6", "the response field id is deprecated. Use key instead."), - new Change("6.6", "the response field refId is deprecated. Use refKey instead.")); + new Change("6.6", "the response field 'id' is deprecated. Use 'key' instead."), + new Change("6.6", "the response field 'refId' is deprecated. Use 'refKey' instead.")); action.createSortParams(SORTS, NAME_SORT, true) .setDescription("Comma-separated list of sort fields") @@ -202,15 +202,10 @@ public class ComponentTreeAction implements MeasuresWsAction { .setMinimumLength(QUERY_MINIMUM_LENGTH) .setExampleValue("FILE_NAM"); - action.createParam(DEPRECATED_PARAM_BASE_COMPONENT_ID) - .setDescription("Base component id. The search is based on this component.") - .setExampleValue(UUID_EXAMPLE_02) - .setDeprecatedSince("6.6"); - action.createParam(PARAM_COMPONENT) + .setRequired(true) .setDescription("Component key. The search is based on this component.") - .setExampleValue(KEY_PROJECT_EXAMPLE_001) - .setDeprecatedKey(DEPRECATED_PARAM_BASE_COMPONENT_KEY, "6.6"); + .setExampleValue(KEY_PROJECT_EXAMPLE_001); action.createParam(PARAM_BRANCH) .setDescription("Branch key. Not available in the community edition.") @@ -342,8 +337,7 @@ public class ComponentTreeAction implements MeasuresWsAction { List metricKeys = request.mandatoryParamAsStrings(PARAM_METRIC_KEYS); checkArgument(metricKeys.size() <= MAX_METRIC_KEYS, "Number of metrics keys is limited to %s, got %s", MAX_METRIC_KEYS, metricKeys.size()); ComponentTreeRequest componentTreeRequest = new ComponentTreeRequest() - .setBaseComponentId(request.param(DEPRECATED_PARAM_BASE_COMPONENT_ID)) - .setComponent(request.param(PARAM_COMPONENT)) + .setComponent(request.mandatoryParam(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)) .setMetricKeys(metricKeys) @@ -375,11 +369,10 @@ public class ComponentTreeAction implements MeasuresWsAction { } private static Measures.Component.Builder toWsComponent(ComponentDto component, Map measures, - Map referenceComponentsByUuid) { + Map referenceComponentsByUuid) { Measures.Component.Builder wsComponent = componentDtoToWsComponent(component); ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid()); if (referenceComponent != null) { - wsComponent.setRefId(referenceComponent.uuid()); wsComponent.setRefKey(referenceComponent.getKey()); } Measures.Measure.Builder measureBuilder = Measures.Measure.newBuilder(); @@ -447,16 +440,12 @@ public class ComponentTreeAction implements MeasuresWsAction { } private ComponentDto loadComponent(DbSession dbSession, ComponentTreeRequest 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'", - DEPRECATED_PARAM_BASE_COMPONENT_ID, PARAM_BRANCH, PARAM_PULL_REQUEST); if (branch == null && pullRequest == null) { - return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, BASE_COMPONENT_ID_AND_KEY); + return componentFinder.getByKey(dbSession, componentKey); } - checkRequest(componentKey != null, "The '%s' parameter is missing", PARAM_COMPONENT); return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest); } @@ -501,7 +490,7 @@ public class ComponentTreeAction implements MeasuresWsAction { } private Table searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent, - ComponentTreeQuery componentTreeQuery, List components, List metrics) { + ComponentTreeQuery componentTreeQuery, List components, List metrics) { Map metricsByUuid = Maps.uniqueIndex(metrics, MetricDto::getUuid); MeasureTreeQuery measureQuery = MeasureTreeQuery.builder() @@ -533,7 +522,7 @@ public class ComponentTreeAction implements MeasuresWsAction { * */ private static void addBestValuesToMeasures(Table measuresByComponentUuidAndMetric, List components, - List metrics) { + List metrics) { List metricDtosWithBestValueMeasure = metrics.stream() .filter(MetricDtoFunctions.isOptimizedForBestValue()) .map(new MetricDtoToMetricDtoWithBestValue()) @@ -554,7 +543,7 @@ public class ComponentTreeAction implements MeasuresWsAction { } private static List filterComponents(List components, - Table measuresByComponentUuidAndMetric, List metrics, ComponentTreeRequest wsRequest) { + Table measuresByComponentUuidAndMetric, List metrics, ComponentTreeRequest wsRequest) { if (!componentWithMeasuresOnly(wsRequest)) { return components; } @@ -574,7 +563,7 @@ public class ComponentTreeAction implements MeasuresWsAction { } private static List sortComponents(List components, ComponentTreeRequest wsRequest, List metrics, - Table measuresByComponentUuidAndMetric) { + Table measuresByComponentUuidAndMetric) { return ComponentTreeSort.sortComponents(components, wsRequest, metrics, measuresByComponentUuidAndMetric); } 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 07a4445baa4..7a6cdecd4ae 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 @@ -24,8 +24,6 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; class ComponentTreeRequest { - - private String baseComponentId; private String component; private String branch; private String pullRequest; @@ -42,30 +40,11 @@ class ComponentTreeRequest { private Integer page; private Integer pageSize; - /** - * @deprecated since 6.6, please use {@link #getComponent()} instead - */ - @Deprecated - @CheckForNull - public String getBaseComponentId() { - return baseComponentId; - } - - /** - * @deprecated since 6.6, please use {@link #setComponent(String)} instead - */ - @Deprecated - public ComponentTreeRequest setBaseComponentId(@Nullable String baseComponentId) { - this.baseComponentId = baseComponentId; - return this; - } - - @CheckForNull public String getComponent() { return component; } - public ComponentTreeRequest setComponent(@Nullable String component) { + public ComponentTreeRequest setComponent(String component) { this.component = component; return this; } 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 7401d923665..95b01f6383c 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 @@ -225,7 +225,7 @@ public class ComponentActionTest { } @Test - public void reference_uuid_in_the_response() { + public void reference_key_in_the_response() { userSession.logIn().setRoot(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto view = db.components().insertPrivatePortfolio(); @@ -235,22 +235,9 @@ public class ComponentActionTest { ComponentWsResponse response = newRequest(projectCopy.getKey(), metric.getKey()); - assertThat(response.getComponent().getRefId()).isEqualTo(project.uuid()); assertThat(response.getComponent().getRefKey()).isEqualTo(project.getKey()); } - @Test - public void return_deprecated_id_in_the_response() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(UserRole.USER, project); - db.components().insertSnapshot(project); - MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); - - ComponentWsResponse response = newRequest(project.getKey(), metric.getKey()); - - assertThat(response.getComponent().getId()).isEqualTo(project.uuid()); - } - @Test public void use_deprecated_component_id_parameter() { ComponentDto project = db.components().insertPrivateProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 40c62df3dc4..ace3cf74fec 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -76,8 +76,6 @@ import static org.sonar.db.component.ComponentTesting.newProjectCopy; import static org.sonar.db.component.SnapshotTesting.newAnalysis; import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIOD; import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_ADDITIONAL_PERIODS; -import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; -import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_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; @@ -353,15 +351,15 @@ public class ComponentTreeActionTest { public void load_measures_multi_sort_with_metric_key_and_paginated() { ComponentDto project = db.components().insertPrivateProject(); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file9 = db.components().insertComponent(newFileDto(project, null, "file-uuid-9").setName("file-1")); - ComponentDto file8 = db.components().insertComponent(newFileDto(project, null, "file-uuid-8").setName("file-1")); - ComponentDto file7 = db.components().insertComponent(newFileDto(project, null, "file-uuid-7").setName("file-1")); - ComponentDto file6 = db.components().insertComponent(newFileDto(project, null, "file-uuid-6").setName("file-1")); - ComponentDto file5 = db.components().insertComponent(newFileDto(project, null, "file-uuid-5").setName("file-1")); - ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setName("file-1")); - ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setName("file-1")); - ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setName("file-1")); - ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setName("file-1")); + ComponentDto file9 = db.components().insertComponent(newFileDto(project, null, "file-uuid-9").setName("file-1").setDbKey("file-9-key")); + ComponentDto file8 = db.components().insertComponent(newFileDto(project, null, "file-uuid-8").setName("file-1").setDbKey("file-8-key")); + ComponentDto file7 = db.components().insertComponent(newFileDto(project, null, "file-uuid-7").setName("file-1").setDbKey("file-7-key")); + ComponentDto file6 = db.components().insertComponent(newFileDto(project, null, "file-uuid-6").setName("file-1").setDbKey("file-6-key")); + ComponentDto file5 = db.components().insertComponent(newFileDto(project, null, "file-uuid-5").setName("file-1").setDbKey("file-5-key")); + ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setName("file-1").setDbKey("file-4-key")); + ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setName("file-1").setDbKey("file-3-key")); + ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setName("file-1").setDbKey("file-2-key")); + ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setName("file-1").setDbKey("file-1-key")); MetricDto coverage = insertCoverageMetric(); db.commit(); db.measures().insertLiveMeasure(file1, coverage, m -> m.setValue(1.0d)); @@ -385,7 +383,7 @@ public class ComponentTreeActionTest { .setParam(Param.PAGE_SIZE, "3") .executeProtobuf(ComponentTreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-4", "file-uuid-5", "file-uuid-6"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("file-4-key", "file-5-key", "file-6-key"); assertThat(response.getPaging().getPageIndex()).isEqualTo(2); assertThat(response.getPaging().getPageSize()).isEqualTo(3); assertThat(response.getPaging().getTotal()).isEqualTo(9); @@ -395,10 +393,10 @@ public class ComponentTreeActionTest { public void sort_by_metric_value() { ComponentDto project = db.components().insertPrivateProject(); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4")); - ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3")); - ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1")); - ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2")); + ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setDbKey("file-4-key")); + ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key")); + ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key")); + ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key")); MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); db.commit(); @@ -413,7 +411,7 @@ public class ComponentTreeActionTest { .setParam(PARAM_METRIC_KEYS, "ncloc") .executeProtobuf(ComponentTreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3", "file-uuid-4"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("file-1-key", "file-2-key", "file-3-key", "file-4-key"); assertThat(response.getPaging().getTotal()).isEqualTo(4); } @@ -421,10 +419,10 @@ public class ComponentTreeActionTest { public void remove_components_without_measure_on_the_metric_sort() { ComponentDto project = db.components().insertPrivateProject(); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file1 = newFileDto(project, null, "file-uuid-1"); - ComponentDto file2 = newFileDto(project, null, "file-uuid-2"); - ComponentDto file3 = newFileDto(project, null, "file-uuid-3"); - ComponentDto file4 = newFileDto(project, null, "file-uuid-4"); + ComponentDto file1 = newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key"); + ComponentDto file2 = newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key"); + ComponentDto file3 = newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key"); + ComponentDto file4 = newFileDto(project, null, "file-uuid-4").setDbKey("file-4-key"); db.components().insertComponent(file1); db.components().insertComponent(file2); db.components().insertComponent(file3); @@ -446,9 +444,9 @@ public class ComponentTreeActionTest { .setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER) .executeProtobuf(ComponentTreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id") - .containsExactly(file1.uuid(), file2.uuid(), file3.uuid()) - .doesNotContain(file4.uuid()); + assertThat(response.getComponentsList()).extracting("key") + .containsExactly(file1.getKey(), file2.getKey(), file3.getKey()) + .doesNotContain(file4.getKey()); assertThat(response.getPaging().getTotal()).isEqualTo(3); } @@ -456,9 +454,9 @@ public class ComponentTreeActionTest { public void sort_by_metric_period() { ComponentDto project = db.components().insertPrivateProject(); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3")); - ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1")); - ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2")); + ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key")); + ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key")); + ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key")); MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); db.commit(); @@ -474,17 +472,17 @@ public class ComponentTreeActionTest { .setParam(PARAM_METRIC_PERIOD_SORT, "1") .executeProtobuf(ComponentTreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3"); + assertThat(response.getComponentsList()).extracting("key").containsExactly("file-1-key", "file-2-key", "file-3-key"); } @Test public void remove_components_without_measure_on_the_metric_period_sort() { ComponentDto project = db.components().insertPrivateProject(); SnapshotDto projectSnapshot = db.components().insertSnapshot(project); - ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4")); - ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3")); - ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2")); - ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1")); + ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setDbKey("file-4-key")); + ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key")); + ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key")); + ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key")); MetricDto ncloc = newMetricDto().setKey("new_ncloc").setValueType(INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(null).setVariation(1.0d)); @@ -503,9 +501,9 @@ public class ComponentTreeActionTest { .setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER) .executeProtobuf(ComponentTreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id") - .containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3") - .doesNotContain("file-uuid-4"); + assertThat(response.getComponentsList()).extracting("key") + .containsExactly("file-1-key", "file-2-key", "file-3-key") + .doesNotContain("file-4-key"); } @Test @@ -619,52 +617,6 @@ public class ComponentTreeActionTest { .isEmpty(); } - @Test - public void return_deprecated_id_in_the_response() { - ComponentDto project = db.components().insertPrivateProject(); - SnapshotDto analysis = db.components().insertSnapshot(project); - ComponentDto file = db.components().insertComponent(newFileDto(project)); - MetricDto ncloc = insertNclocMetric(); - db.measures().insertLiveMeasure(file, ncloc, m -> m.setValue(2d)); - - ComponentTreeWsResponse response = ws.newRequest() - .setParam(PARAM_COMPONENT, project.getKey()) - .setParam(PARAM_METRIC_KEYS, ncloc.getKey()) - .executeProtobuf(ComponentTreeWsResponse.class); - - assertThat(response.getBaseComponent().getId()).isEqualTo(project.uuid()); - assertThat(response.getComponentsList()).extracting(Component::getId) - .containsExactlyInAnyOrder(file.uuid()); - } - - @Test - public void use_deprecated_base_component_id_parameter() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(USER, project); - insertNclocMetric(); - - ComponentTreeWsResponse response = ws.newRequest() - .setParam("baseComponentId", project.uuid()) - .setParam(PARAM_METRIC_KEYS, "ncloc") - .executeProtobuf(ComponentTreeWsResponse.class); - - assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getKey()); - } - - @Test - public void use_deprecated_base_component_key_parameter() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(USER, project); - insertNclocMetric(); - - ComponentTreeWsResponse response = ws.newRequest() - .setParam("baseComponentKey", project.getKey()) - .setParam(PARAM_METRIC_KEYS, "ncloc") - .executeProtobuf(ComponentTreeWsResponse.class); - - assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getKey()); - } - @Test public void metric_without_a_domain() { ComponentDto project = db.components().insertPrivateProject(); @@ -701,8 +653,8 @@ public class ComponentTreeActionTest { .executeProtobuf(ComponentTreeWsResponse.class); assertThat(result.getComponentsList()) - .extracting(Component::getKey, Component::getRefId, Component::getRefKey) - .containsExactlyInAnyOrder(tuple(projectCopy.getKey(), project.uuid(), project.getKey())); + .extracting(Component::getKey, Component::getRefKey) + .containsExactlyInAnyOrder(tuple(projectCopy.getKey(), project.getKey())); } @Test @@ -728,8 +680,8 @@ public class ComponentTreeActionTest { .extracting(Component::getKey, Component::getBranch) .containsExactlyInAnyOrder(applicationBranch.getKey(), applicationBranch.getBranch()); assertThat(result.getComponentsList()) - .extracting(Component::getKey, Component::getBranch, Component::getRefId, Component::getRefKey) - .containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), projectBranch.getBranch(), projectBranch.uuid(), project.getKey())); + .extracting(Component::getKey, Component::getBranch, Component::getRefKey) + .containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), projectBranch.getBranch(), project.getKey())); } @Test @@ -933,7 +885,7 @@ public class ComponentTreeActionTest { expectedException.expectMessage("Component key 'project-key' not found"); ws.newRequest() - .setParam(DEPRECATED_PARAM_BASE_COMPONENT_KEY, "project-key") + .setParam(PARAM_COMPONENT, "project-key") .setParam(PARAM_METRIC_KEYS, "ncloc") .execute(); } @@ -988,22 +940,6 @@ public class ComponentTreeActionTest { .execute(); } - @Test - public void fail_when_using_branch_uuid() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - insertNclocMetric(); - - expectedException.expect(NotFoundException.class); - expectedException.expectMessage(format("Component id '%s' not found", branch.uuid())); - - ws.newRequest() - .setParam(DEPRECATED_PARAM_BASE_COMPONENT_ID, branch.uuid()) - .setParam(PARAM_METRIC_KEYS, "ncloc") - .execute(); - } - private static MetricDto newMetricDto() { return MetricTesting.newMetricDto() .setWorstValue(null) diff --git a/sonar-ws/src/main/protobuf/ws-measures.proto b/sonar-ws/src/main/protobuf/ws-measures.proto index 17d7c0c866c..ebe34f594a3 100644 --- a/sonar-ws/src/main/protobuf/ws-measures.proto +++ b/sonar-ws/src/main/protobuf/ws-measures.proto @@ -68,9 +68,8 @@ message SearchHistoryResponse { } message Component { - optional string id = 1; + reserved 1,3; optional string key = 2; - optional string refId = 3; optional string refKey = 4; optional string projectId = 5; optional string name = 6;