import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_KEY;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
+import static org.sonarqube.ws.client.ce.CeWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY;
public class ActivityStatusAction implements CeWsAction {
private final UserSession userSession;
action.createParam(PARAM_COMPONENT_ID)
.setDescription("Id of the component (project) to filter on")
.setExampleValue(Uuids.UUID_EXAMPLE_03);
- action.createParam(PARAM_COMPONENT_KEY)
+ action.createParam(DEPRECATED_PARAM_COMPONENT_KEY)
.setDescription("Key of the component (project) to filter on")
.setExampleValue(KeyExamples.KEY_PROJECT_EXAMPLE_001);
private static ActivityStatusWsRequest toWsRequest(Request request) {
return ActivityStatusWsRequest.newBuilder()
.setComponentId(request.param(PARAM_COMPONENT_ID))
- .setComponentKey(request.param(PARAM_COMPONENT_KEY))
+ .setComponentKey(request.param(DEPRECATED_PARAM_COMPONENT_KEY))
.build();
}
}
import org.sonar.server.user.UserSession;
import org.sonar.server.ws.KeyExamples;
-import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.db.Pagination.forPage;
-import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_KEY;
-import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
+import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.WsCe.ProjectResponse;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_BRANCH;
+import static org.sonarqube.ws.client.ce.CeWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
+import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY;
public class ComponentAction implements CeWsAction {
.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, not both.",
- PARAM_COMPONENT_ID, PARAM_COMPONENT_KEY)
+ PARAM_COMPONENT_ID, DEPRECATED_PARAM_COMPONENT_KEY)
.setSince("5.2")
.setResponseExample(getClass().getResource("component-example.json"))
.setChangelog(
action.createParam(PARAM_COMPONENT_ID)
.setRequired(false)
- .setExampleValue(Uuids.UUID_EXAMPLE_01);
+ .setExampleValue(Uuids.UUID_EXAMPLE_01)
+ .setDeprecatedSince("6.6");
- action.createParam(PARAM_COMPONENT_KEY)
+ action.createParam(PARAM_COMPONENT)
.setRequired(false)
- .setExampleValue(KeyExamples.KEY_PROJECT_EXAMPLE_001);
-
- action.createParam(PARAM_BRANCH)
- .setDescription("Branch key")
- .setInternal(true)
- .setExampleValue(KEY_BRANCH_EXAMPLE_001);
+ .setExampleValue(KeyExamples.KEY_PROJECT_EXAMPLE_001)
+ .setDeprecatedKey("componentKey", "6.6");
}
@Override
}
private ComponentDto loadComponent(DbSession dbSession, Request wsRequest) {
- String componentKey = wsRequest.param(PARAM_COMPONENT_KEY);
+ String componentKey = wsRequest.param(PARAM_COMPONENT);
String componentId = wsRequest.param(PARAM_COMPONENT_ID);
- String branch = wsRequest.param(PARAM_BRANCH);
- checkArgument(componentId == null || branch == null, "'%s' and '%s' parameters cannot be used at the same time", PARAM_COMPONENT_ID,
- PARAM_BRANCH);
- return branch == null
- ? componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_KEY)
- : componentFinder.getByKeyAndBranch(dbSession, componentKey, branch);
+ return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_COMPONENT);
}
}
*/
package org.sonar.server.ce.ws;
-import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskCharacteristicDto;
-import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.SnapshotDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonarqube.ws.Common;
import org.sonarqube.ws.WsCe;
setNullable(organizationKey, builder::setOrganization);
if (dto.getComponentUuid() != null) {
builder.setComponentId(dto.getComponentUuid());
- buildComponent(builder, dto.getComponentUuid(), componentDtoCache);
+ setComponent(builder, dto.getComponentUuid(), componentDtoCache);
}
builder.setId(dto.getUuid());
builder.setStatus(WsCe.TaskStatus.valueOf(dto.getStatus().name()));
builder.setSubmittedAt(formatDateTime(new Date(dto.getCreatedAt())));
setNullable(dto.getStartedAt(), builder::setStartedAt, DateUtils::formatDateTime);
setNullable(computeExecutionTimeMs(dto), builder::setExecutionTimeMs);
- builder.setIncremental(componentDtoCache.hasIncrementalCharacteristic(dto.getUuid()));
- componentDtoCache.getBranchName(dto.getUuid()).ifPresent(
- b -> {
- builder.setBranch(b);
- builder.setBranchType(componentDtoCache.getBranchType(dto.getUuid())
- .orElseThrow(() -> new IllegalStateException(format("Could not find branch type of '%s'", dto.getUuid()))));
- });
+ setIncremental(builder, dto.getUuid(), componentDtoCache);
+ setBranch(builder, dto.getUuid(), componentDtoCache);
return builder.build();
}
builder.setStatus(WsCe.TaskStatus.valueOf(dto.getStatus().name()));
builder.setType(dto.getTaskType());
builder.setLogs(false);
- setNullable(dto.getComponentUuid(), uuid -> buildComponent(builder, uuid, componentDtoCache).setComponentId(uuid));
+ setNullable(dto.getComponentUuid(), uuid -> setComponent(builder, uuid, componentDtoCache).setComponentId(uuid));
String analysisUuid = dto.getAnalysisUuid();
if (analysisUuid != null) {
builder.setAnalysisId(analysisUuid);
}
- SnapshotDto analysis = analysisUuid == null ? null : componentDtoCache.getAnalysis(analysisUuid);
- builder.setIncremental(analysis != null && analysis.getIncremental());
+ setIncremental(builder, dto.getUuid(), componentDtoCache);
+ setBranch(builder, dto.getUuid(), componentDtoCache);
setNullable(analysisUuid, builder::setAnalysisId);
setNullable(dto.getSubmitterLogin(), builder::setSubmitterLogin);
builder.setSubmittedAt(formatDateTime(new Date(dto.getSubmittedAt())));
return builder.build();
}
- private static WsCe.Task.Builder buildComponent(WsCe.Task.Builder builder, @Nullable String componentUuid, DtoCache componentDtoCache) {
+ private static WsCe.Task.Builder setComponent(WsCe.Task.Builder builder, @Nullable String componentUuid, DtoCache componentDtoCache) {
ComponentDto componentDto = componentDtoCache.getComponent(componentUuid);
if (componentDto == null) {
return builder;
builder.setComponentKey(componentDto.getKey());
builder.setComponentName(componentDto.name());
builder.setComponentQualifier(componentDto.qualifier());
- String branch = componentDto.getBranch();
- if (branch == null) {
- return builder;
- }
- builder.setBranch(branch);
- builder.setBranchType(Common.BranchType.valueOf(componentDtoCache.getBranch(componentUuid).getBranchType().name()));
+ return builder;
+ }
+
+ private static WsCe.Task.Builder setIncremental(WsCe.Task.Builder builder, String taskUuid, DtoCache componentDtoCache) {
+ builder.setIncremental(componentDtoCache.hasIncrementalCharacteristic(taskUuid));
+ return builder;
+ }
+
+ private static WsCe.Task.Builder setBranch(WsCe.Task.Builder builder, String taskUuid, DtoCache componentDtoCache) {
+ componentDtoCache.getBranchName(taskUuid).ifPresent(
+ b -> {
+ builder.setBranch(b);
+ builder.setBranchType(componentDtoCache.getBranchType(taskUuid)
+ .orElseThrow(() -> new IllegalStateException(format("Could not find branch type of task '%s'", taskUuid))));
+ });
return builder;
}
private static class DtoCache {
private final Map<String, ComponentDto> componentsByUuid;
private final Map<String, OrganizationDto> organizationsByUuid;
- private final Map<String, SnapshotDto> analysisByUuid;
- private final Map<String, BranchDto> branchesByUuid;
private final Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid;
- private DtoCache(Map<String, ComponentDto> componentsByUuid, Map<String, OrganizationDto> organizationsByUuid, Map<String, SnapshotDto> analysisByUuid,
- Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid, Map<String, BranchDto> branchesByUuid) {
+ private DtoCache(Map<String, ComponentDto> componentsByUuid, Map<String, OrganizationDto> organizationsByUuid,
+ Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid) {
this.componentsByUuid = componentsByUuid;
this.organizationsByUuid = organizationsByUuid;
- this.analysisByUuid = analysisByUuid;
this.characteristicsByTaskUuid = characteristicsByTaskUuid;
- this.branchesByUuid = branchesByUuid;
}
static DtoCache forQueueDtos(DbClient dbClient, DbSession dbSession, Collection<CeQueueDto> ceQueueDtos) {
Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao()
.selectByTaskUuids(dbSession, ceQueueDtos.stream().map(CeQueueDto::getUuid).collect(Collectors.toList()))
.stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
- Map<String, BranchDto> branchesByUuid = dbClient.branchDao().selectByUuids(dbSession, componentsByUuid.keySet()).stream()
- .collect(MoreCollectors.uniqueIndex(BranchDto::getUuid));
- return new DtoCache(componentsByUuid, buildOrganizationsByUuid(dbClient, dbSession, componentsByUuid), Collections.emptyMap(), characteristicsByTaskUuid,
- branchesByUuid);
+ return new DtoCache(componentsByUuid, buildOrganizationsByUuid(dbClient, dbSession, componentsByUuid), characteristicsByTaskUuid);
}
private static Set<String> uuidOfCeQueueDtos(Collection<CeQueueDto> ceQueueDtos) {
uuidOfCeActivityDtos(ceActivityDtos))
.stream()
.collect(MoreCollectors.uniqueIndex(ComponentDto::uuid));
- Set<String> analysisUuids = ceActivityDtos.stream().map(CeActivityDto::getAnalysisUuid).filter(Objects::nonNull).collect(MoreCollectors.toSet());
- Map<String, SnapshotDto> analysisByUuid = dbClient.snapshotDao().selectByUuids(dbSession, analysisUuids).stream().collect(MoreCollectors.uniqueIndex(SnapshotDto::getUuid));
- Map<String, BranchDto> branchesByUuid = dbClient.branchDao().selectByUuids(dbSession, componentsByUuid.keySet()).stream()
- .collect(MoreCollectors.uniqueIndex(BranchDto::getUuid));
- return new DtoCache(componentsByUuid, buildOrganizationsByUuid(dbClient, dbSession, componentsByUuid), analysisByUuid,
- ImmutableMultimap.<String, CeTaskCharacteristicDto>builder().build(), branchesByUuid);
+ Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao()
+ .selectByTaskUuids(dbSession, ceActivityDtos.stream().map(CeActivityDto::getUuid).collect(Collectors.toList()))
+ .stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
+ return new DtoCache(componentsByUuid, buildOrganizationsByUuid(dbClient, dbSession, componentsByUuid), characteristicsByTaskUuid);
}
private static Set<String> uuidOfCeActivityDtos(Collection<CeActivityDto> ceActivityDtos) {
return organizationDto.getKey();
}
- @CheckForNull
- SnapshotDto getAnalysis(String analysisUuid) {
- return analysisByUuid.get(analysisUuid);
- }
-
- @CheckForNull
- BranchDto getBranch(String componentUuid) {
- return branchesByUuid.get(componentUuid);
- }
-
boolean hasIncrementalCharacteristic(String taskUuid) {
return characteristicsByTaskUuid.get(taskUuid).stream()
.filter(c -> c.getKey().equals(CeTaskCharacteristicDto.INCREMENTAL_KEY))
public void incremental_analysis_on_single_project() {
ComponentDto project = db.components().insertPrivateProject();
SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- insertActivity("T1", project, SUCCESS, incrementalAnalysis);
+ CeActivityDto activity = insertActivity("T1", project, SUCCESS, incrementalAnalysis);
+ insertCharacteristic(activity, INCREMENTAL_KEY, "true");
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
ActivityResponse activityResponse = call(ws.newRequest()
ComponentDto project = db.components().insertPrivateProject();
SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
SnapshotDto standardAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(false));
- insertActivity("T1", project, SUCCESS, incrementalAnalysis);
+ CeActivityDto incrementalTask = insertActivity("T1", project, SUCCESS, incrementalAnalysis);
+ insertCharacteristic(incrementalTask, INCREMENTAL_KEY, "true");
insertActivity("T2", project, SUCCESS, standardAnalysis);
logInAsSystemAdministrator();
public void incremental_analysis_on_search_uuid() {
ComponentDto project = db.components().insertPrivateProject();
SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- insertActivity("T1", project, SUCCESS, incrementalAnalysis);
+ CeActivityDto activity = insertActivity("T1", project, SUCCESS, incrementalAnalysis);
+ insertCharacteristic(activity, INCREMENTAL_KEY, "true");
logInAsSystemAdministrator();
ActivityResponse activityResponse = call(ws.newRequest()
userSession.addProjectPermission(UserRole.USER, project);
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG));
SnapshotDto analysis = db.components().insertSnapshot(longLivingBranch);
- insertActivity("T1", longLivingBranch, SUCCESS, analysis);
+ CeActivityDto activity = insertActivity("T1", project, SUCCESS, analysis);
+ insertCharacteristic(activity, BRANCH_KEY, longLivingBranch.getBranch());
+ insertCharacteristic(activity, BRANCH_TYPE_KEY, LONG.name());
ActivityResponse response = ws.newRequest().executeProtobuf(ActivityResponse.class);
}
private CeTaskCharacteristicDto insertCharacteristic(CeQueueDto queueDto, String key, String value) {
+ return insertCharacteristic(queueDto.getUuid(), key, value);
+ }
+
+ private CeTaskCharacteristicDto insertCharacteristic(CeActivityDto activityDto, String key, String value) {
+ return insertCharacteristic(activityDto.getUuid(), key, value);
+ }
+
+ private CeTaskCharacteristicDto insertCharacteristic(String taskUuid, String key, String value) {
CeTaskCharacteristicDto dto = new CeTaskCharacteristicDto()
.setUuid(Uuids.createFast())
- .setTaskUuid(queueDto.getUuid())
+ .setTaskUuid(taskUuid)
.setKey(key)
.setValue(value);
db.getDbClient().ceTaskCharacteristicsDao().insert(db.getSession(), Collections.singletonList(dto));
import static org.sonar.db.ce.CeQueueTesting.newCeQueueDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.test.JsonAssert.assertJson;
+import static org.sonarqube.ws.client.ce.CeWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY;
public class ActivityStatusActionTest {
request.setParam(PARAM_COMPONENT_ID, componentUuid);
}
if (componentKey != null) {
- request.setParam(PARAM_COMPONENT_KEY, componentKey);
+ request.setParam(DEPRECATED_PARAM_COMPONENT_KEY, componentKey);
}
return request.executeProtobuf(WsCe.ActivityStatusWsResponse.class);
}
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY;
import static org.sonar.db.ce.CeTaskCharacteristicDto.INCREMENTAL_KEY;
import static org.sonar.db.component.BranchType.LONG;
-import static org.sonar.db.component.ComponentTesting.newFileDto;
+import static org.sonar.db.component.BranchType.SHORT;
+import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH;
public class ComponentActionTest {
userSession.addProjectPermission(UserRole.USER, project);
WsCe.ProjectResponse response = ws.newRequest()
- .setParam("componentId", project.uuid())
+ .setParam(PARAM_COMPONENT, project.getKey())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.getQueueCount()).isEqualTo(0);
insertQueue("T5", project1, PENDING);
WsCe.ProjectResponse response = ws.newRequest()
- .setParam("componentId", project1.uuid())
+ .setParam(PARAM_COMPONENT, project1.getKey())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.getQueueCount()).isEqualTo(2);
assertThat(response.getQueue(0).getId()).isEqualTo("T4");
insertActivity("T1", project, CeActivityDto.Status.SUCCESS, analysis);
WsCe.ProjectResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT_KEY, project.getDbKey())
+ .setParam(PARAM_COMPONENT, project.getDbKey())
+ .executeProtobuf(WsCe.ProjectResponse.class);
+ assertThat(response.hasCurrent()).isTrue();
+ assertThat(response.getCurrent().getId()).isEqualTo("T1");
+ assertThat(response.getCurrent().getAnalysisId()).isEqualTo(analysis.getUuid());
+ }
+
+ @Test
+ public void search_tasks_by_component_id() {
+ ComponentDto project = db.components().insertPrivateProject();
+ logInWithBrowsePermission(project);
+ SnapshotDto analysis = db.components().insertSnapshot(project);
+ insertActivity("T1", project, CeActivityDto.Status.SUCCESS, analysis);
+
+ WsCe.ProjectResponse response = ws.newRequest()
+ .setParam(PARAM_COMPONENT_ID, project.uuid())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.hasCurrent()).isTrue();
assertThat(response.getCurrent().getId()).isEqualTo("T1");
insertActivity("T5", project, CeActivityDto.Status.CANCELED);
WsCe.ProjectResponse response = ws.newRequest()
- .setParam("componentId", project.uuid())
+ .setParam(PARAM_COMPONENT, project.getKey())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.getQueueCount()).isEqualTo(0);
// T3 is the latest task executed on PROJECT_1 ignoring Canceled ones
assertThat(response.getCurrent().getId()).isEqualTo("T3");
}
- @Test
- public void incremental_analysis_by_component_id() {
- ComponentDto project = db.components().insertPrivateProject();
- userSession.logIn().addProjectPermission(UserRole.USER, project);
- SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- insertActivity("T1", project, SUCCESS, incrementalAnalysis);
-
- WsCe.ProjectResponse response = ws.newRequest()
- .setParam("componentId", project.uuid())
- .executeProtobuf(WsCe.ProjectResponse.class);
-
- assertThat(response.getCurrent())
- .extracting(WsCe.Task::getId, WsCe.Task::getIncremental)
- .containsExactlyInAnyOrder("T1", true);
- }
-
@Test
public void incremental_analysis_by_component_key() {
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- insertActivity("T1", project, SUCCESS, incrementalAnalysis);
+ CeActivityDto activity = insertActivity("T1", project, SUCCESS, incrementalAnalysis);
+ insertCharacteristic(activity, INCREMENTAL_KEY, "true");
WsCe.ProjectResponse response = ws.newRequest()
- .setParam("componentKey", project.getKey())
+ .setParam(PARAM_COMPONENT, project.getKey())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.getCurrent())
insertCharacteristic(queue2, INCREMENTAL_KEY, "true");
WsCe.ProjectResponse response = ws.newRequest()
- .setParam("componentId", project.uuid())
+ .setParam(PARAM_COMPONENT, project.getKey())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.getQueueList())
userSession.addProjectPermission(UserRole.USER, project);
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG));
SnapshotDto analysis = db.components().insertSnapshot(longLivingBranch);
- insertActivity("T1", longLivingBranch, SUCCESS, analysis);
+ CeActivityDto activity = insertActivity("T1", project, SUCCESS, analysis);
+ insertCharacteristic(activity, BRANCH_KEY, longLivingBranch.getBranch());
+ insertCharacteristic(activity, BRANCH_TYPE_KEY, LONG.name());
WsCe.ProjectResponse response = ws.newRequest()
- .setParam("componentKey", longLivingBranch.getKey())
- .setParam("branch", longLivingBranch.getBranch())
+ .setParam(PARAM_COMPONENT, project.getKey())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.getCurrent())
.extracting(WsCe.Task::getId, WsCe.Task::getBranch, WsCe.Task::getBranchType, WsCe.Task::getStatus, WsCe.Task::getComponentKey)
.containsOnly(
- "T1", longLivingBranch.getBranch(), Common.BranchType.LONG, WsCe.TaskStatus.SUCCESS, longLivingBranch.getKey());
+ "T1", longLivingBranch.getBranch(), Common.BranchType.LONG, WsCe.TaskStatus.SUCCESS, project.getKey());
}
@Test
ComponentDto project = db.components().insertMainBranch();
userSession.addProjectPermission(UserRole.USER, project);
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG));
- CeQueueDto queue1 = insertQueue("T1", longLivingBranch, IN_PROGRESS);
+ CeQueueDto queue1 = insertQueue("T1", project, IN_PROGRESS);
insertCharacteristic(queue1, BRANCH_KEY, longLivingBranch.getBranch());
insertCharacteristic(queue1, BRANCH_TYPE_KEY, LONG.name());
- CeQueueDto queue2 = insertQueue("T2", longLivingBranch, PENDING);
+ CeQueueDto queue2 = insertQueue("T2", project, PENDING);
insertCharacteristic(queue2, BRANCH_KEY, longLivingBranch.getBranch());
insertCharacteristic(queue2, BRANCH_TYPE_KEY, LONG.name());
WsCe.ProjectResponse response = ws.newRequest()
- .setParam("componentKey", longLivingBranch.getKey())
- .setParam("branch", longLivingBranch.getBranch())
+ .setParam(PARAM_COMPONENT, longLivingBranch.getKey())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.getQueueList())
.extracting(WsCe.Task::getId, WsCe.Task::getBranch, WsCe.Task::getBranchType, WsCe.Task::getStatus, WsCe.Task::getComponentKey)
.containsOnly(
- tuple("T1", longLivingBranch.getBranch(), Common.BranchType.LONG, WsCe.TaskStatus.IN_PROGRESS, longLivingBranch.getKey()),
- tuple("T2", longLivingBranch.getBranch(), Common.BranchType.LONG, WsCe.TaskStatus.PENDING, longLivingBranch.getKey()));
+ tuple("T1", longLivingBranch.getBranch(), Common.BranchType.LONG, WsCe.TaskStatus.IN_PROGRESS, project.getKey()),
+ tuple("T2", longLivingBranch.getBranch(), Common.BranchType.LONG, WsCe.TaskStatus.PENDING, project.getKey()));
+ }
+
+ @Test
+ public void return_many_tasks_from_same_project() {
+ ComponentDto project = db.components().insertMainBranch();
+ userSession.addProjectPermission(UserRole.USER, project);
+ insertQueue("Main", project, IN_PROGRESS);
+ ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG).setKey("long-branch"));
+ CeQueueDto longLivingBranchQueue = insertQueue("Long", project, IN_PROGRESS);
+ insertCharacteristic(longLivingBranchQueue, BRANCH_KEY, longLivingBranch.getBranch());
+ insertCharacteristic(longLivingBranchQueue, BRANCH_TYPE_KEY, LONG.name());
+ ComponentDto shortLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT).setKey("short-branch"));
+ CeQueueDto shortLivingBranchQueue = insertQueue("Short", project, PENDING);
+ insertCharacteristic(shortLivingBranchQueue, BRANCH_KEY, shortLivingBranch.getBranch());
+ insertCharacteristic(shortLivingBranchQueue, BRANCH_TYPE_KEY, SHORT.name());
+ CeQueueDto incrementalQueue = insertQueue("Incremental", project, PENDING);
+ insertCharacteristic(incrementalQueue, INCREMENTAL_KEY, "true");
+
+ WsCe.ProjectResponse response = ws.newRequest()
+ .setParam(PARAM_COMPONENT, longLivingBranch.getKey())
+ .executeProtobuf(WsCe.ProjectResponse.class);
+
+ assertThat(response.getQueueList())
+ .extracting(WsCe.Task::getId, WsCe.Task::getComponentKey, WsCe.Task::getBranch, WsCe.Task::getBranchType, WsCe.Task::getIncremental)
+ .containsOnly(
+ tuple("Main", project.getKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE, false),
+ tuple("Long", longLivingBranch.getKey(), longLivingBranch.getBranch(), Common.BranchType.LONG, false),
+ tuple("Short", shortLivingBranch.getKey(), shortLivingBranch.getBranch(), Common.BranchType.SHORT, false),
+ tuple("Incremental", project.getKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE, true));
+ }
+
+ @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);
+
+ WsCe.ProjectResponse response = ws.newRequest()
+ .setParam("componentKey", project.getKey())
+ .executeProtobuf(WsCe.ProjectResponse.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() throws Exception {
expectedException.expect(NotFoundException.class);
ws.newRequest()
- .setParam("componentId", "UNKNOWN")
+ .setParam(PARAM_COMPONENT, "UNKNOWN")
.setMediaType(MediaTypes.PROTOBUF)
.execute();
}
expectedException.expectMessage("Insufficient privileges");
ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, project.uuid())
+ .setParam(PARAM_COMPONENT, project.getKey())
.execute();
}
ws.newRequest().execute();
}
- @Test
- public void fail_if_branch_does_not_exist() {
- 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(NotFoundException.class);
- expectedException.expectMessage(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch"));
-
- ws.newRequest()
- .setParam(PARAM_COMPONENT_KEY, file.getKey())
- .setParam(PARAM_BRANCH, "another_branch")
- .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("'componentId' and 'branch' parameters cannot be used at the same time");
-
- ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, file.uuid())
- .setParam(PARAM_BRANCH, "my_branch")
- .execute();
- }
-
private void logInWithBrowsePermission(ComponentDto project) {
userSession.logIn().addProjectPermission(UserRole.USER, project);
}
}
private CeTaskCharacteristicDto insertCharacteristic(CeQueueDto queueDto, String key, String value) {
+ return insertCharacteristic(queueDto.getUuid(), key, value);
+ }
+
+ private CeTaskCharacteristicDto insertCharacteristic(CeActivityDto activityDto, String key, String value) {
+ return insertCharacteristic(activityDto.getUuid(), key, value);
+ }
+
+ private CeTaskCharacteristicDto insertCharacteristic(String taskUuid, String key, String value) {
CeTaskCharacteristicDto dto = new CeTaskCharacteristicDto()
.setUuid(Uuids.createFast())
- .setTaskUuid(queueDto.getUuid())
+ .setTaskUuid(taskUuid)
.setKey(key)
.setValue(value);
db.getDbClient().ceTaskCharacteristicsDao().insert(db.getSession(), Collections.singletonList(dto));
import org.sonar.db.ce.CeTaskCharacteristicDto;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.SnapshotDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
logInAsRoot();
ComponentDto project = db.components().insertPrivateProject();
- SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- CeQueueDto queueDto = new CeQueueDto()
- .setTaskType(CeTaskTypes.REPORT)
- .setUuid(SOME_TASK_UUID)
- .setComponentUuid(project.uuid());
- CeActivityDto activityDto = new CeActivityDto(queueDto)
- .setStatus(CeActivityDto.Status.FAILED)
- .setExecutionTimeMs(500L)
- .setAnalysisUuid(analysis.getUuid());
- persist(activityDto);
+ db.components().insertSnapshot(project, s -> s.setIncremental(true));
+ CeActivityDto activity = createAndPersistArchivedTask(project);
+ insertCharacteristic(activity, "incremental", "true");
WsCe.TaskResponse taskResponse = ws.newRequest()
.setParam("id", SOME_TASK_UUID)
ComponentDto project = db.components().insertMainBranch();
userSession.addProjectPermission(UserRole.USER, project);
ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG));
- SnapshotDto analysis = db.components().insertSnapshot(longLivingBranch);
- CeQueueDto queueDto = new CeQueueDto()
- .setTaskType(CeTaskTypes.REPORT)
- .setUuid(SOME_TASK_UUID)
- .setComponentUuid(longLivingBranch.uuid());
- CeActivityDto activityDto = new CeActivityDto(queueDto)
- .setStatus(CeActivityDto.Status.FAILED)
- .setExecutionTimeMs(500L)
- .setAnalysisUuid(analysis.getUuid());
- persist(activityDto);
+ db.components().insertSnapshot(longLivingBranch);
+ CeActivityDto activity = createAndPersistArchivedTask(project);
+ insertCharacteristic(activity, BRANCH_KEY, longLivingBranch.getBranch());
+ insertCharacteristic(activity, BRANCH_TYPE_KEY, LONG.name());
WsCe.TaskResponse taskResponse = ws.newRequest()
.setParam("id", SOME_TASK_UUID)
}
private CeTaskCharacteristicDto insertCharacteristic(CeQueueDto queueDto, String key, String value) {
+ return insertCharacteristic(queueDto.getUuid(), key, value);
+ }
+
+ private CeTaskCharacteristicDto insertCharacteristic(CeActivityDto activityDto, String key, String value) {
+ return insertCharacteristic(activityDto.getUuid(), key, value);
+ }
+
+ private CeTaskCharacteristicDto insertCharacteristic(String taskUuid, String key, String value) {
CeTaskCharacteristicDto dto = new CeTaskCharacteristicDto()
.setUuid(Uuids.createFast())
- .setTaskUuid(queueDto.getUuid())
+ .setTaskUuid(taskUuid)
.setKey(key)
.setValue(value);
db.getDbClient().ceTaskCharacteristicsDao().insert(db.getSession(), Collections.singletonList(dto));
import org.sonarqube.ws.client.WsConnector;
import static org.sonarqube.ws.client.ce.CeWsParameters.ACTION_WORKER_COUNT;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_BRANCH;
+import static org.sonarqube.ws.client.ce.CeWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
+import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MAX_EXECUTED_AT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MIN_SUBMITTED_AT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_ONLY_CURRENTS;
return call(
new GetRequest(path("activity_status"))
.setParam(PARAM_COMPONENT_ID, request.getComponentId())
- .setParam(PARAM_COMPONENT_KEY, request.getComponentKey()),
+ .setParam(DEPRECATED_PARAM_COMPONENT_KEY, request.getComponentKey()),
WsCe.ActivityStatusWsResponse.parser());
}
return call(new GetRequest(path(ACTION_WORKER_COUNT)), WorkerCountResponse.parser());
}
- public ProjectResponse component(String componentKey, String branch) {
+ public ProjectResponse component(String componentKey) {
return call(
new GetRequest(path("component"))
- .setParam(PARAM_COMPONENT_KEY, componentKey)
- .setParam(PARAM_BRANCH, branch),
+ .setParam(PARAM_COMPONENT, componentKey),
ProjectResponse.parser());
}
public static final String ACTION_WORKER_COUNT = "worker_count";
public static final String PARAM_COMPONENT_ID = "componentId";
- public static final String PARAM_COMPONENT_KEY = "componentKey";
+ public static final String DEPRECATED_PARAM_COMPONENT_KEY = "componentKey";
+ public static final String PARAM_COMPONENT = "component";
public static final String PARAM_COMPONENT_QUERY = "componentQuery";
public static final String PARAM_TYPE = "type";
public static final String PARAM_STATUS = "status";
public static final String PARAM_ONLY_CURRENTS = "onlyCurrents";
public static final String PARAM_MIN_SUBMITTED_AT = "minSubmittedAt";
public static final String PARAM_MAX_EXECUTED_AT = "maxExecutedAt";
- public static final String PARAM_BRANCH = "branch";
private CeWsParameters() {
// prevent instantiation
}
enum BranchType {
- // Zero is required in order to not get MAINTAINABILITY as default value
+ // Zero is required in order to not get LONG as default value
// See http://androiddevblog.com/protocol-buffers-pitfall-adding-enum-values/
UNKNOWN_BRANCH_TYPE = 0;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.MapEntry.entry;
import static org.mockito.Mockito.mock;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_BRANCH;
+import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MAX_EXECUTED_AT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MIN_SUBMITTED_AT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_ONLY_CURRENTS;
@Test
public void task_with_stacktrace_and_scanner_context() {
underTest.task(TaskWsRequest.newBuilder("task_id")
- .withErrorStacktrace()
- .withScannerContext()
- .build());
+ .withErrorStacktrace()
+ .withScannerContext()
+ .build());
assertThat(serviceTester.getGetRequest().getPath()).isEqualTo("api/ce/task");
assertThat(serviceTester.getGetRequest().getParams()).containsOnly(entry("id", "task_id"), entry("additionalFields", "stacktrace,scannerContext"));
@Test
public void task_with_scanner_context_only() {
underTest.task(TaskWsRequest.newBuilder("task_id")
- .withScannerContext()
- .build());
+ .withScannerContext()
+ .build());
assertThat(serviceTester.getGetRequest().getPath()).isEqualTo("api/ce/task");
assertThat(serviceTester.getGetRequest().getParams()).containsOnly(entry("id", "task_id"), entry("additionalFields", "scannerContext"));
@Test
public void task_with_stacktrace_only() {
underTest.task(TaskWsRequest.newBuilder("task_id")
- .withErrorStacktrace()
- .build());
+ .withErrorStacktrace()
+ .build());
assertThat(serviceTester.getGetRequest().getPath()).isEqualTo("api/ce/task");
assertThat(serviceTester.getGetRequest().getParams()).containsOnly(entry("id", "task_id"), entry("additionalFields", "stacktrace"));
@Test
public void component() {
- underTest.component("my_component", "my_branch");
+ underTest.component("my_component");
GetRequest result = serviceTester.getGetRequest();
assertThat(serviceTester.getGetParser()).isSameAs(WsCe.ProjectResponse.parser());
serviceTester.assertThat(result)
.hasPath("component")
- .hasParam(PARAM_COMPONENT_KEY, "my_component")
- .hasParam(PARAM_BRANCH, "my_branch")
+ .hasParam(PARAM_COMPONENT, "my_component")
.andNoOtherParam();
}
}