Search in sources :

Example 1 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class BranchPersisterImpl method persist.

public void persist(DbSession dbSession) {
    Branch branch = analysisMetadataHolder.getBranch();
    String branchUuid = treeRootHolder.getRoot().getUuid();
    ComponentDto branchComponentDto = dbClient.componentDao().selectByUuid(dbSession, branchUuid).orElseThrow(() -> new IllegalStateException("Component has been deleted by end-user during analysis"));
    // insert or update in table project_branches
    dbClient.branchDao().upsert(dbSession, toBranchDto(dbSession, branchComponentDto, branch, checkIfExcludedFromPurge()));
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) ComponentDto(org.sonar.db.component.ComponentDto)

Example 2 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class PostProjectAnalysisTasksExecutorTest method setUp.

@Before
public void setUp() {
    qualityGateHolder.setQualityGate(new QualityGate(QUALITY_GATE_UUID, QUALITY_GATE_NAME, of(CONDITION_1, CONDITION_2)));
    qualityGateStatusHolder.setStatus(QualityGateStatus.OK, ImmutableMap.of(CONDITION_1, ConditionStatus.create(ConditionStatus.EvaluationStatus.OK, "value"), CONDITION_2, ConditionStatus.NO_VALUE_STATUS));
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(BranchType.BRANCH);
    analysisMetadataHolder.setBranch(branch);
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Before(org.junit.Before)

Example 3 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class BranchPersisterImplTest method createPullRequest.

private static Branch createPullRequest(String key, String mergeBranchUuid) {
    Branch branch = createBranch(PULL_REQUEST, false, key, mergeBranchUuid);
    when(branch.getPullRequestKey()).thenReturn(key);
    return branch;
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch)

Example 4 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class ComponentTreeBuilderTest method newUnderTest.

private ComponentTreeBuilder newUnderTest(ProjectAttributes projectAttributes, boolean mainBranch) {
    Branch branch = mock(Branch.class);
    when(branch.isMain()).thenReturn(mainBranch);
    return new ComponentTreeBuilder(KEY_GENERATOR, PUBLIC_KEY_GENERATOR, UUID_SUPPLIER, scannerComponentProvider, projectInDb, branch, projectAttributes);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch)

Example 5 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class ConfigurationRepositoryTest method branch_settings.

@Test
public void branch_settings() {
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto branchDto = db.components().insertProjectBranch(project);
    Branch branch = mock(Branch.class);
    when(branch.getName()).thenReturn(branchDto.getBranch());
    analysisMetadataHolder.setProject(Project.from(project)).setBranch(branch);
    globalSettings.setProperty("global", "global value");
    insertProjectProperty(project, "project", "project value");
    insertProjectProperty(branchDto, "branch", "branch value");
    Configuration config = underTest.getConfiguration();
    assertThat(config.get("global")).hasValue("global value");
    assertThat(config.get("project")).hasValue("project value");
    assertThat(config.get("branch")).hasValue("branch value");
}
Also used : Configuration(org.sonar.api.config.Configuration) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)40 Test (org.junit.Test)21 DefaultIssue (org.sonar.core.issue.DefaultIssue)7 ComponentDto (org.sonar.db.component.ComponentDto)7 Before (org.junit.Before)5 BranchType (org.sonar.db.component.BranchType)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Rule (org.junit.Rule)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.when (org.mockito.Mockito.when)4 AnalysisMetadataHolderRule (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule)4 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)4 DbTester (org.sonar.db.DbTester)4 Project (org.sonar.server.project.Project)4 Date (java.util.Date)3 FieldDiffs (org.sonar.core.issue.FieldDiffs)3 ComponentTesting (org.sonar.db.component.ComponentTesting)3 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)3 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)3 RuleKey (org.sonar.api.rule.RuleKey)2