use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ElementsAndCoveredElementsCounter method initialize.
@Override
public void initialize(CounterInitializationContext context) {
Component component = context.getLeaf();
if (component.getType() == Component.Type.FILE && component.getFileAttributes().isUnitTest()) {
return;
}
initializeForSupportedLeaf(context);
}
use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class IssueCounter method beforeComponent.
@Override
public void beforeComponent(Component component) {
// TODO optimization no need to instantiate counter if no open issues
currentCounters = new Counters();
countersByComponentRef.put(component.getReportAttributes().getRef(), currentCounters);
// aggregate children counters
for (Component child : component.getChildren()) {
// no need to keep the children in memory. They can be garbage-collected.
Counters childCounters = countersByComponentRef.remove(child.getReportAttributes().getRef());
currentCounters.add(childCounters);
}
}
use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class FileMoveDetectionStep method execute.
@Override
public void execute() {
// do nothing if no files in db (first analysis)
Analysis baseProjectAnalysis = analysisMetadataHolder.getBaseAnalysis();
if (baseProjectAnalysis == null) {
LOG.debug("First analysis. Do nothing.");
return;
}
Map<String, DbComponent> dbFilesByKey = getDbFilesByKey();
if (dbFilesByKey.isEmpty()) {
LOG.debug("Previous snapshot has no file. Do nothing.");
return;
}
Map<String, Component> reportFilesByKey = getReportFilesByKey(this.rootHolder.getRoot());
if (reportFilesByKey.isEmpty()) {
LOG.debug("No files in report. Do nothing.");
return;
}
Set<String> addedFileKeys = ImmutableSet.copyOf(Sets.difference(reportFilesByKey.keySet(), dbFilesByKey.keySet()));
Set<String> removedFileKeys = ImmutableSet.copyOf(Sets.difference(dbFilesByKey.keySet(), reportFilesByKey.keySet()));
// can find matches if at least one of the added or removed files groups is empty => abort
if (addedFileKeys.isEmpty() || removedFileKeys.isEmpty()) {
LOG.debug("Either no files added or no files removed. Do nothing.");
return;
}
// retrieve file data from report
Map<String, File> reportFileSourcesByKey = getReportFileSourcesByKey(reportFilesByKey, addedFileKeys);
// compute score matrix
ScoreMatrix scoreMatrix = computeScoreMatrix(dbFilesByKey, removedFileKeys, reportFileSourcesByKey);
printIfDebug(scoreMatrix);
// not a single match with score higher than MIN_REQUIRED_SCORE => abort
if (scoreMatrix.getMaxScore() < MIN_REQUIRED_SCORE) {
LOG.debug("max score in matrix is less than min required score (%s). Do nothing.", MIN_REQUIRED_SCORE);
return;
}
MatchesByScore matchesByScore = MatchesByScore.create(scoreMatrix);
ElectedMatches electedMatches = electMatches(removedFileKeys, reportFileSourcesByKey, matchesByScore);
registerMatches(dbFilesByKey, reportFilesByKey, electedMatches);
}
use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class FileMoveDetectionStep method getReportFileSourcesByKey.
private Map<String, File> getReportFileSourcesByKey(Map<String, Component> reportFilesByKey, Set<String> addedFileKeys) {
ImmutableMap.Builder<String, File> builder = ImmutableMap.builder();
for (String fileKey : addedFileKeys) {
// FIXME computation of sourceHash and lineHashes might be done multiple times for some files: here, in ComputeFileSourceData, in
// SourceHashRepository
Component component = reportFilesByKey.get(fileKey);
SourceLinesHashesComputer linesHashesComputer = new SourceLinesHashesComputer();
try (CloseableIterator<String> lineIterator = sourceLinesRepository.readLines(component)) {
while (lineIterator.hasNext()) {
String line = lineIterator.next();
linesHashesComputer.addLine(line);
}
}
builder.put(fileKey, new File(component.getReportAttributes().getPath(), linesHashesComputer.getLineHashes()));
}
return builder.build();
}
use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class BuildComponentTreeStep method execute.
@Override
public void execute() {
String branch = analysisMetadataHolder.getBranch();
ScannerReport.Component reportProject = reportReader.readComponent(analysisMetadataHolder.getRootComponentRef());
String projectKey = createKey(reportProject.getKey(), branch);
UuidFactory uuidFactory = new UuidFactory(dbClient, projectKey);
try (DbSession dbSession = dbClient.openSession(false)) {
BaseAnalysisSupplier baseAnalysisSupplier = new BaseAnalysisSupplier(dbClient, dbSession);
ComponentRootBuilder rootBuilder = new ComponentRootBuilder(branch, uuidFactory::getOrCreateForKey, reportReader::readComponent, () -> dbClient.componentDao().selectByKey(dbSession, projectKey), baseAnalysisSupplier);
Component project = rootBuilder.build(reportProject, projectKey);
treeRootHolder.setRoot(project);
analysisMetadataHolder.setBaseAnalysis(toAnalysis(baseAnalysisSupplier.apply(project.getUuid())));
}
}
Aggregations