From d6a17a778de357348e3e88771d79e0fa42a5369b Mon Sep 17 00:00:00 2001 From: Michal Duda Date: Wed, 24 Feb 2021 11:03:11 +0100 Subject: [PATCH] SONAR-13848 remove deprecations from api/ce/component --- .../sonar/server/ce/ws/ComponentAction.java | 27 +++++++------------ .../org/sonar/server/ce/ws/TaskFormatter.java | 2 -- .../server/ce/ws/ActivityActionTest.java | 4 +-- .../server/ce/ws/ComponentActionTest.java | 26 ++++-------------- .../sonar/server/ce/ws/TaskActionTest.java | 2 -- .../sonar/server/ce/ws/TaskFormatterTest.java | 3 --- sonar-ws/src/main/protobuf/ws-ce.proto | 3 +-- 7 files changed, 16 insertions(+), 51 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ComponentAction.java index 07daaff3c4c..4882da76bf4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ComponentAction.java @@ -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).
" + - "Requires the following permission: 'Browse' on the specified component.
" + - "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); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java index 15851556e3b..178619f7ff7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java @@ -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); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java index 44dbe39b810..92da8486bb5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java @@ -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(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java index e34a779e381..47625ecdc2f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java @@ -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() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java index 3eae53eff02..8f781cccb3f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java @@ -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(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java index 860c92eb1f3..c49b2ddeafe 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/TaskFormatterTest.java @@ -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(); diff --git a/sonar-ws/src/main/protobuf/ws-ce.proto b/sonar-ws/src/main/protobuf/ws-ce.proto index 053c1182ac6..8eefda48532 100644 --- a/sonar-ws/src/main/protobuf/ws-ce.proto +++ b/sonar-ws/src/main/protobuf/ws-ce.proto @@ -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; -- 2.39.5