]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13848 remove deprecations from api/ce/component
authorMichal Duda <michal.duda@sonarsource.com>
Wed, 24 Feb 2021 10:03:11 +0000 (11:03 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 26 Feb 2021 20:07:40 +0000 (20:07 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ComponentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java
sonar-ws/src/main/protobuf/ws-ce.proto

index 07daaff3c4cc6f6346da3b5a9cf0a0e0983ac7be..4882da76bf42d5dca485794ab21c8c0586921a9e 100644 (file)
@@ -25,7 +25,6 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.web.UserRole;
-import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.ce.CeActivityDto;
@@ -38,11 +37,10 @@ import org.sonar.server.ws.KeyExamples;
 import org.sonarqube.ws.Ce;
 import org.sonarqube.ws.Ce.ComponentResponse;
 
+import static java.lang.String.format;
 import static java.util.Collections.emptyList;
 import static org.sonar.db.Pagination.forPage;
 import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT;
-import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID;
-import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class ComponentAction implements CeWsAction {
@@ -63,26 +61,20 @@ public class ComponentAction implements CeWsAction {
   public void define(WebService.NewController controller) {
     WebService.NewAction action = controller.createAction("component")
       .setDescription("Get the pending tasks, in-progress tasks and the last executed task of a given component (usually a project).<br>" +
-        "Requires the following permission: 'Browse' on the specified component.<br>" +
-        "Either '%s' or '%s' must be provided.",
-        PARAM_COMPONENT_ID, PARAM_COMPONENT)
+        "Requires the following permission: 'Browse' on the specified component.")
       .setSince("5.2")
       .setResponseExample(getClass().getResource("component-example.json"))
       .setChangelog(
         new Change("6.1", "field \"logs\" is deprecated and its value is always false"),
         new Change("6.6", "fields \"branch\" and \"branchType\" added"),
-        new Change("7.6", String.format("The use of module keys in parameter \"%s\" is deprecated", PARAM_COMPONENT)))
+        new Change("7.6", format("The use of module keys in parameter \"%s\" is deprecated", PARAM_COMPONENT)),
+        new Change("8.8", "Deprecated parameter 'componentId' has been removed."),
+        new Change("8.8", "Parameter 'component' is now required."))
       .setHandler(this);
 
-    action.createParam(PARAM_COMPONENT_ID)
-      .setRequired(false)
-      .setExampleValue(Uuids.UUID_EXAMPLE_01)
-      .setDeprecatedSince("6.6");
-
     action.createParam(PARAM_COMPONENT)
-      .setRequired(false)
-      .setExampleValue(KeyExamples.KEY_PROJECT_EXAMPLE_001)
-      .setDeprecatedKey("componentKey", "6.6");
+      .setRequired(true)
+      .setExampleValue(KeyExamples.KEY_PROJECT_EXAMPLE_001);
   }
 
   @Override
@@ -106,8 +98,7 @@ public class ComponentAction implements CeWsAction {
   }
 
   private ComponentDto loadComponent(DbSession dbSession, Request wsRequest) {
-    String componentKey = wsRequest.param(PARAM_COMPONENT);
-    String componentId = wsRequest.param(PARAM_COMPONENT_ID);
-    return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_COMPONENT);
+    String componentKey = wsRequest.mandatoryParam(PARAM_COMPONENT);
+    return componentFinder.getByKey(dbSession, componentKey);
   }
 }
index 15851556e3bd5c023c760e399a706a1b655942f9..178619f7ff7849b1116e1f37a05163bf6d486325 100644 (file)
@@ -83,7 +83,6 @@ public class TaskFormatter {
     builder.setId(dto.getUuid());
     builder.setStatus(Ce.TaskStatus.valueOf(dto.getStatus().name()));
     builder.setType(dto.getTaskType());
-    builder.setLogs(false);
     cache.getUser(dto.getSubmitterUuid()).ifPresent(user -> builder.setSubmitterLogin(user.getLogin()));
     builder.setSubmittedAt(formatDateTime(new Date(dto.getCreatedAt())));
     ofNullable(dto.getStartedAt()).map(DateUtils::formatDateTime).ifPresent(builder::setStartedAt);
@@ -108,7 +107,6 @@ public class TaskFormatter {
     builder.setId(dto.getUuid());
     builder.setStatus(Ce.TaskStatus.valueOf(dto.getStatus().name()));
     builder.setType(dto.getTaskType());
-    builder.setLogs(false);
     ofNullable(dto.getComponentUuid()).ifPresent(uuid -> setComponent(builder, uuid, cache).setComponentId(uuid));
     String analysisUuid = dto.getAnalysisUuid();
     ofNullable(analysisUuid).ifPresent(builder::setAnalysisId);
index 44dbe39b810a3811b6af87ce7c92b2eb0cf8cd70..92da8486bb52d757feb6600980d7c9f4f84954a9 100644 (file)
@@ -90,7 +90,7 @@ public class ActivityActionTest {
   public DbTester db = DbTester.create(System2.INSTANCE);
 
   private final TaskFormatter formatter = new TaskFormatter(db.getDbClient(), System2.INSTANCE);
-  private final ActivityAction underTest = new ActivityAction(userSession, db.getDbClient(), formatter, new CeTaskProcessor[] {mock(CeTaskProcessor.class)});
+  private final ActivityAction underTest = new ActivityAction(userSession, db.getDbClient(), formatter, new CeTaskProcessor[]{mock(CeTaskProcessor.class)});
   private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
@@ -113,14 +113,12 @@ public class ActivityActionTest {
     assertThat(task.getComponentId()).isEqualTo(project2.uuid());
     assertThat(task.hasAnalysisId()).isFalse();
     assertThat(task.getExecutionTimeMs()).isEqualTo(500L);
-    assertThat(task.getLogs()).isFalse();
     assertThat(task.getWarningCount()).isZero();
 
     task = activityResponse.getTasks(1);
     assertThat(task.getId()).isEqualTo("T1");
     assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
     assertThat(task.getComponentId()).isEqualTo(project1.uuid());
-    assertThat(task.getLogs()).isFalse();
     assertThat(task.getWarningCount()).isZero();
   }
 
index e34a779e3819d08c02464aa6a26d9344996415ae..47625ecdc2f2e4100d37c176338d665c23095fdf 100644 (file)
@@ -58,7 +58,6 @@ import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_KEY;
 import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY;
 import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT;
-import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID;
 
 public class ComponentActionTest {
 
@@ -67,9 +66,9 @@ public class ComponentActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private TaskFormatter formatter = new TaskFormatter(db.getDbClient(), System2.INSTANCE);
-  private ComponentAction underTest = new ComponentAction(userSession, db.getDbClient(), formatter, TestComponentFinder.from(db));
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final TaskFormatter formatter = new TaskFormatter(db.getDbClient(), System2.INSTANCE);
+  private final ComponentAction underTest = new ComponentAction(userSession, db.getDbClient(), formatter, TestComponentFinder.from(db));
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
   public void empty_queue_and_empty_activity() {
@@ -130,14 +129,14 @@ public class ComponentActionTest {
   }
 
   @Test
-  public void search_tasks_by_component_id() {
+  public void search_tasks_by_component() {
     ComponentDto project = db.components().insertPrivateProject();
     logInWithBrowsePermission(project);
     SnapshotDto analysis = db.components().insertSnapshot(project);
     insertActivity("T1", project, CeActivityDto.Status.SUCCESS, analysis);
 
     Ce.ComponentResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT_ID, project.uuid())
+      .setParam(PARAM_COMPONENT, project.getKey())
       .executeProtobuf(Ce.ComponentResponse.class);
     assertThat(response.hasCurrent()).isTrue();
     Ce.Task current = response.getCurrent();
@@ -262,21 +261,6 @@ public class ComponentActionTest {
       .containsOnly(messageCount, emptyList());
   }
 
-  @Test
-  public void deprecated_component_key() {
-    ComponentDto project = db.components().insertPrivateProject();
-    logInWithBrowsePermission(project);
-    SnapshotDto analysis = db.components().insertSnapshot(project);
-    insertActivity("T1", project, CeActivityDto.Status.SUCCESS, analysis);
-
-    Ce.ComponentResponse response = ws.newRequest()
-      .setParam("componentKey", project.getKey())
-      .executeProtobuf(Ce.ComponentResponse.class);
-    assertThat(response.hasCurrent()).isTrue();
-    assertThat(response.getCurrent().getId()).isEqualTo("T1");
-    assertThat(response.getCurrent().getAnalysisId()).isEqualTo(analysis.getUuid());
-  }
-
   @Test
   public void fail_with_404_when_component_does_not_exist() {
     TestRequest request = ws.newRequest()
index 3eae53eff02783707cdc1336f754c0cc69b1986e..8f781cccb3fa3824e34be918e8dc149cbb1a70ee 100644 (file)
@@ -105,7 +105,6 @@ public class TaskActionTest {
     assertThat(taskResponse.getTask().getComponentKey()).isEqualTo(privateProject.getDbKey());
     assertThat(taskResponse.getTask().getComponentName()).isEqualTo(privateProject.name());
     assertThat(taskResponse.getTask().hasExecutionTimeMs()).isFalse();
-    assertThat(taskResponse.getTask().getLogs()).isFalse();
     assertThat(taskResponse.getTask().getWarningCount()).isZero();
     assertThat(taskResponse.getTask().getWarningsList()).isEmpty();
   }
@@ -152,7 +151,6 @@ public class TaskActionTest {
     assertThat(task.getComponentName()).isEqualTo(privateProject.name());
     assertThat(task.getAnalysisId()).isEqualTo(activityDto.getAnalysisUuid());
     assertThat(task.getExecutionTimeMs()).isEqualTo(500L);
-    assertThat(task.getLogs()).isFalse();
     assertThat(task.getWarningCount()).isZero();
     assertThat(task.getWarningsList()).isEmpty();
   }
index 860c92eb1f36d33bea9e161ea09b40fbecfb85ef..c49b2ddeafe5246491bfc395d9717e0539d7afd8 100644 (file)
@@ -70,7 +70,6 @@ public class TaskFormatterTest {
     assertThat(wsTask.getType()).isEqualTo("TYPE");
     assertThat(wsTask.getId()).isEqualTo("UUID");
     assertThat(wsTask.getStatus()).isEqualTo(Ce.TaskStatus.PENDING);
-    assertThat(wsTask.getLogs()).isFalse();
     assertThat(wsTask.getSubmittedAt()).isEqualTo(DateUtils.formatDateTime(new Date(1_450_000_000_000L)));
     assertThat(wsTask.hasScannerContext()).isFalse();
 
@@ -110,7 +109,6 @@ public class TaskFormatterTest {
     assertThat(wsTask.getComponentName()).isEqualTo("Component Name");
     assertThat(wsTask.getComponentQualifier()).isEqualTo("TRK");
     assertThat(wsTask.getStatus()).isEqualTo(Ce.TaskStatus.IN_PROGRESS);
-    assertThat(wsTask.getLogs()).isFalse();
     assertThat(wsTask.getSubmitterLogin()).isEqualTo(user.getLogin());
     assertThat(wsTask.hasExecutionTimeMs()).isTrue();
     assertThat(wsTask.hasExecutedAt()).isFalse();
@@ -194,7 +192,6 @@ public class TaskFormatterTest {
     assertThat(wsTask.getSubmitterLogin()).isEqualTo(user.getLogin());
     assertThat(wsTask.getExecutionTimeMs()).isEqualTo(500L);
     assertThat(wsTask.getAnalysisId()).isEqualTo("U1");
-    assertThat(wsTask.getLogs()).isFalse();
     assertThat(wsTask.hasScannerContext()).isFalse();
     assertThat(wsTask.getWarningCount()).isEqualTo(warningCount);
     assertThat(wsTask.getWarningsList()).isEmpty();
index 053c1182ac66d1c1a14e27ca4bedbea19a55f3ce..8eefda4853256358a806d9be9778ddf08f503cb5 100644 (file)
@@ -108,7 +108,7 @@ message WorkerCountResponse {
 }
 
 message Task {
-  reserved 20; //drop organization
+  reserved 15,20; //drop organizations, drop 'logs'
   optional string id = 1;
   optional string type = 2;
   optional string componentId = 3;
@@ -123,7 +123,6 @@ message Task {
   optional string executedAt = 12;
   optional bool isLastExecuted = 13;
   optional int64 executionTimeMs = 14;
-  optional bool logs = 15;
   optional string errorMessage = 16;
   optional string errorStacktrace = 17;
   optional string scannerContext = 18;