Search in sources :

Example 1 with Component

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);
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 2 with Component

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);
    }
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 3 with Component

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);
}
Also used : Analysis(org.sonar.server.computation.task.projectanalysis.analysis.Analysis) Component(org.sonar.server.computation.task.projectanalysis.component.Component) File(org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File)

Example 4 with Component

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();
}
Also used : SourceLinesHashesComputer(org.sonar.core.hash.SourceLinesHashesComputer) Component(org.sonar.server.computation.task.projectanalysis.component.Component) File(org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with Component

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())));
    }
}
Also used : DbSession(org.sonar.db.DbSession) UuidFactory(org.sonar.server.computation.task.projectanalysis.component.UuidFactory) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) ComponentRootBuilder(org.sonar.server.computation.task.projectanalysis.component.ComponentRootBuilder) Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Aggregations

Component (org.sonar.server.computation.task.projectanalysis.component.Component)55 Test (org.junit.Test)33 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)24 ViewsComponent (org.sonar.server.computation.task.projectanalysis.component.ViewsComponent)15 ComponentDto (org.sonar.db.component.ComponentDto)12 SnapshotDto (org.sonar.db.component.SnapshotDto)10 DbSession (org.sonar.db.DbSession)6 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)5 OrganizationDto (org.sonar.db.organization.OrganizationDto)5 DepthTraversalTypeAwareCrawler (org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)4 Period (org.sonar.server.computation.task.projectanalysis.period.Period)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FileAttributes (org.sonar.server.computation.task.projectanalysis.component.FileAttributes)2 TypeAwareVisitorAdapter (org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter)2 InProjectDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InProjectDuplicate)2 InnerDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate)2 File (org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1