Search in sources :

Example 6 with BranchDto

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());
        }
    }
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 7 with BranchDto

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());
        }
    }
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 8 with BranchDto

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);
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto)

Example 9 with BranchDto

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);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) Random(java.util.Random) RuleKey(org.sonar.api.rule.RuleKey) RuleDto(org.sonar.db.rule.RuleDto) Before(org.junit.Before)

Example 10 with BranchDto

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());
}
Also used : ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) BranchDto(org.sonar.db.component.BranchDto) DbTester(org.sonar.db.DbTester) BranchType(org.sonar.db.component.BranchType) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ComponentRepositoryImpl(org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) MetricDto(org.sonar.db.metric.MetricDto) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) INT(org.sonar.api.measures.Metric.ValueType.INT) ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) ProjectDto(org.sonar.db.project.ProjectDto) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Mockito.mock(org.mockito.Mockito.mock) MetricDto(org.sonar.db.metric.MetricDto) BranchDto(org.sonar.db.component.BranchDto) ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Aggregations

BranchDto (org.sonar.db.component.BranchDto)111 Test (org.junit.Test)62 ComponentDto (org.sonar.db.component.ComponentDto)52 ProjectDto (org.sonar.db.project.ProjectDto)42 DbSession (org.sonar.db.DbSession)31 SnapshotDto (org.sonar.db.component.SnapshotDto)22 List (java.util.List)15 ComponentTesting.newBranchDto (org.sonar.db.component.ComponentTesting.newBranchDto)13 DbClient (org.sonar.db.DbClient)12 MetricDto (org.sonar.db.metric.MetricDto)12 Map (java.util.Map)9 Optional (java.util.Optional)9 Nullable (javax.annotation.Nullable)9 WebService (org.sonar.api.server.ws.WebService)9 System2 (org.sonar.api.utils.System2)9 NotFoundException (org.sonar.server.exceptions.NotFoundException)9 Collection (java.util.Collection)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Rule (org.junit.Rule)8 Request (org.sonar.api.server.ws.Request)8