]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9682 Clean component parameters in api/measures/component_tree
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 4 Aug 2017 04:09:24 +0000 (06:09 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 08:55:10 +0000 (10:55 +0200)
- deprecate baseComponentId
- rename baseComponentKey to component
- deprecate id in response

server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java
server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeWsRequest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java
sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java
sonar-ws/src/test/java/org/sonarqube/ws/client/measure/MeasuresServiceTest.java

index 4efe151b8a4318947b77b880703923105435b207..b3e3c5b5ae63f105853e4d6537e82846945dcd45 100644 (file)
@@ -62,9 +62,10 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT_TREE;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_METRICS;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_KEY;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS;
@@ -132,12 +133,15 @@ public class ComponentTreeAction implements MeasuresWsAction {
       .setDescription(format("Navigate through components based on the chosen strategy with specified measures. The %s or the %s parameter must be provided.<br>" +
         "Requires the following permission: 'Browse' on the specified project.<br>" +
         "When limiting search with the %s parameter, directories are not returned.",
-        PARAM_BASE_COMPONENT_ID, PARAM_BASE_COMPONENT_KEY, Param.TEXT_QUERY))
+        DEPRECATED_PARAM_BASE_COMPONENT_ID, PARAM_COMPONENT, Param.TEXT_QUERY))
       .setResponseExample(getClass().getResource("component_tree-example.json"))
       .setSince("5.4")
       .setHandler(this)
       .addPagingParams(100, MAX_SIZE)
-      .setChangelog(new Change("6.3", format("Number of metric keys is limited to %s", MAX_METRIC_KEYS)));
+      .setChangelog(
+        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."));
 
     action.createSortParams(SORTS, NAME_SORT, true)
       .setDescription("Comma-separated list of sort fields")
@@ -151,13 +155,15 @@ public class ComponentTreeAction implements MeasuresWsAction {
         "Must have at least %d characters.", QUERY_MINIMUM_LENGTH))
       .setExampleValue("FILE_NAM");
 
-    action.createParam(PARAM_BASE_COMPONENT_ID)
+    action.createParam(DEPRECATED_PARAM_BASE_COMPONENT_ID)
       .setDescription("Base component id. The search is based on this component.")
-      .setExampleValue(UUID_EXAMPLE_02);
+      .setExampleValue(UUID_EXAMPLE_02)
+      .setDeprecatedSince("6.6");
 
-    action.createParam(PARAM_BASE_COMPONENT_KEY)
-      .setDescription("Base component key. The search is based on this component.")
-      .setExampleValue(KEY_PROJECT_EXAMPLE_001);
+    action.createParam(PARAM_COMPONENT)
+      .setDescription("Component key. The search is based on this component.")
+      .setExampleValue(KEY_PROJECT_EXAMPLE_001)
+      .setDeprecatedKey(DEPRECATED_PARAM_BASE_COMPONENT_KEY, "6.6");
 
     action.createParam(PARAM_METRIC_SORT)
       .setDescription(
@@ -275,8 +281,8 @@ public class ComponentTreeAction implements MeasuresWsAction {
     List<String> 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());
     ComponentTreeWsRequest componentTreeWsRequest = new ComponentTreeWsRequest()
-      .setBaseComponentId(request.param(PARAM_BASE_COMPONENT_ID))
-      .setBaseComponentKey(request.param(PARAM_BASE_COMPONENT_KEY))
+      .setBaseComponentId(request.param(DEPRECATED_PARAM_BASE_COMPONENT_ID))
+      .setComponent(request.param(PARAM_COMPONENT))
       .setMetricKeys(metricKeys)
       .setStrategy(request.mandatoryParam(PARAM_STRATEGY))
       .setQualifiers(request.paramAsStrings(PARAM_QUALIFIERS))
index 1eb6457d052d18d16d36177e81c535f247accefc..b454bebd4fa6df938c8733702dc35255a5aed43f 100644 (file)
@@ -93,7 +93,7 @@ public class ComponentTreeDataLoader {
 
   ComponentTreeData load(ComponentTreeWsRequest wsRequest) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, wsRequest.getBaseComponentId(), wsRequest.getBaseComponentKey(), BASE_COMPONENT_ID_AND_KEY);
+      ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, wsRequest.getBaseComponentId(), wsRequest.getComponent(), BASE_COMPONENT_ID_AND_KEY);
       checkPermissions(baseComponent);
       Optional<SnapshotDto> baseSnapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, baseComponent.projectUuid());
       if (!baseSnapshot.isPresent()) {
index ed469dcd456f9a53fa2258516c5c33a47d11b343..701f30a397005d83a57365176c282e41440bf909 100644 (file)
@@ -5,7 +5,6 @@
     "total": 3
   },
   "baseComponent": {
-    "id": "project-id",
     "key": "MY_PROJECT",
     "name": "My Project",
     "qualifier": "TRK",
@@ -31,7 +30,6 @@
   },
   "components": [
     {
-      "id": "AVIwDXE-bJbJqrw6wFv5",
       "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java",
       "name": "ElementImpl.java",
       "qualifier": "FIL",
@@ -58,7 +56,6 @@
       ]
     },
     {
-      "id": "AVIwDXE_bJbJqrw6wFwJ",
       "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java",
       "name": "ElementImplTest.java",
       "qualifier": "UTS",
@@ -77,7 +74,6 @@
       ]
     },
     {
-      "id": "AVIwDXE-bJbJqrw6wFv8",
       "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl",
       "name": "src/main/java/com/sonarsource/markdown/impl",
       "qualifier": "DIR",
index c4ff5c7957ce8aa223570ad79465c94cd9adf507..b9f233b5693b707f56cd97634d9cf44e7879157f 100644 (file)
@@ -52,6 +52,7 @@ import org.sonarqube.ws.Common;
 import org.sonarqube.ws.WsMeasures;
 import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse;
 
+import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY;
@@ -59,7 +60,9 @@ import static org.sonar.api.measures.Metric.ValueType.DISTRIB;
 import static org.sonar.api.measures.Metric.ValueType.FLOAT;
 import static org.sonar.api.measures.Metric.ValueType.INT;
 import static org.sonar.api.measures.Metric.ValueType.RATING;
+import static org.sonar.api.server.ws.WebService.Param.SORT;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
+import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
@@ -73,9 +76,9 @@ import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT;
 import static org.sonar.server.measure.ws.ComponentTreeAction.WITH_MEASURES_ONLY_METRIC_SORT_FILTER;
 import static org.sonar.test.JsonAssert.assertJson;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_KEY;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT;
@@ -111,10 +114,63 @@ public class ComponentTreeActionTest {
 
   @Test
   public void json_example() {
-    insertJsonExampleData();
+    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT")
+      .setName("My Project"));
+    SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
+      .setPeriodMode("previous_version")
+      .setPeriodParam("1.0-SNAPSHOT"));
+    ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null)
+      .setUuid("AVIwDXE-bJbJqrw6wFv5")
+      .setDbKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java")
+      .setName("ElementImpl.java")
+      .setLanguage("java")
+      .setQualifier(Qualifiers.FILE)
+      .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"));
+    ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null)
+      .setUuid("AVIwDXE_bJbJqrw6wFwJ")
+      .setDbKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java")
+      .setName("ElementImplTest.java")
+      .setLanguage("java")
+      .setQualifier(Qualifiers.UNIT_TEST_FILE)
+      .setPath("src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java"));
+    ComponentDto dir = componentDb.insertComponent(newDirectory(project, "src/main/java/com/sonarsource/markdown/impl")
+      .setUuid("AVIwDXE-bJbJqrw6wFv8")
+      .setDbKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl")
+      .setQualifier(Qualifiers.DIRECTORY));
+
+    MetricDto complexity = insertComplexityMetric();
+    dbClient.measureDao().insert(dbSession,
+      newMeasureDto(complexity, file1, analysis)
+        .setValue(12.0d),
+      newMeasureDto(complexity, dir, analysis)
+        .setValue(35.0d)
+        .setVariation(0.0d),
+      newMeasureDto(complexity, project, analysis)
+        .setValue(42.0d));
+
+    MetricDto ncloc = insertNclocMetric();
+    dbClient.measureDao().insert(dbSession,
+      newMeasureDto(ncloc, file1, analysis)
+        .setValue(114.0d),
+      newMeasureDto(ncloc, dir, analysis)
+        .setValue(217.0d)
+        .setVariation(0.0d),
+      newMeasureDto(ncloc, project, analysis)
+        .setValue(1984.0d));
+
+    MetricDto newViolations = insertNewViolationsMetric();
+    dbClient.measureDao().insert(dbSession,
+      newMeasureDto(newViolations, file1, analysis)
+        .setVariation(25.0d),
+      newMeasureDto(newViolations, dir, analysis)
+        .setVariation(25.0d),
+      newMeasureDto(newViolations, project, analysis)
+        .setVariation(255.0d));
+
+    db.commit();
 
     String response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-id")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc, complexity, new_violations")
       .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods")
       .execute()
@@ -125,14 +181,14 @@ public class ComponentTreeActionTest {
 
   @Test
   public void empty_response() {
-    componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc, complexity")
       .executeProtobuf(ComponentTreeWsResponse.class);
 
-    assertThat(response.getBaseComponent().getId()).isEqualTo("project-uuid");
+    assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getKey());
     assertThat(response.getComponentsList()).isEmpty();
     assertThat(response.getMetrics().getMetricsList()).isEmpty();
     assertThat(response.getPeriods().getPeriodsList()).isEmpty();
@@ -140,15 +196,14 @@ public class ComponentTreeActionTest {
 
   @Test
   public void load_measures_and_periods() {
-    ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
-    componentDb.insertComponent(projectDto);
+    ComponentDto project = db.components().insertPrivateProject();
     SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession,
-      newAnalysis(projectDto)
+      newAnalysis(project)
         .setPeriodDate(System.currentTimeMillis())
         .setPeriodMode("last_version")
         .setPeriodDate(System.currentTimeMillis()));
-    userSession.anonymous().addProjectPermission(UserRole.USER, projectDto);
-    ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1");
+    userSession.anonymous().addProjectPermission(UserRole.USER, project);
+    ComponentDto directoryDto = newDirectory(project, "directory-uuid", "path/to/directory").setName("directory-1");
     componentDb.insertComponent(directoryDto);
     ComponentDto file = newFileDto(directoryDto, null, "file-uuid").setName("file-1");
     componentDb.insertComponent(file);
@@ -161,7 +216,7 @@ public class ComponentTreeActionTest {
     db.commit();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc,coverage")
       .setParam(PARAM_ADDITIONAL_FIELDS, ADDITIONAL_PERIODS)
       .executeProtobuf(ComponentTreeWsResponse.class);
@@ -176,10 +231,10 @@ public class ComponentTreeActionTest {
 
   @Test
   public void load_measures_with_best_value() {
-    ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
-    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
-    userSession.anonymous().addProjectPermission(UserRole.USER, projectDto);
-    ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1");
+    ComponentDto project = db.components().insertPrivateProject();
+    SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
+    userSession.anonymous().addProjectPermission(UserRole.USER, project);
+    ComponentDto directoryDto = newDirectory(project, "directory-uuid", "path/to/directory").setName("directory-1");
     componentDb.insertComponent(directoryDto);
     ComponentDto file = newFileDto(directoryDto, null, "file-uuid").setName("file-1");
     componentDb.insertComponent(file);
@@ -201,7 +256,7 @@ public class ComponentTreeActionTest {
     db.commit();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc,coverage,new_violations")
       .setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
       .executeProtobuf(ComponentTreeWsResponse.class);
@@ -220,14 +275,13 @@ public class ComponentTreeActionTest {
 
   @Test
   public void use_best_value_for_rating() {
-    ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
-    userSession.anonymous().addProjectPermission(UserRole.USER, projectDto);
-    componentDb.insertComponent(projectDto);
-    SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(projectDto)
+    ComponentDto project = db.components().insertPrivateProject();
+    userSession.anonymous().addProjectPermission(UserRole.USER, project);
+    SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
       .setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
       .setPeriodMode("previous_version")
       .setPeriodParam("1.0-SNAPSHOT"));
-    ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1");
+    ComponentDto directoryDto = newDirectory(project, "directory-uuid", "path/to/directory").setName("directory-1");
     componentDb.insertComponent(directoryDto);
     ComponentDto file = newFileDto(directoryDto, null, "file-uuid").setName("file-1");
     componentDb.insertComponent(file);
@@ -240,7 +294,7 @@ public class ComponentTreeActionTest {
     db.commit();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, NEW_SECURITY_RATING_KEY)
       .setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
       .executeProtobuf(ComponentTreeWsResponse.class);
@@ -253,17 +307,17 @@ public class ComponentTreeActionTest {
 
   @Test
   public void load_measures_multi_sort_with_metric_key_and_paginated() {
-    ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
-    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
-    ComponentDto file9 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-9").setName("file-1"));
-    ComponentDto file8 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-8").setName("file-1"));
-    ComponentDto file7 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-7").setName("file-1"));
-    ComponentDto file6 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-6").setName("file-1"));
-    ComponentDto file5 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-5").setName("file-1"));
-    ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4").setName("file-1"));
-    ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3").setName("file-1"));
-    ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-2").setName("file-1"));
-    ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1").setName("file-1"));
+    ComponentDto project = db.components().insertPrivateProject();
+    SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
+    ComponentDto file9 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-9").setName("file-1"));
+    ComponentDto file8 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-8").setName("file-1"));
+    ComponentDto file7 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-7").setName("file-1"));
+    ComponentDto file6 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-6").setName("file-1"));
+    ComponentDto file5 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-5").setName("file-1"));
+    ComponentDto file4 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-4").setName("file-1"));
+    ComponentDto file3 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-3").setName("file-1"));
+    ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-2").setName("file-1"));
+    ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-1").setName("file-1"));
     MetricDto coverage = insertCoverageMetric();
     dbClient.measureDao().insert(dbSession,
       newMeasureDto(coverage, file1, projectSnapshot).setValue(1.0d),
@@ -278,8 +332,8 @@ public class ComponentTreeActionTest {
     db.commit();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
-      .setParam(Param.SORT, NAME_SORT + ", " + METRIC_SORT)
+      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(SORT, NAME_SORT + ", " + METRIC_SORT)
       .setParam(PARAM_METRIC_SORT, "coverage")
       .setParam(PARAM_METRIC_KEYS, "coverage")
       .setParam(PARAM_STRATEGY, "leaves")
@@ -296,12 +350,12 @@ public class ComponentTreeActionTest {
 
   @Test
   public void sort_by_metric_value() {
-    ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
-    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
-    ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4"));
-    ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
-    ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1"));
-    ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-2"));
+    ComponentDto project = db.components().insertPrivateProject();
+    SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
+    ComponentDto file4 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-4"));
+    ComponentDto file3 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-3"));
+    ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-1"));
+    ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-2"));
     MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
     dbClient.metricDao().insert(dbSession, ncloc);
     dbClient.measureDao().insert(dbSession,
@@ -311,8 +365,8 @@ public class ComponentTreeActionTest {
     db.commit();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
-      .setParam(Param.SORT, METRIC_SORT)
+      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(SORT, METRIC_SORT)
       .setParam(PARAM_METRIC_SORT, "ncloc")
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .executeProtobuf(ComponentTreeWsResponse.class);
@@ -323,8 +377,8 @@ public class ComponentTreeActionTest {
 
   @Test
   public void remove_components_without_measure_on_the_metric_sort() {
-    ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
-    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
+    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");
@@ -344,8 +398,8 @@ public class ComponentTreeActionTest {
     db.commit();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, project.uuid())
-      .setParam(Param.SORT, METRIC_SORT)
+      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(SORT, METRIC_SORT)
       .setParam(PARAM_METRIC_SORT, "ncloc")
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER)
@@ -359,11 +413,11 @@ public class ComponentTreeActionTest {
 
   @Test
   public void sort_by_metric_period() {
-    ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
-    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
-    ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
-    ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1"));
-    ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-2"));
+    ComponentDto project = db.components().insertPrivateProject();
+    SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
+    ComponentDto file3 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-3"));
+    ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-1"));
+    ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-2"));
     MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
     dbClient.metricDao().insert(dbSession, ncloc);
     dbClient.measureDao().insert(dbSession,
@@ -373,8 +427,8 @@ public class ComponentTreeActionTest {
     db.commit();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
-      .setParam(Param.SORT, METRIC_PERIOD_SORT)
+      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(SORT, METRIC_PERIOD_SORT)
       .setParam(PARAM_METRIC_SORT, "ncloc")
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .setParam(PARAM_METRIC_PERIOD_SORT, "1")
@@ -385,12 +439,12 @@ public class ComponentTreeActionTest {
 
   @Test
   public void remove_components_without_measure_on_the_metric_period_sort() {
-    ComponentDto projectDto = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid");
-    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
-    ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4"));
-    ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
-    ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-2"));
-    ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1"));
+    ComponentDto project = db.components().insertPrivateProject();
+    SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
+    ComponentDto file4 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-4"));
+    ComponentDto file3 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-3"));
+    ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-2"));
+    ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file-uuid-1"));
     MetricDto ncloc = newMetricDto().setKey("new_ncloc").setValueType(INT.name()).setDirection(1);
     dbClient.metricDao().insert(dbSession, ncloc);
     dbClient.measureDao().insert(dbSession,
@@ -402,8 +456,8 @@ public class ComponentTreeActionTest {
     db.commit();
 
     ComponentTreeWsResponse response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
-      .setParam(Param.SORT, METRIC_PERIOD_SORT + "," + NAME_SORT)
+      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(SORT, METRIC_PERIOD_SORT + "," + NAME_SORT)
       .setParam(PARAM_METRIC_SORT, "new_ncloc")
       .setParam(PARAM_METRIC_KEYS, "new_ncloc")
       .setParam(PARAM_METRIC_PERIOD_SORT, "1")
@@ -418,22 +472,67 @@ public class ComponentTreeActionTest {
   @Test
   public void load_measures_when_no_leave_qualifier() {
     resourceTypes.setLeavesQualifiers();
-    String projectUuid = "project-uuid";
-    ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), projectUuid);
-    componentDb.insertProjectAndSnapshot(project);
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     componentDb.insertComponent(newFileDto(project, null));
     insertNclocMetric();
 
     ComponentTreeWsResponse result = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, projectUuid)
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_STRATEGY, LEAVES_STRATEGY)
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .executeProtobuf(ComponentTreeWsResponse.class);
 
-    assertThat(result.getBaseComponent().getId()).isEqualTo(projectUuid);
+    assertThat(result.getBaseComponent().getKey()).isEqualTo(project.getKey());
     assertThat(result.getComponentsCount()).isEqualTo(0);
   }
 
+  @Test
+  public void return_deprecated_id_in_the_response() {
+    ComponentDto project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(project);
+    ComponentDto file = componentDb.insertComponent(newFileDto(project));
+    MetricDto ncloc = insertNclocMetric();
+    db.measures().insertMeasure(file, analysis, 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(WsMeasures.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();
@@ -444,7 +543,7 @@ public class ComponentTreeActionTest {
     db.measures().insertMeasure(project, analysis, metricWithoutDomain);
 
     ComponentTreeWsResponse result = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_KEY, project.getKey())
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, metricWithoutDomain.getKey())
       .setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
       .executeProtobuf(ComponentTreeWsResponse.class);
@@ -465,7 +564,7 @@ public class ComponentTreeActionTest {
     db.measures().insertMeasure(projectCopy, viewAnalysis, ncloc, m -> m.setValue(5d));
 
     ComponentTreeWsResponse result = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_KEY, view.getKey())
+      .setParam(PARAM_COMPONENT, view.getKey())
       .setParam(PARAM_METRIC_KEYS, ncloc.getKey())
       .executeProtobuf(ComponentTreeWsResponse.class);
 
@@ -476,33 +575,36 @@ public class ComponentTreeActionTest {
 
   @Test
   public void fail_when_metric_keys_parameter_is_empty() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("The 'metricKeys' parameter must contain at least one metric key");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "")
       .executeProtobuf(ComponentTreeWsResponse.class);
   }
 
   @Test
   public void fail_when_a_metric_is_not_found() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     insertNclocMetric();
     insertNewViolationsMetric();
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("The following metric keys are not found: unknown-metric, another-unknown-metric");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc, new_violations, unknown-metric, another-unknown-metric").executeProtobuf(ComponentTreeWsResponse.class);
   }
 
   @Test
   public void fail_when_using_DISTRIB_metrics() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     dbClient.metricDao().insert(dbSession, newMetricDto().setKey("distrib1").setValueType(DISTRIB.name()));
     dbClient.metricDao().insert(dbSession, newMetricDto().setKey("distrib2").setValueType(DISTRIB.name()));
     db.commit();
@@ -511,14 +613,16 @@ public class ComponentTreeActionTest {
     expectedException.expectMessage("Metrics distrib1, distrib2 can't be requested in this web service. Please use api/measures/component");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "distrib1,distrib2")
       .execute();
   }
 
   @Test
   public void fail_when_using_DATA_metrics() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
+
     dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data1").setValueType(DISTRIB.name()));
     dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data2").setValueType(DISTRIB.name()));
     db.commit();
@@ -527,14 +631,15 @@ public class ComponentTreeActionTest {
     expectedException.expectMessage("Metrics data1, data2 can't be requested in this web service. Please use api/measures/component");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "data1,data2")
       .execute();
   }
 
   @Test
   public void fail_when_setting_more_than_15_metric_keys() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     List<String> metrics = IntStream.range(0, 20)
       .mapToObj(i -> "metric" + i)
       .collect(MoreCollectors.toList());
@@ -544,21 +649,22 @@ public class ComponentTreeActionTest {
     expectedException.expectMessage("'metricKeys' can contains only 15 values, got 20");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, Joiner.on(",").join(metrics))
       .execute();
   }
 
   @Test
   public void fail_when_search_query_have_less_than_3_characters() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     insertNclocMetric();
     insertNewViolationsMetric();
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("The 'q' parameter must have at least 3 characters");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc, new_violations")
       .setParam(Param.TEXT_QUERY, "fi")
       .executeProtobuf(ComponentTreeWsResponse.class);
@@ -567,68 +673,77 @@ public class ComponentTreeActionTest {
   @Test
   public void fail_when_insufficient_privileges() {
     userSession.logIn();
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
+
     expectedException.expect(ForbiddenException.class);
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .executeProtobuf(ComponentTreeWsResponse.class);
   }
 
   @Test
   public void fail_when_sort_by_metric_and_no_metric_sort_provided() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     expectedException.expect(BadRequestException.class);
     expectedException
       .expectMessage("To sort by a metric, the 's' parameter must contain 'metric' or 'metricPeriod', and a metric key must be provided in the 'metricSort' parameter");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       // PARAM_METRIC_SORT is not set
-      .setParam(Param.SORT, METRIC_SORT)
+      .setParam(SORT, METRIC_SORT)
       .executeProtobuf(ComponentTreeWsResponse.class);
   }
 
   @Test
   public void fail_when_sort_by_metric_and_not_in_the_list_of_metric_keys() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
+
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("To sort by the 'complexity' metric, it must be in the list of metric keys in the 'metricKeys' parameter");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc,violations")
       .setParam(PARAM_METRIC_SORT, "complexity")
-      .setParam(Param.SORT, METRIC_SORT)
+      .setParam(SORT, METRIC_SORT)
       .executeProtobuf(ComponentTreeWsResponse.class);
   }
 
   @Test
   public void fail_when_sort_by_metric_period_and_no_metric_period_sort_provided() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
+
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("To sort by a metric period, the 's' parameter must contain 'metricPeriod' and the 'metricPeriodSort' must be provided.");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .setParam(PARAM_METRIC_SORT, "ncloc")
       // PARAM_METRIC_PERIOD_SORT_IS_NOT_SET
-      .setParam(Param.SORT, METRIC_PERIOD_SORT)
+      .setParam(SORT, METRIC_PERIOD_SORT)
       .executeProtobuf(ComponentTreeWsResponse.class);
   }
 
   @Test
   public void fail_when_paging_parameter_is_too_big() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     insertNclocMetric();
+
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("The 'ps' parameter must be less than 500");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .setParam(Param.PAGE_SIZE, "2540")
       .executeProtobuf(ComponentTreeWsResponse.class);
@@ -636,14 +751,16 @@ public class ComponentTreeActionTest {
 
   @Test
   public void fail_when_with_measures_only_and_no_metric_sort() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     insertNclocMetric();
+
     expectedException.expect(BadRequestException.class);
     expectedException
       .expectMessage("To filter components based on the sort metric, the 's' parameter must contain 'metric' or 'metricPeriod' and the 'metricSort' parameter must be provided");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER)
       .executeProtobuf(ComponentTreeWsResponse.class);
@@ -657,23 +774,24 @@ public class ComponentTreeActionTest {
     expectedException.expectMessage("Component key 'project-key' not found");
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_KEY, "project-key")
+      .setParam(DEPRECATED_PARAM_BASE_COMPONENT_KEY, "project-key")
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .execute();
   }
 
   @Test
   public void fail_when_component_is_removed() {
-    ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization()));
-    componentDb.insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
+    ComponentDto file = componentDb.insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false));
     userSession.anonymous().addProjectPermission(UserRole.USER, project);
     insertNclocMetric();
 
     expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("Component key 'file-key' not found");
+    expectedException.expectMessage(format("Component key '%s' not found", file.getKey()));
 
     ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_KEY, "file-key")
+      .setParam(PARAM_COMPONENT, file.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .execute();
   }
@@ -686,68 +804,6 @@ public class ComponentTreeActionTest {
       .setUserManaged(false);
   }
 
-  private void insertJsonExampleData() {
-    ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-id")
-      .setDbKey("MY_PROJECT")
-      .setName("My Project")
-      .setQualifier(Qualifiers.PROJECT);
-    componentDb.insertComponent(project);
-    SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
-      .setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
-      .setPeriodMode("previous_version")
-      .setPeriodParam("1.0-SNAPSHOT"));
-
-    ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null)
-      .setUuid("AVIwDXE-bJbJqrw6wFv5")
-      .setDbKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java")
-      .setName("ElementImpl.java")
-      .setLanguage("java")
-      .setQualifier(Qualifiers.FILE)
-      .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"));
-    ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null)
-      .setUuid("AVIwDXE_bJbJqrw6wFwJ")
-      .setDbKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java")
-      .setName("ElementImplTest.java")
-      .setLanguage("java")
-      .setQualifier(Qualifiers.UNIT_TEST_FILE)
-      .setPath("src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java"));
-    ComponentDto dir = componentDb.insertComponent(newDirectory(project, "src/main/java/com/sonarsource/markdown/impl")
-      .setUuid("AVIwDXE-bJbJqrw6wFv8")
-      .setDbKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl")
-      .setQualifier(Qualifiers.DIRECTORY));
-
-    MetricDto complexity = insertComplexityMetric();
-    dbClient.measureDao().insert(dbSession,
-      newMeasureDto(complexity, file1, projectSnapshot)
-        .setValue(12.0d),
-      newMeasureDto(complexity, dir, projectSnapshot)
-        .setValue(35.0d)
-        .setVariation(0.0d),
-      newMeasureDto(complexity, project, projectSnapshot)
-        .setValue(42.0d));
-
-    MetricDto ncloc = insertNclocMetric();
-    dbClient.measureDao().insert(dbSession,
-      newMeasureDto(ncloc, file1, projectSnapshot)
-        .setValue(114.0d),
-      newMeasureDto(ncloc, dir, projectSnapshot)
-        .setValue(217.0d)
-        .setVariation(0.0d),
-      newMeasureDto(ncloc, project, projectSnapshot)
-        .setValue(1984.0d));
-
-    MetricDto newViolations = insertNewViolationsMetric();
-    dbClient.measureDao().insert(dbSession,
-      newMeasureDto(newViolations, file1, projectSnapshot)
-        .setVariation(25.0d),
-      newMeasureDto(newViolations, dir, projectSnapshot)
-        .setVariation(25.0d),
-      newMeasureDto(newViolations, project, projectSnapshot)
-        .setVariation(255.0d));
-
-    db.commit();
-  }
-
   private MetricDto insertNewViolationsMetric() {
     MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDto()
       .setKey("new_violations")
index cb985375b6efd4deac7b826017a9ca4b2b50df3d..d6c550eae920e2e9df78542d579d83a002359df4 100644 (file)
@@ -27,6 +27,7 @@ public class ComponentTreeWsRequest {
 
   private String baseComponentId;
   private String baseComponentKey;
+  private String component;
   private String strategy;
   private List<String> qualifiers;
   private List<String> additionalFields;
@@ -42,26 +43,52 @@ public class ComponentTreeWsRequest {
   private String developerId;
   private String developerKey;
 
+  /**
+   * @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 ComponentTreeWsRequest setBaseComponentId(@Nullable String baseComponentId) {
     this.baseComponentId = baseComponentId;
     return this;
   }
 
+  /**
+   * @deprecated since 6.6, please use {@link #getComponent()} instead
+   */
+  @Deprecated
   @CheckForNull
   public String getBaseComponentKey() {
     return baseComponentKey;
   }
 
+  /**
+   * @deprecated since 6.6, please use {@link #setComponent(String)} instead
+   */
+  @Deprecated
   public ComponentTreeWsRequest setBaseComponentKey(@Nullable String baseComponentKey) {
     this.baseComponentKey = baseComponentKey;
     return this;
   }
 
+  @CheckForNull
+  public String getComponent() {
+    return component;
+  }
+
+  public ComponentTreeWsRequest setComponent(@Nullable String component) {
+    this.component = component;
+    return this;
+  }
+
   @CheckForNull
   public String getStrategy() {
     return strategy;
@@ -102,11 +129,12 @@ public class ComponentTreeWsRequest {
     return this;
   }
 
+  @CheckForNull
   public List<String> getSort() {
     return sort;
   }
 
-  public ComponentTreeWsRequest setSort(List<String> sort) {
+  public ComponentTreeWsRequest setSort(@Nullable List<String> sort) {
     this.sort = sort;
     return this;
   }
@@ -146,7 +174,7 @@ public class ComponentTreeWsRequest {
     return asc;
   }
 
-  public ComponentTreeWsRequest setAsc(boolean asc) {
+  public ComponentTreeWsRequest setAsc(@Nullable Boolean asc) {
     this.asc = asc;
     return this;
   }
index f81d8b9a72ba05017a6620454830d4956d7863ac..dca24806339cf868ffbc2019e937c09561e9ed3e 100644 (file)
@@ -32,11 +32,11 @@ import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPON
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT_TREE;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_SEARCH_HISTORY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.CONTROLLER_MEASURES;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID;
@@ -58,8 +58,9 @@ public class MeasuresService extends BaseService {
 
   public ComponentTreeWsResponse componentTree(ComponentTreeWsRequest request) {
     GetRequest getRequest = new GetRequest(path(ACTION_COMPONENT_TREE))
-      .setParam(PARAM_BASE_COMPONENT_ID, request.getBaseComponentId())
-      .setParam(PARAM_BASE_COMPONENT_KEY, request.getBaseComponentKey())
+      .setParam(DEPRECATED_PARAM_BASE_COMPONENT_ID, request.getBaseComponentId())
+      .setParam(DEPRECATED_PARAM_BASE_COMPONENT_KEY, request.getBaseComponentKey())
+      .setParam(PARAM_COMPONENT, request.getComponent())
       .setParam(PARAM_STRATEGY, request.getStrategy())
       .setParam(PARAM_QUALIFIERS, inlineMultipleParamValue(request.getQualifiers()))
       .setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys()))
index 70b7c27496d6419415c101e9a0c6c56b459a042a..519ec102d41a81b7c93a73ec5d4c34407ca5485b 100644 (file)
@@ -31,8 +31,8 @@ public class MeasuresWsParameters {
   public static final String ACTION_SEARCH_HISTORY = "search_history";
 
   // parameters
-  public static final String PARAM_BASE_COMPONENT_ID = "baseComponentId";
-  public static final String PARAM_BASE_COMPONENT_KEY = "baseComponentKey";
+  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_STRATEGY = "strategy";
index c0b0d0c1967fcfd7f0c1aacac8bfac0bc7dfcbff..b83ac53ce90c6c1d87e22a390fb9adea5dfaf8ab 100644 (file)
@@ -33,9 +33,9 @@ import static com.google.common.collect.Lists.newArrayList;
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID;
@@ -81,6 +81,7 @@ public class MeasuresServiceTest {
     ComponentTreeWsRequest componentTreeRequest = new ComponentTreeWsRequest()
       .setBaseComponentId(VALUE_BASE_COMPONENT_ID)
       .setBaseComponentKey(VALUE_BASE_COMPONENT_KEY)
+      .setComponent(VALUE_BASE_COMPONENT_KEY)
       .setMetricKeys(VALUE_METRIC_KEYS)
       .setStrategy(VALUE_STRATEGY)
       .setQualifiers(VALUE_QUALIFIERS)
@@ -100,8 +101,9 @@ public class MeasuresServiceTest {
 
     assertThat(serviceTester.getGetParser()).isSameAs(ComponentTreeWsResponse.parser());
     serviceTester.assertThat(getRequest)
-      .hasParam(PARAM_BASE_COMPONENT_ID, VALUE_BASE_COMPONENT_ID)
-      .hasParam(PARAM_BASE_COMPONENT_KEY, VALUE_BASE_COMPONENT_KEY)
+      .hasParam(DEPRECATED_PARAM_BASE_COMPONENT_ID, VALUE_BASE_COMPONENT_ID)
+      .hasParam(DEPRECATED_PARAM_BASE_COMPONENT_KEY, VALUE_BASE_COMPONENT_KEY)
+      .hasParam(PARAM_COMPONENT, VALUE_BASE_COMPONENT_KEY)
       .hasParam(PARAM_METRIC_KEYS, "ncloc,complexity")
       .hasParam(PARAM_STRATEGY, VALUE_STRATEGY)
       .hasParam(PARAM_QUALIFIERS, "FIL,PRJ")