Search in sources :

Example 1 with DepthTraversalTypeAwareCrawler

use of org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler in project sonarqube by SonarSource.

the class PersistAnalysisStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        new DepthTraversalTypeAwareCrawler(new PersistSnapshotsPathAwareVisitor(dbSession, analysisMetadataHolder.getAnalysisDate())).visit(treeRootHolder.getRoot());
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)

Example 2 with DepthTraversalTypeAwareCrawler

use of org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler in project sonarqube by SonarSource.

the class PersistCrossProjectDuplicationIndexStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    if (!crossProjectDuplicationStatusHolder.isEnabled()) {
        return;
    }
    try (DbSession dbSession = dbClient.openSession(true)) {
        Component project = treeRootHolder.getRoot();
        DuplicationVisitor visitor = new DuplicationVisitor(dbSession, analysisMetadataHolder.getUuid());
        new DepthTraversalTypeAwareCrawler(visitor).visit(project);
        dbSession.commit();
        context.getStatistics().add("inserts", visitor.count);
    }
}
Also used : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 3 with DepthTraversalTypeAwareCrawler

use of org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler in project sonarqube by SonarSource.

the class PersistDuplicationDataStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    boolean supportUpsert = dbClient.getDatabase().getDialect().supportsUpsert();
    // structure (same PreparedStatement))
    try (DbSession dbSession = dbClient.openSession(false);
        DuplicationVisitor visitor = new DuplicationVisitor(dbSession, supportUpsert)) {
        new DepthTraversalTypeAwareCrawler(visitor).visit(treeRootHolder.getRoot());
        context.getStatistics().add("insertsOrUpdates", visitor.insertsOrUpdates);
    }
}
Also used : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)

Example 4 with DepthTraversalTypeAwareCrawler

use of org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler in project sonarqube by SonarSource.

the class PersistLiveMeasuresStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    boolean supportUpsert = dbClient.getDatabase().getDialect().supportsUpsert();
    try (DbSession dbSession = dbClient.openSession(true)) {
        Component root = treeRootHolder.getRoot();
        MeasureVisitor visitor = new MeasureVisitor(dbSession, supportUpsert);
        new DepthTraversalTypeAwareCrawler(visitor).visit(root);
        dbSession.commit();
        context.getStatistics().add("insertsOrUpdates", visitor.insertsOrUpdates);
    }
}
Also used : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 5 with DepthTraversalTypeAwareCrawler

use of org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler in project sonarqube by SonarSource.

the class ValidateProjectStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        validateTargetBranch(dbSession);
        Component root = treeRootHolder.getRoot();
        // FIXME if module have really be dropped, no more need to load them
        List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getDbKey());
        Map<String, ComponentDto> baseModulesByKey = baseModules.stream().collect(Collectors.toMap(ComponentDto::getDbKey, x -> x));
        ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao(), baseModulesByKey);
        new DepthTraversalTypeAwareCrawler(visitor).visit(root);
        if (!visitor.validationMessages.isEmpty()) {
            throw MessageException.of("Validation of project failed:\n  o " + MESSAGES_JOINER.join(visitor.validationMessages));
        }
    }
}
Also used : BranchDto(org.sonar.db.component.BranchDto) Date(java.util.Date) TypeAwareVisitorAdapter(org.sonar.ce.task.projectanalysis.component.TypeAwareVisitorAdapter) DbSession(org.sonar.db.DbSession) ArrayList(java.util.ArrayList) ComputationStep(org.sonar.ce.task.step.ComputationStep) Map(java.util.Map) MessageException(org.sonar.api.utils.MessageException) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) Component(org.sonar.ce.task.projectanalysis.component.Component) DepthTraversalTypeAwareCrawler(org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) ComponentKeys.isValidProjectKey(org.sonar.core.component.ComponentKeys.isValidProjectKey) CrawlerDepthLimit(org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) AnalysisMetadataHolder(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DbClient(org.sonar.db.DbClient) ALLOWED_CHARACTERS_MESSAGE(org.sonar.core.component.ComponentKeys.ALLOWED_CHARACTERS_MESSAGE) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) TreeRootHolder(org.sonar.ce.task.projectanalysis.component.TreeRootHolder) Optional(java.util.Optional) ComponentVisitor(org.sonar.ce.task.projectanalysis.component.ComponentVisitor) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDao(org.sonar.db.component.ComponentDao) Joiner(com.google.common.base.Joiner) DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.ce.task.projectanalysis.component.Component)

Aggregations

DepthTraversalTypeAwareCrawler (org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)9 DbSession (org.sonar.db.DbSession)7 Component (org.sonar.ce.task.projectanalysis.component.Component)4 TypeAwareVisitorAdapter (org.sonar.ce.task.projectanalysis.component.TypeAwareVisitorAdapter)2 Joiner (com.google.common.base.Joiner)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 DateUtils.formatDateTime (org.sonar.api.utils.DateUtils.formatDateTime)1 MessageException (org.sonar.api.utils.MessageException)1 AnalysisMetadataHolder (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder)1 ComponentVisitor (org.sonar.ce.task.projectanalysis.component.ComponentVisitor)1 CrawlerDepthLimit (org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit)1 TreeRootHolder (org.sonar.ce.task.projectanalysis.component.TreeRootHolder)1