Search in sources :

Example 6 with Component

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

the class HandleUnanalyzedLanguagesStep method computeMeasures.

private void computeMeasures(Map<String, Integer> filesPerLanguage) {
    Component project = treeRootHolder.getRoot();
    Integer unanalyzedCFiles = filesPerLanguage.getOrDefault(C.toString(), 0);
    if (unanalyzedCFiles > 0) {
        measureRepository.add(project, unanalyzedCMetric, Measure.newMeasureBuilder().create(unanalyzedCFiles));
    }
    Integer unanalyzedCppFiles = filesPerLanguage.getOrDefault(CPP.toString(), 0);
    if (unanalyzedCppFiles > 0) {
        measureRepository.add(project, unanalyzedCppMetric, Measure.newMeasureBuilder().create(unanalyzedCppFiles));
    }
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 7 with Component

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

the class SendIssueNotificationsStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    BranchType branchType = analysisMetadataHolder.getBranch().getType();
    if (branchType == PULL_REQUEST) {
        return;
    }
    Component project = treeRootHolder.getRoot();
    NotificationStatistics notificationStatistics = new NotificationStatistics();
    if (service.hasProjectSubscribersForTypes(analysisMetadataHolder.getProject().getUuid(), NOTIF_TYPES)) {
        doExecute(notificationStatistics, project);
    }
    notificationStatistics.dumpTo(context);
}
Also used : BranchType(org.sonar.db.component.BranchType) Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 8 with Component

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

the class SendIssueNotificationsStep method doExecute.

private void doExecute(NotificationStatistics notificationStatistics, Component project) {
    long analysisDate = analysisMetadataHolder.getAnalysisDate();
    Predicate<DefaultIssue> onCurrentAnalysis = i -> i.isNew() && i.creationDate().getTime() >= truncateToSeconds(analysisDate);
    NewIssuesStatistics newIssuesStats = new NewIssuesStatistics(onCurrentAnalysis);
    Map<String, UserDto> assigneesByUuid;
    try (DbSession dbSession = dbClient.openSession(false)) {
        Iterable<DefaultIssue> iterable = protoIssueCache::traverse;
        Set<String> assigneeUuids = stream(iterable.spliterator(), false).map(DefaultIssue::assignee).filter(Objects::nonNull).collect(Collectors.toSet());
        assigneesByUuid = dbClient.userDao().selectByUuids(dbSession, assigneeUuids).stream().collect(toMap(UserDto::getUuid, dto -> dto));
    }
    try (CloseableIterator<DefaultIssue> issues = protoIssueCache.traverse()) {
        processIssues(newIssuesStats, issues, assigneesByUuid, notificationStatistics);
    }
    if (newIssuesStats.hasIssuesOnCurrentAnalysis()) {
        sendNewIssuesNotification(newIssuesStats, project, assigneesByUuid, analysisDate, notificationStatistics);
        sendMyNewIssuesNotification(newIssuesStats, project, assigneesByUuid, analysisDate, notificationStatistics);
    }
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) Duration(org.sonar.api.utils.Duration) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date) NewIssuesStatistics(org.sonar.server.issue.notification.NewIssuesStatistics) DbSession(org.sonar.db.DbSession) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) RuleType(org.sonar.api.rules.RuleType) HashSet(java.util.HashSet) MoreCollectors.toSet(org.sonar.core.util.stream.MoreCollectors.toSet) ComputationStep(org.sonar.ce.task.step.ComputationStep) Collections.singleton(java.util.Collections.singleton) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) NotificationService(org.sonar.server.notification.NotificationService) Component(org.sonar.ce.task.projectanalysis.component.Component) ProtoIssueCache(org.sonar.ce.task.projectanalysis.issue.ProtoIssueCache) BranchType(org.sonar.db.component.BranchType) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultIssue(org.sonar.core.issue.DefaultIssue) Predicate(java.util.function.Predicate) Notification(org.sonar.api.notifications.Notification) CloseableIterator(org.sonar.core.util.CloseableIterator) Set(java.util.Set) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) AnalysisMetadataHolder(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder) Objects(java.util.Objects) DbClient(org.sonar.db.DbClient) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ChronoUnit(java.time.temporal.ChronoUnit) Issue(org.sonar.api.issue.Issue) StreamSupport.stream(java.util.stream.StreamSupport.stream) NotificationFactory(org.sonar.ce.task.projectanalysis.notification.NotificationFactory) TreeRootHolder(org.sonar.ce.task.projectanalysis.component.TreeRootHolder) CheckForNull(javax.annotation.CheckForNull) DbSession(org.sonar.db.DbSession) NewIssuesStatistics(org.sonar.server.issue.notification.NewIssuesStatistics) UserDto(org.sonar.db.user.UserDto) DefaultIssue(org.sonar.core.issue.DefaultIssue)

Example 9 with Component

use of org.sonar.ce.task.projectanalysis.component.Component 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 10 with Component

use of org.sonar.ce.task.projectanalysis.component.Component 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)

Aggregations

Component (org.sonar.ce.task.projectanalysis.component.Component)118 Test (org.junit.Test)82 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)47 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 ComponentDto (org.sonar.db.component.ComponentDto)25 ViewsComponent (org.sonar.ce.task.projectanalysis.component.ViewsComponent)14 DefaultIssue (org.sonar.core.issue.DefaultIssue)14 DbSession (org.sonar.db.DbSession)11 Period (org.sonar.ce.task.projectanalysis.period.Period)8 SnapshotDto (org.sonar.db.component.SnapshotDto)8 FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)6 DbClient (org.sonar.db.DbClient)6 List (java.util.List)5 ComputationStep (org.sonar.ce.task.step.ComputationStep)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 DepthTraversalTypeAwareCrawler (org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 Map (java.util.Map)3