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;
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 {
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
}
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);
}
}
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);
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);
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
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();
}
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 {
@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() {
}
@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();
.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()
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();
}
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();
}
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();
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();
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();
}
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;
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;