use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class BuildComponentTreeStepTest method generate_keys_when_using_existing_branch.
@Test
public void generate_keys_when_using_existing_branch() {
ComponentDto projectDto = dbTester.components().insertPublicProject();
ComponentDto branchDto = dbTester.components().insertProjectBranch(projectDto);
Branch branch = mock(Branch.class);
when(branch.getName()).thenReturn(branchDto.getBranch());
when(branch.isMain()).thenReturn(false);
when(branch.generateKey(any(), any())).thenReturn(branchDto.getDbKey());
analysisMetadataHolder.setRootComponentRef(ROOT_REF).setAnalysisDate(ANALYSIS_DATE).setProject(Project.from(projectDto)).setBranch(branch);
BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath);
reportReader.putComponent(component(ROOT_REF, PROJECT, branchDto.getKey()));
underTest.execute(new TestComputationStepContext());
verifyComponentByRef(ROOT_REF, branchDto.getDbKey(), branchDto.getKey(), analysisMetadataHolder.getProject().getName(), branchDto.uuid());
}
use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class BuildComponentTreeStep method execute.
@Override
public void execute(ComputationStep.Context context) {
try (DbSession dbSession = dbClient.openSession(false)) {
ScannerReport.Component reportProject = reportReader.readComponent(analysisMetadataHolder.getRootComponentRef());
ComponentKeyGenerator keyGenerator = loadKeyGenerator();
ComponentKeyGenerator publicKeyGenerator = loadPublicKeyGenerator();
ScannerReport.Metadata metadata = reportReader.readMetadata();
// root key of branch, not necessarily of project
String rootKey = keyGenerator.generateKey(reportProject.getKey(), null);
Function<String, String> pathToKey = path -> keyGenerator.generateKey(reportProject.getKey(), path);
// loads the UUIDs from database. If they don't exist, then generate new ones
ComponentUuidFactoryWithMigration componentUuidFactoryWithMigration = new ComponentUuidFactoryWithMigration(dbClient, dbSession, rootKey, pathToKey, reportModulesPath.get());
String rootUuid = componentUuidFactoryWithMigration.getOrCreateForKey(rootKey);
Optional<SnapshotDto> baseAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, rootUuid);
ComponentTreeBuilder builder = new ComponentTreeBuilder(keyGenerator, publicKeyGenerator, componentUuidFactoryWithMigration::getOrCreateForKey, reportReader::readComponent, analysisMetadataHolder.getProject(), analysisMetadataHolder.getBranch(), createProjectAttributes(metadata, baseAnalysis.orElse(null)));
String relativePathFromScmRoot = metadata.getRelativePathFromScmRoot();
Component reportTreeRoot = builder.buildProject(reportProject, relativePathFromScmRoot);
if (analysisMetadataHolder.isPullRequest()) {
Component changedComponentTreeRoot = builder.buildChangedComponentTreeRoot(reportTreeRoot);
treeRootHolder.setRoots(changedComponentTreeRoot, reportTreeRoot);
} else {
treeRootHolder.setRoots(reportTreeRoot, reportTreeRoot);
}
analysisMetadataHolder.setBaseAnalysis(baseAnalysis.map(BuildComponentTreeStep::toAnalysis).orElse(null));
context.getStatistics().add("components", treeRootHolder.getSize());
}
}
use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class BranchPersisterImplTest method createBranch.
private static Branch createBranch(BranchType type, boolean isMain, String name, @Nullable String mergeBranchUuid) {
Branch branch = mock(Branch.class);
when(branch.getType()).thenReturn(type);
when(branch.getName()).thenReturn(name);
when(branch.isMain()).thenReturn(isMain);
when(branch.getReferenceBranchUuid()).thenReturn(mergeBranchUuid);
when(branch.getTargetBranchName()).thenReturn(mergeBranchUuid);
return branch;
}
use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class SiblingComponentsWithOpenIssuesTest method setBranch.
private void setBranch(BranchType currentBranchType, @Nullable String mergeBranchUuid) {
Branch branch = mock(Branch.class);
when(branch.getType()).thenReturn(currentBranchType);
when(branch.getReferenceBranchUuid()).thenReturn(mergeBranchUuid);
metadataHolder.setBranch(branch);
}
use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class ReferenceBranchComponentUuidsTest method setUp.
@Before
public void setUp() {
underTest = new ReferenceBranchComponentUuids(analysisMetadataHolder, db.getDbClient());
project = mock(Project.class);
analysisMetadataHolder.setProject(project);
analysisMetadataHolder.setBranch(branch);
ComponentDto projectDto = db.components().insertPublicProject();
when(project.getUuid()).thenReturn(projectDto.uuid());
branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch1"));
branch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch2"));
pr1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
pr2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
branch2File = ComponentTesting.newFileDto(branch2, null, "file").setUuid("branch2File");
pr1File = ComponentTesting.newFileDto(pr1, null, "file").setUuid("file1");
pr2File = ComponentTesting.newFileDto(pr2, null, "file").setUuid("file2");
db.components().insertComponents(branch1File, pr1File, pr2File, branch2File);
}
Aggregations