]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11869 Remove deprecated parameters in measures WS
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 15 Oct 2019 18:43:22 +0000 (13:43 -0500)
committerSonarTech <sonartech@sonarsource.com>
Mon, 21 Oct 2019 18:21:11 +0000 (20:21 +0200)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeRequest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java

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