use of org.sonar.ce.task.projectanalysis.component.ComponentUuidFactoryWithMigration 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());
}
}
Aggregations