Search in sources :

Example 1 with Analysis

use of org.sonar.server.computation.task.projectanalysis.analysis.Analysis 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)

Aggregations

Analysis (org.sonar.server.computation.task.projectanalysis.analysis.Analysis)1 Component (org.sonar.server.computation.task.projectanalysis.component.Component)1 File (org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File)1