From: Julien Lancelot Date: Thu, 3 Aug 2017 17:12:44 +0000 (+0200) Subject: SONAR-9676 Clean component parameters in api/measures/component X-Git-Tag: 6.6-RC1~380^2~123 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=682128592478eff93567b11bcc7d083bf23f56b4;p=sonarqube.git SONAR-9676 Clean component parameters in api/measures/component - deprecate componentId - rename componentKey to component - deprecate id in response --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index 0aff113cd62..5bcfd73345f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -33,6 +33,7 @@ import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.resources.Qualifiers; +import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -73,9 +74,10 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT; 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_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_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_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; @@ -98,18 +100,23 @@ public class ComponentAction implements MeasuresWsAction { 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.", - PARAM_COMPONENT_ID, PARAM_COMPONENT_KEY)) + DEPRECATED_PARAM_COMPONENT_ID, PARAM_COMPONENT)) .setResponseExample(getClass().getResource("component-example.json")) .setSince("5.4") + .setChangelog( + 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_ID) - .setDescription("Component id") - .setExampleValue(UUID_EXAMPLE_01); - - action.createParam(PARAM_COMPONENT_KEY) + action.createParam(PARAM_COMPONENT) .setDescription("Component key") - .setExampleValue(KEY_PROJECT_EXAMPLE_001); + .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"); createMetricKeysParameter(action); createAdditionalFieldsParameter(action); @@ -124,7 +131,7 @@ public class ComponentAction implements MeasuresWsAction { private ComponentWsResponse doHandle(ComponentWsRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { - ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponentKey(), COMPONENT_ID_AND_KEY); + ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponent(), COMPONENT_ID_AND_KEY); Long developerId = searchDeveloperId(dbSession, request); Optional refComponent = getReferenceComponent(dbSession, component); checkPermissions(component); @@ -242,8 +249,8 @@ public class ComponentAction implements MeasuresWsAction { private static ComponentWsRequest toComponentWsRequest(Request request) { ComponentWsRequest componentWsRequest = new ComponentWsRequest() - .setComponentId(request.param(PARAM_COMPONENT_ID)) - .setComponentKey(request.param(PARAM_COMPONENT_KEY)) + .setComponentId(request.param(DEPRECATED_PARAM_COMPONENT_ID)) + .setComponent(request.param(PARAM_COMPONENT)) .setAdditionalFields(request.paramAsStrings(PARAM_ADDITIONAL_FIELDS)) .setMetricKeys(request.mandatoryParamAsStrings(PARAM_METRIC_KEYS)) .setDeveloperId(request.param(PARAM_DEVELOPER_ID)) diff --git a/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component-example.json b/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component-example.json index 8e7080ce4a4..dbac846a7e7 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component-example.json @@ -1,6 +1,5 @@ { "component": { - "id": "AVIwDXE-bJbJqrw6wFv5", "key": "MY_PROJECT:ElementImpl.java", "name": "ElementImpl.java", "qualifier": "FIL", diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index 53f6bc7c87e..0e7ba8748a3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -19,51 +19,43 @@ */ package org.sonar.server.measure.ws; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.measures.Metric.ValueType; -import org.sonar.api.resources.Qualifiers; import org.sonar.api.server.ws.WebService; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.System2; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; +import org.sonar.api.web.UserRole; import org.sonar.db.DbTester; -import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.component.SnapshotTesting; import org.sonar.db.metric.MetricDto; import org.sonar.server.component.TestComponentFinder; +import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsActionTester; import org.sonarqube.ws.Common; +import org.sonarqube.ws.Common; +import org.sonarqube.ws.WsMeasures; +import org.sonarqube.ws.WsMeasures.Component; import org.sonarqube.ws.WsMeasures.ComponentWsResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.utils.DateUtils.parseDateTime; import static org.sonar.api.web.UserRole.USER; import static org.sonar.db.component.ComponentTesting.newFileDto; -import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; import static org.sonar.db.component.ComponentTesting.newProjectCopy; -import static org.sonar.db.component.ComponentTesting.newView; import static org.sonar.db.component.SnapshotTesting.newAnalysis; -import static org.sonar.db.measure.MeasureTesting.newMeasureDto; -import static org.sonar.db.metric.MetricTesting.newMetricDto; import static org.sonar.test.JsonAssert.assertJson; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_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_METRIC_KEYS; public class ComponentActionTest { - private static final String PROJECT_UUID = "project-uuid"; @Rule public UserSessionRule userSession = UserSessionRule.standalone(); @@ -72,16 +64,7 @@ public class ComponentActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private ComponentDbTester componentDb = new ComponentDbTester(db); - private DbClient dbClient = db.getDbClient(); - private final DbSession dbSession = db.getSession(); - - private WsActionTester ws = new WsActionTester(new ComponentAction(dbClient, TestComponentFinder.from(db), userSession)); - - @Before - public void setUp() { - userSession.logIn().setRoot(); - } + private WsActionTester ws = new WsActionTester(new ComponentAction(db.getDbClient(), TestComponentFinder.from(db), userSession)); @Test public void definition() { @@ -89,45 +72,34 @@ public class ComponentActionTest { assertThat(def.since()).isEqualTo("5.4"); assertThat(def.params()).extracting(Param::key) - .containsExactlyInAnyOrder("componentId", "componentKey", "metricKeys", "additionalFields", "developerId", "developerKey"); + .containsExactlyInAnyOrder("componentId", "component", "metricKeys", "additionalFields", "developerId", "developerKey"); assertThat(def.param("developerId").deprecatedSince()).isEqualTo("6.4"); assertThat(def.param("developerKey").deprecatedSince()).isEqualTo("6.4"); - } - - @Test - public void json_example() { - insertJsonExampleData(); - - String response = ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "AVIwDXE-bJbJqrw6wFv5") - .setParam(PARAM_METRIC_KEYS, "ncloc, complexity, new_violations") - .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods") - .execute() - .getInput(); - - assertJson(response).isSimilarTo(getClass().getResource("component-example.json")); + assertThat(def.param("componentId").deprecatedSince()).isEqualTo("6.6"); } @Test public void provided_project() { - ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID)); - userSession.addProjectPermission(USER, project); + ComponentDto project = db.components().insertPrivateProject(); + logAsUser(project); insertNclocMetric(); - ComponentWsResponse response = newRequest(PROJECT_UUID, "ncloc"); + ComponentWsResponse response = newRequest(project.getKey(), "ncloc"); assertThat(response.getMetrics().getMetricsCount()).isEqualTo(1); assertThat(response.getPeriods().getPeriodsCount()).isEqualTo(0); - assertThat(response.getComponent().getId()).isEqualTo(PROJECT_UUID); + assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); } @Test public void without_additional_fields() { - componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), "project-uuid")); + ComponentDto project = db.components().insertPrivateProject(); + logAsUser(project); + db.components().insertSnapshot(project); insertNclocMetric(); String response = ws.newRequest() - .setParam(PARAM_COMPONENT_ID, "project-uuid") + .setParam(PARAM_COMPONENT, project.getKey()) .setParam(PARAM_METRIC_KEYS, "ncloc") .execute().getInput(); @@ -138,31 +110,73 @@ public class ComponentActionTest { @Test public void reference_uuid_in_the_response() { - ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid").setDbKey("project-key"); - componentDb.insertProjectAndSnapshot(project); - ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid"); - componentDb.insertViewAndSnapshot(view); - componentDb.insertComponent(newProjectCopy("project-uuid-copy", project, view)); + userSession.logIn().setRoot(); + ComponentDto project = db.components().insertPrivateProject(); + ComponentDto view = db.components().insertView(); + db.components().insertSnapshot(view); + ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-uuid-copy", project, view)); + insertNclocMetric(); + + ComponentWsResponse response = newRequest(projectCopy.getKey(), "ncloc"); + + 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(); + logAsUser(project); + db.components().insertSnapshot(project); + insertNclocMetric(); + + ComponentWsResponse response = newRequest(project.getKey(), "ncloc"); + + assertThat(response.getComponent().getId()).isEqualTo(project.uuid()); + } + + @Test + public void use_deprecated_component_id_parameter() { + ComponentDto project = db.components().insertPrivateProject(); + logAsUser(project); + userSession.addProjectPermission(USER, project); + insertNclocMetric(); + + ComponentWsResponse response = ws.newRequest() + .setParam("componentId", project.uuid()) + .setParam(PARAM_METRIC_KEYS, "ncloc") + .executeProtobuf(ComponentWsResponse.class); + + assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); + } + + @Test + public void use_deprecated_component_key_parameter() { + ComponentDto project = db.components().insertPrivateProject(); + logAsUser(project); + userSession.addProjectPermission(USER, project); insertNclocMetric(); - ComponentWsResponse response = newRequest("project-uuid-copy", "ncloc"); + ComponentWsResponse response = ws.newRequest() + .setParam("componentKey", project.getKey()) + .setParam(PARAM_METRIC_KEYS, "ncloc") + .executeProtobuf(ComponentWsResponse.class); - assertThat(response.getComponent().getId()).isEqualTo("project-uuid-copy"); - assertThat(response.getComponent().getRefId()).isEqualTo("project-uuid"); - assertThat(response.getComponent().getRefKey()).isEqualTo("project-key"); + assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); } @Test public void metric_without_a_domain() { ComponentDto project = db.components().insertPrivateProject(); - SnapshotDto analysis = db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(project)); + logAsUser(project); + SnapshotDto analysis = db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(project)); MetricDto metricWithoutDomain = db.measures().insertMetric(m -> m - .setValueType(ValueType.INT.name()) + .setValueType(Measure.ValueType.INT.name()) .setDomain(null)); db.measures().insertMeasure(project, analysis, metricWithoutDomain); ComponentWsResponse response = ws.newRequest() - .setParam(PARAM_COMPONENT_KEY, project.getKey()) + .setParam(PARAM_COMPONENT, project.getKey()) .setParam(PARAM_METRIC_KEYS, metricWithoutDomain.getKey()) .setParam(PARAM_ADDITIONAL_FIELDS, "metrics") .executeProtobuf(ComponentWsResponse.class); @@ -175,49 +189,57 @@ public class ComponentActionTest { @Test public void fail_when_developer_is_not_found() { - expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Component id 'unknown-developer-id' not found"); + ComponentDto project = db.components().insertPrivateProject(); + logAsUser(project); + db.components().insertSnapshot(project); - componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID)); insertNclocMetric(); + expectedException.expect(NotFoundException.class); + expectedException.expectMessage("Component id 'unknown-developer-id' not found"); + ws.newRequest() - .setParam(PARAM_COMPONENT_ID, PROJECT_UUID) + .setParam(PARAM_COMPONENT, project.getKey()) .setParam(PARAM_METRIC_KEYS, "ncloc") .setParam(PARAM_DEVELOPER_ID, "unknown-developer-id").executeProtobuf(ComponentWsResponse.class); } @Test public void fail_when_a_metric_is_not_found() { - componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID)); + ComponentDto project = db.components().insertPrivateProject(); + logAsUser(project); + db.components().insertSnapshot(project); insertNclocMetric(); insertComplexityMetric(); expectedException.expect(NotFoundException.class); expectedException.expectMessage("The following metric keys are not found: unknown-metric, another-unknown-metric"); - newRequest(PROJECT_UUID, "ncloc, complexity, unknown-metric, another-unknown-metric"); + newRequest(project.getKey(), "ncloc, complexity, unknown-metric, another-unknown-metric"); } @Test public void fail_when_empty_metric_keys_parameter() { - componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID)); + ComponentDto project = db.components().insertPrivateProject(); + logAsUser(project); + db.components().insertSnapshot(project); expectedException.expect(BadRequestException.class); expectedException.expectMessage("At least one metric key must be provided"); - newRequest(PROJECT_UUID, ""); + newRequest(project.getKey(), ""); } @Test public void fail_when_not_enough_permission() { userSession.logIn(); - componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID)); + ComponentDto project = db.components().insertPrivateProject(); + db.components().insertSnapshot(project); insertNclocMetric(); expectedException.expect(ForbiddenException.class); - newRequest(PROJECT_UUID, "ncloc"); + newRequest(project.getKey(), "ncloc"); } @Test @@ -228,45 +250,76 @@ public class ComponentActionTest { expectedException.expectMessage("Component key 'project-key' not found"); ws.newRequest() - .setParam(PARAM_COMPONENT_KEY, "project-key") + .setParam(PARAM_COMPONENT, "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(p -> p.setEnabled(false)); + logAsUser(project); userSession.addProjectPermission(USER, project); insertNclocMetric(); expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Component key 'file-key' not found"); + expectedException.expectMessage(String.format("Component key '%s' not found", project.getKey())); ws.newRequest() - .setParam(PARAM_COMPONENT_KEY, "file-key") + .setParam(PARAM_COMPONENT, project.getKey()) .setParam(PARAM_METRIC_KEYS, "ncloc") .execute(); } - private ComponentWsResponse newRequest(String componentUuid, String metricKeys) { - return ws.newRequest() - .setParam(PARAM_COMPONENT_ID, componentUuid) - .setParam(PARAM_METRIC_KEYS, metricKeys) - .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods").executeProtobuf(ComponentWsResponse.class); + @Test + public void json_example() { + ComponentDto project = db.components().insertPrivateProject(); + logAsUser(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 file = db.components().insertComponent(newFileDto(project) + .setDbKey("MY_PROJECT:ElementImpl.java") + .setName("ElementImpl.java") + .setLanguage("java") + .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java")); + MetricDto complexity = insertComplexityMetric(); + db.measures().insertMeasure(file, analysis, complexity, + m -> m.setValue(12.0d) + .setVariation(2.0d) + .setData(null)); + MetricDto ncloc = insertNclocMetric(); + db.measures().insertMeasure(file, analysis, ncloc, + m -> m.setValue(114.0d) + .setVariation(3.0d) + .setData(null)); + MetricDto newViolations = insertNewViolationMetric(); + db.measures().insertMeasure(file, analysis, newViolations, + m -> m.setVariation(25.0d) + .setValue(null) + .setData(null)); + + String response = ws.newRequest() + .setParam(PARAM_COMPONENT, file.getKey()) + .setParam(PARAM_METRIC_KEYS, "ncloc, complexity, new_violations") + .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods") + .execute() + .getInput(); + + assertJson(response).isSimilarTo(getClass().getResource("component-example.json")); } - private static MetricDto newMetricDtoWithoutOptimization() { - return newMetricDto() - .setWorstValue(null) - .setOptimizedBestValue(false) - .setBestValue(null) - .setUserManaged(false); + private ComponentWsResponse newRequest(String componentKey, String metricKeys) { + return ws.newRequest() + .setParam(PARAM_COMPONENT, componentKey) + .setParam(PARAM_METRIC_KEYS, metricKeys) + .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods") + .executeProtobuf(ComponentWsResponse.class); } private MetricDto insertNclocMetric() { - MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization() - .setKey("ncloc") + return db.measures().insertMetric(m -> m.setKey("ncloc") .setShortName("Lines of code") .setDescription("Non Commenting Lines of Code") .setDomain("Size") @@ -275,13 +328,10 @@ public class ComponentActionTest { .setQualitative(false) .setHidden(false) .setUserManaged(false)); - db.commit(); - return metric; } private MetricDto insertComplexityMetric() { - MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization() - .setKey("complexity") + return db.measures().insertMetric(m -> m.setKey("complexity") .setShortName("Complexity") .setDescription("Cyclomatic complexity") .setDomain("Complexity") @@ -290,13 +340,10 @@ public class ComponentActionTest { .setQualitative(false) .setHidden(false) .setUserManaged(false)); - db.commit(); - return metric; } private MetricDto insertNewViolationMetric() { - MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization() - .setKey("new_violations") + return db.measures().insertMetric(m -> m.setKey("new_violations") .setShortName("New issues") .setDescription("New Issues") .setDomain("Issues") @@ -305,43 +352,10 @@ public class ComponentActionTest { .setQualitative(true) .setHidden(false) .setUserManaged(false)); - db.commit(); - return metric; } - private void insertJsonExampleData() { - ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID); - SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project) - .setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()) - .setPeriodMode("previous_version") - .setPeriodParam("1.0-SNAPSHOT"); - ComponentDto file = newFileDto(project, null) - .setUuid("AVIwDXE-bJbJqrw6wFv5") - .setDbKey("MY_PROJECT:ElementImpl.java") - .setName("ElementImpl.java") - .setQualifier(Qualifiers.FILE) - .setLanguage("java") - .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"); - componentDb.insertComponents(project, file); - dbClient.snapshotDao().insert(dbSession, projectSnapshot); - - MetricDto complexity = insertComplexityMetric(); - dbClient.measureDao().insert(dbSession, - newMeasureDto(complexity, file, projectSnapshot) - .setValue(12.0d) - .setVariation(2.0d)); - - MetricDto ncloc = insertNclocMetric(); - dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, file, projectSnapshot) - .setValue(114.0d) - .setVariation(3.0d)); - - MetricDto newViolations = insertNewViolationMetric(); - dbClient.measureDao().insert(dbSession, - newMeasureDto(newViolations, file, projectSnapshot) - .setVariation(25.0d)); - db.commit(); + private void logAsUser(ComponentDto project) { + userSession.addProjectPermission(UserRole.USER, project); } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentWsRequest.java index 4c2fbf2ce2e..998ac57209f 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentWsRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentWsRequest.java @@ -26,31 +26,58 @@ import javax.annotation.Nullable; public class ComponentWsRequest { private String componentId; private String componentKey; + private String component; private List metricKeys; private List additionalFields; private String developerId; private String developerKey; + /** + * @deprecated since 6.6, please use {@link #getComponent()} instead + */ + @Deprecated @CheckForNull public String getComponentId() { return componentId; } + /** + * @deprecated since 6.6, please use {@link #setComponent(String)} instead + */ + @Deprecated public ComponentWsRequest setComponentId(@Nullable String componentId) { this.componentId = componentId; return this; } + /** + * @deprecated since 6.6, please use {@link #getComponent()} instead + */ + @Deprecated @CheckForNull public String getComponentKey() { return componentKey; } + /** + * @deprecated since 6.6, please use {@link #setComponent(String)} instead + */ + @Deprecated public ComponentWsRequest setComponentKey(@Nullable String componentKey) { this.componentKey = componentKey; return this; } + @CheckForNull + public String getComponent() { + return component; + } + + public ComponentWsRequest setComponent(@Nullable String component) { + this.component = component; + return this; + } + public List getMetricKeys() { return metricKeys; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java index 470dfa7fa29..f81d8b9a72b 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java @@ -32,13 +32,13 @@ 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_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_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY; 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_FROM; @@ -79,8 +79,9 @@ public class MeasuresService extends BaseService { public ComponentWsResponse component(ComponentWsRequest request) { GetRequest getRequest = new GetRequest(path(ACTION_COMPONENT)) - .setParam(PARAM_COMPONENT_ID, request.getComponentId()) - .setParam(PARAM_COMPONENT_KEY, request.getComponentKey()) + .setParam(DEPRECATED_PARAM_COMPONENT_ID, request.getComponentId()) + .setParam(DEPRECATED_PARAM_COMPONENT_KEY, request.getComponentKey()) + .setParam(PARAM_COMPONENT, request.getComponent()) .setParam(PARAM_ADDITIONAL_FIELDS, inlineMultipleParamValue(request.getAdditionalFields())) .setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys())) .setParam(PARAM_DEVELOPER_ID, request.getDeveloperId()) diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java index 48599358cc4..70b7c27496d 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java @@ -43,8 +43,8 @@ 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 PARAM_COMPONENT_ID = "componentId"; - public static final String PARAM_COMPONENT_KEY = "componentKey"; + 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";