use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class EnableAnalysisStep method execute.
@Override
public void execute(ComputationStep.Context context) {
try (DbSession dbSession = dbClient.openSession(false)) {
Component project = treeRootHolder.getRoot();
dbClient.snapshotDao().switchIsLastFlagAndSetProcessedStatus(dbSession, project.getUuid(), analysisMetadataHolder.getUuid());
dbClient.componentDao().applyBChangesForRootComponentUuid(dbSession, project.getUuid());
dbSession.commit();
}
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class UpdateQualityProfilesLastUsedDateStep method execute.
@Override
public void execute(ComputationStep.Context context) {
Component root = treeRootHolder.getRoot();
Metric metric = metricRepository.getByKey(QUALITY_PROFILES_KEY);
Set<QualityProfile> qualityProfiles = parseQualityProfiles(measureRepository.getRawMeasure(root, metric));
try (DbSession dbSession = dbClient.openSession(true)) {
for (QualityProfile qualityProfile : qualityProfiles) {
updateDate(dbSession, qualityProfile.getQpKey(), analysisMetadataHolder.getAnalysisDate());
}
dbSession.commit();
}
}
use of org.sonar.ce.task.projectanalysis.component.Component 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.component.Component in project sonarqube by SonarSource.
the class FileMoveDetectionStep method execute.
@Override
public void execute(ComputationStep.Context context) {
// do nothing if no files in db (first analysis)
if (analysisMetadataHolder.isFirstAnalysis()) {
LOG.debug("First analysis. Do nothing.");
return;
}
Profiler p = Profiler.createIfTrace(LOG);
p.start();
Map<String, Component> reportFilesByUuid = getReportFilesByUuid(this.rootHolder.getRoot());
context.getStatistics().add("reportFiles", reportFilesByUuid.size());
if (reportFilesByUuid.isEmpty()) {
LOG.debug("No files in report. No file move detection.");
return;
}
Map<String, DbComponent> dbFilesByUuid = getDbFilesByUuid();
context.getStatistics().add("dbFiles", dbFilesByUuid.size());
Set<String> addedFileUuids = difference(reportFilesByUuid.keySet(), dbFilesByUuid.keySet());
context.getStatistics().add("addedFiles", addedFileUuids.size());
if (dbFilesByUuid.isEmpty()) {
registerAddedFiles(addedFileUuids, reportFilesByUuid, null);
LOG.debug("Previous snapshot has no file. No file move detection.");
return;
}
Set<String> removedFileUuids = difference(dbFilesByUuid.keySet(), reportFilesByUuid.keySet());
// can't find matches if at least one of the added or removed files groups is empty => abort
if (addedFileUuids.isEmpty() || removedFileUuids.isEmpty()) {
registerAddedFiles(addedFileUuids, reportFilesByUuid, null);
LOG.debug("Either no files added or no files removed. Do nothing.");
return;
}
// retrieve file data from report
Map<String, File> addedFileHashesByUuid = getReportFileHashesByUuid(reportFilesByUuid, addedFileUuids);
p.stopTrace("loaded");
// compute score matrix
p.start();
ScoreMatrix scoreMatrix = computeScoreMatrix(dbFilesByUuid, removedFileUuids, addedFileHashesByUuid);
p.stopTrace("Score matrix computed");
scoreMatrixDumper.dumpAsCsv(scoreMatrix);
// not a single match with score higher than MIN_REQUIRED_SCORE => abort
if (scoreMatrix.getMaxScore() < MIN_REQUIRED_SCORE) {
context.getStatistics().add("movedFiles", 0);
registerAddedFiles(addedFileUuids, reportFilesByUuid, null);
LOG.debug("max score in matrix is less than min required score ({}). Do nothing.", MIN_REQUIRED_SCORE);
return;
}
p.start();
MatchesByScore matchesByScore = MatchesByScore.create(scoreMatrix);
ElectedMatches electedMatches = electMatches(removedFileUuids, addedFileHashesByUuid, matchesByScore);
p.stopTrace("Matches elected");
context.getStatistics().add("movedFiles", electedMatches.size());
registerMatches(dbFilesByUuid, reportFilesByUuid, electedMatches);
registerAddedFiles(addedFileUuids, reportFilesByUuid, electedMatches);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class FileMoveDetectionStep method getReportFilesByUuid.
private static Map<String, Component> getReportFilesByUuid(Component root) {
final ImmutableMap.Builder<String, Component> builder = ImmutableMap.builder();
new DepthTraversalTypeAwareCrawler(new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) {
@Override
public void visitFile(Component file) {
builder.put(file.getUuid(), file);
}
}).visit(root);
return builder.build();
}
Aggregations