use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class TargetBranchComponentUuids method initForTargetBranch.
private void initForTargetBranch(DbSession dbSession) {
Optional<BranchDto> branchDtoOpt = dbClient.branchDao().selectByBranchKey(dbSession, analysisMetadataHolder.getProject().getUuid(), analysisMetadataHolder.getBranch().getTargetBranchName());
targetBranchUuid = branchDtoOpt.map(BranchDto::getUuid).orElse(null);
hasTargetBranchAnalysis = targetBranchUuid != null && dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, targetBranchUuid).isPresent();
if (hasTargetBranchAnalysis) {
List<ComponentDto> targetComponents = dbClient.componentDao().selectByProjectUuid(targetBranchUuid, dbSession);
for (ComponentDto dto : targetComponents) {
targetBranchComponentsUuidsByKey.put(dto.getKey(), dto.uuid());
}
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SourceBranchComponentUuids method initForSourceBranch.
private void initForSourceBranch(DbSession dbSession) {
Optional<BranchDto> branchDtoOpt = dbClient.branchDao().selectByBranchKey(dbSession, analysisMetadataHolder.getProject().getUuid(), analysisMetadataHolder.getBranch().getName());
String sourceBranchUuid = branchDtoOpt.map(BranchDto::getUuid).orElse(null);
hasSourceBranchAnalysis = sourceBranchUuid != null && dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, sourceBranchUuid).isPresent();
if (hasSourceBranchAnalysis) {
List<ComponentDto> targetComponents = dbClient.componentDao().selectByProjectUuid(sourceBranchUuid, dbSession);
for (ComponentDto dto : targetComponents) {
sourceBranchComponentsUuidsByKey.put(dto.getKey(), dto.uuid());
}
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class LoadProjectStep method execute.
@Override
public void execute(Context context) {
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = dbClient.projectDao().selectProjectByKey(dbSession, descriptor.getKey()).orElseThrow(() -> MessageException.of(format("Project with key [%s] does not exist", descriptor.getKey())));
definitionHolder.setProjectDto(project);
List<BranchDto> branches = dbClient.branchDao().selectByProject(dbSession, project).stream().collect(toList());
definitionHolder.setBranches(branches);
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ExportIssuesStepTest method setUp.
@Before
public void setUp() {
ProjectDto project = createProject();
when(projectHolder.projectDto()).thenReturn(project);
when(projectHolder.branches()).thenReturn(newArrayList(new BranchDto().setBranchType(BranchType.BRANCH).setKey("master").setProjectUuid(SOME_PROJECT_UUID).setUuid(SOME_PROJECT_UUID)));
// adds a random number of Rules to db and repository so that READY_RULE_KEY does always get id=ref=1
for (int i = 0; i < new Random().nextInt(150); i++) {
RuleKey ruleKey = RuleKey.of("repo_" + i, "key_" + i);
RuleDto ruleDto = insertRule(ruleKey.toString());
ruleRepository.register(ruleDto.getUuid(), ruleKey);
}
this.readyRuleDto = insertRule(READY_RULE_KEY);
componentRepository.register(12, SOME_PROJECT_UUID, false);
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ExportLiveMeasuresStepTest method export_measures.
@Test
public void export_measures() {
ComponentDto project = createProject(true);
componentRepository.register(1, project.uuid(), false);
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()));
dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(4711.0d).setVariation(null));
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(project));
when(projectHolder.branches()).thenReturn(newArrayList(new BranchDto().setProjectUuid(project.uuid()).setUuid(project.uuid()).setKey("master").setBranchType(BranchType.BRANCH)));
underTest.execute(new TestComputationStepContext());
List<ProjectDump.LiveMeasure> exportedMeasures = dumpWriter.getWrittenMessagesOf(DumpElement.LIVE_MEASURES);
assertThat(exportedMeasures).hasSize(1);
assertThat(exportedMeasures).extracting(ProjectDump.LiveMeasure::getMetricRef, m -> m.getDoubleValue().getValue(), ProjectDump.LiveMeasure::hasVariation).containsOnly(tuple(0, 4711.0d, false));
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
}
Aggregations