public static final String PARAM_METRIC_PERIOD_SORT = "metricPeriodSort";
public static final String PARAM_METRIC_SORT_FILTER = "metricSortFilter";
public static final String PARAM_ADDITIONAL_FIELDS = "additionalFields";
- public static final String DEPRECATED_PARAM_COMPONENT_ID = "componentId";
- public static final String DEPRECATED_PARAM_COMPONENT_KEY = "componentKey";
public static final String PARAM_PROJECT_KEYS = "projectKeys";
- public static final String PARAM_DEVELOPER_ID = "developerId";
- public static final String PARAM_DEVELOPER_KEY = "developerKey";
public static final String PARAM_FROM = "from";
public static final String PARAM_TO = "to";
import org.sonarqube.ws.Measures;
import org.sonarqube.ws.Measures.ComponentWsResponse;
-import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
-import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
-import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_KEY;
import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_COMPONENT;
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_METRICS;
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIODS;
-import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID;
-import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT;
-import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID;
-import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST;
+import static org.sonar.server.exceptions.BadRequestException.checkRequest;
import static org.sonar.server.measure.ws.ComponentDtoToWsComponent.componentDtoToWsComponent;
import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAdditionalFieldsParameter;
-import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createDeveloperParameters;
import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter;
import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric;
import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeriods;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
-import static org.sonar.server.exceptions.BadRequestException.checkRequest;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
public class ComponentAction implements MeasuresWsAction {
@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction(ACTION_COMPONENT)
- .setDescription(format("Return component with specified measures. The %s or the %s parameter must be provided.<br>" +
- "Requires the following permission: 'Browse' on the project of specified component.",
- DEPRECATED_PARAM_COMPONENT_ID, PARAM_COMPONENT))
+ .setDescription(format("Return component with specified measures.<br>" +
+ "Requires the following permission: 'Browse' on the project of specified component."))
.setResponseExample(getClass().getResource("component-example.json"))
.setSince("5.4")
.setChangelog(
action.createParam(PARAM_COMPONENT)
.setDescription("Component key")
- .setExampleValue(KEY_PROJECT_EXAMPLE_001)
- .setDeprecatedKey(DEPRECATED_PARAM_COMPONENT_KEY, "6.6");
-
- action.createParam(DEPRECATED_PARAM_COMPONENT_ID)
- .setDescription("Component id")
- .setExampleValue(UUID_EXAMPLE_01)
- .setDeprecatedSince("6.6");
+ .setRequired(true)
+ .setExampleValue(KEY_PROJECT_EXAMPLE_001);
action.createParam(PARAM_BRANCH)
.setDescription("Branch key")
createMetricKeysParameter(action);
createAdditionalFieldsParameter(action);
- createDeveloperParameters(action);
}
@Override
public void handle(Request request, Response response) throws Exception {
- if (request.param(PARAM_DEVELOPER_ID) != null || request.param(PARAM_DEVELOPER_KEY) != null) {
- throw new NotFoundException("The Developer Cockpit feature has been dropped. The specified developer cannot be found.");
- }
-
ComponentWsResponse componentWsResponse = doHandle(toComponentWsRequest(request));
writeProtobuf(componentWsResponse, request, response);
}
private ComponentDto loadComponent(DbSession dbSession, ComponentRequest request, @Nullable String branch, @Nullable String pullRequest) {
String componentKey = request.getComponent();
- String componentId = request.getComponentId();
- checkArgument(componentId == null || (branch == null && pullRequest == null), "Parameter '%s' cannot be used at the same time as '%s' or '%s'",
- DEPRECATED_PARAM_COMPONENT_ID, PARAM_BRANCH, PARAM_PULL_REQUEST);
if (branch == null && pullRequest == null) {
- return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_KEY);
+ return componentFinder.getByKey(dbSession, componentKey);
}
checkRequest(componentKey != null, "The '%s' parameter is missing", PARAM_COMPONENT);
private static ComponentRequest toComponentWsRequest(Request request) {
ComponentRequest componentRequest = new ComponentRequest()
- .setComponentId(request.param(DEPRECATED_PARAM_COMPONENT_ID))
- .setComponent(request.param(PARAM_COMPONENT))
+ .setComponent(request.mandatoryParam(PARAM_COMPONENT))
.setBranch(request.param(PARAM_BRANCH))
.setPullRequest(request.param(PARAM_PULL_REQUEST))
.setAdditionalFields(request.paramAsStrings(PARAM_ADDITIONAL_FIELDS))
}
private static class ComponentRequest {
- private String componentId;
private String component;
private String branch;
private String pullRequest;
private List<String> metricKeys;
private List<String> additionalFields;
- /**
- * @deprecated since 6.6, please use {@link #getComponent()} instead
- */
- @Deprecated
- @CheckForNull
- private String getComponentId() {
- return componentId;
- }
-
- /**
- * @deprecated since 6.6, please use {@link #setComponent(String)} instead
- */
- @Deprecated
- private ComponentRequest setComponentId(@Nullable String componentId) {
- this.componentId = componentId;
- return this;
- }
-
- @CheckForNull
private String getComponent() {
return component;
}
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT;
-import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID;
-import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SORT;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_QUALIFIERS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_STRATEGY;
+import static org.sonar.server.exceptions.BadRequestException.checkRequest;
import static org.sonar.server.measure.ws.ComponentDtoToWsComponent.componentDtoToWsComponent;
import static org.sonar.server.measure.ws.MeasureDtoToWsMeasure.updateMeasureBuilder;
import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAdditionalFieldsParameter;
-import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createDeveloperParameters;
import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter;
import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric;
import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeriods;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
-import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
-import static org.sonar.server.exceptions.BadRequestException.checkRequest;
+import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
/**
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.<br>" +
- "Requires the following permission: 'Browse' on the specified project.<br>" +
- "When limiting search with the %s parameter, directories are not returned.",
+ "Requires the following permission: 'Browse' on the specified project.<br>" +
+ "When limiting search with the %s parameter, directories are not returned.",
DEPRECATED_PARAM_BASE_COMPONENT_ID, PARAM_COMPONENT, Param.TEXT_QUERY))
.setResponseExample(getClass().getResource("component_tree-example.json"))
.setSince("5.4")
.setDescription("Comma-separated list of metric keys. Types %s are not allowed.", COMMA_JOINER.join(FORBIDDEN_METRIC_TYPES))
.setMaxValuesAllowed(MAX_METRIC_KEYS);
createAdditionalFieldsParameter(action);
- createDeveloperParameters(action);
createQualifiersParameter(action, newQualifierParameterContext(i18n, resourceTypes));
action.createParam(PARAM_STRATEGY)
}
private ComponentTreeWsResponse doHandle(ComponentTreeRequest request) {
- if (request.getDeveloperId() != null || request.getDeveloperKey() != null) {
- return emptyResponse(null, request);
- }
-
ComponentTreeData data = load(request);
if (data.getComponents() == null) {
return emptyResponse(data.getBaseComponent(), request);
.setMetricSort(request.param(PARAM_METRIC_SORT))
.setMetricSortFilter(request.mandatoryParam(PARAM_METRIC_SORT_FILTER))
.setMetricPeriodSort(request.paramAsInt(PARAM_METRIC_PERIOD_SORT))
- .setDeveloperId(request.param(PARAM_DEVELOPER_ID))
- .setDeveloperKey(request.param(PARAM_DEVELOPER_KEY))
.setPage(request.mandatoryParamAsInt(Param.PAGE))
.setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE))
.setQuery(request.param(Param.TEXT_QUERY));
private List<String> metricKeys;
private Integer page;
private Integer pageSize;
- private String developerId;
- private String developerKey;
/**
* @deprecated since 6.6, please use {@link #getComponent()} instead
this.metricPeriodSort = metricPeriodSort;
return this;
}
-
- @CheckForNull
- public String getDeveloperId() {
- return developerId;
- }
-
- public ComponentTreeRequest setDeveloperId(@Nullable String developerId) {
- this.developerId = developerId;
- return this;
- }
-
- @CheckForNull
- public String getDeveloperKey() {
- return developerKey;
- }
-
- public ComponentTreeRequest setDeveloperKey(@Nullable String developerKey) {
- this.developerKey = developerKey;
- return this;
- }
}
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_FIELDS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
-import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID;
-import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS;
class MeasuresWsParametersBuilder {
.setRequired(true)
.setExampleValue("ncloc,complexity,violations");
}
-
- static void createDeveloperParameters(NewAction action) {
- deprecateDeveloperParameter(action, PARAM_DEVELOPER_ID);
- deprecateDeveloperParameter(action, PARAM_DEVELOPER_KEY);
- }
-
- private static void deprecateDeveloperParameter(NewAction action, String key) {
- action.createParam(key)
- .setDeprecatedSince("6.4")
- .setDescription("Deprecated parameter, used previously with the Developer Cockpit plugin. No measures are returned if parameter is set.");
- }
}
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT;
-import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST;
import static org.sonar.test.JsonAssert.assertJson;
assertThat(def.since()).isEqualTo("5.4");
assertThat(def.params()).extracting(Param::key)
- .containsExactlyInAnyOrder("componentId", "component", "branch", "pullRequest", "metricKeys", "additionalFields", "developerId", "developerKey");
- assertThat(def.param("developerId").deprecatedSince()).isEqualTo("6.4");
- assertThat(def.param("developerKey").deprecatedSince()).isEqualTo("6.4");
- assertThat(def.param("componentId").deprecatedSince()).isEqualTo("6.6");
+ .containsExactlyInAnyOrder("component", "branch", "pullRequest", "metricKeys", "additionalFields");
+
+ WebService.Param component = def.param(PARAM_COMPONENT);
+ assertThat(component.isRequired()).isTrue();
WebService.Param branch = def.param("branch");
assertThat(branch.since()).isEqualTo("6.6");
MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT"));
ComponentWsResponse response = ws.newRequest()
- .setParam("componentId", project.uuid())
- .setParam(PARAM_METRIC_KEYS, metric.getKey())
- .executeProtobuf(ComponentWsResponse.class);
-
- assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
- }
-
- @Test
- public void use_deprecated_component_key_parameter() {
- ComponentDto project = db.components().insertPrivateProject();
- userSession.addProjectPermission(UserRole.USER, project);
- userSession.addProjectPermission(USER, project);
- MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT"));
-
- ComponentWsResponse response = ws.newRequest()
- .setParam("componentKey", project.getKey())
+ .setParam("component", project.getDbKey())
.setParam(PARAM_METRIC_KEYS, metric.getKey())
.executeProtobuf(ComponentWsResponse.class);
.containsExactly(tuple(metric.getKey(), "7", true));
}
- @Test
- public void fail_when_developer_is_not_found() {
- ComponentDto project = db.components().insertPrivateProject();
- userSession.addProjectPermission(UserRole.USER, project);
- db.components().insertSnapshot(project);
-
- MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT"));
-
- expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("The Developer Cockpit feature has been dropped. The specified developer cannot be found.");
-
- ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
- .setParam(PARAM_METRIC_KEYS, metric.getKey())
- .setParam(PARAM_DEVELOPER_ID, "unknown-developer-id").executeProtobuf(ComponentWsResponse.class);
- }
-
@Test
public void fail_when_a_metric_is_not_found() {
ComponentDto project = db.components().insertPrivateProject();
.execute();
}
- @Test
- public void fail_when_componentId_and_branch_params_are_used_together() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
- userSession.addProjectPermission(UserRole.USER, project);
- db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'");
-
- ws.newRequest()
- .setParam(DEPRECATED_PARAM_COMPONENT_ID, file.uuid())
- .setParam(PARAM_BRANCH, "my_branch")
- .setParam(PARAM_METRIC_KEYS, "ncloc")
- .execute();
- }
-
@Test
public void fail_when_using_branch_db_key() throws Exception {
OrganizationDto organization = db.organizations().insert();
.execute();
}
- @Test
- public void fail_when_using_branch_uuid() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertMainBranch(organization);
- userSession.logIn().addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
- MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT"));
-
- expectedException.expect(NotFoundException.class);
- expectedException.expectMessage(format("Component id '%s' not found", branch.uuid()));
-
- ws.newRequest()
- .setParam(DEPRECATED_PARAM_COMPONENT_ID, branch.uuid())
- .setParam(PARAM_METRIC_KEYS, metric.getKey())
- .execute();
- }
-
@Test
public void json_example() {
ComponentDto project = db.components().insertPrivateProject();