Search in sources :

Example 86 with Component

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

Example 87 with Component

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

the class PersistProjectLinksStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    if (!analysisMetadataHolder.getBranch().isMain()) {
        return;
    }
    try (DbSession session = dbClient.openSession(false)) {
        Component project = treeRootHolder.getRoot();
        ScannerReport.Component batchComponent = reportReader.readComponent(project.getReportAttributes().getRef());
        List<ProjectLinkDto> previousLinks = dbClient.projectLinkDao().selectByProjectUuid(session, project.getUuid());
        mergeLinks(session, project.getUuid(), batchComponent.getLinkList(), previousLinks);
        session.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 88 with Component

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

the class PersistProjectLinksStep method mergeLinks.

private void mergeLinks(DbSession session, String componentUuid, List<ScannerReport.ComponentLink> links, List<ProjectLinkDto> previousLinks) {
    Set<String> linkType = new HashSet<>();
    links.forEach(link -> {
        String type = convertType(link.getType());
        checkArgument(!linkType.contains(type), "Link of type '%s' has already been declared on component '%s'", type, componentUuid);
        linkType.add(type);
        Optional<ProjectLinkDto> previousLink = previousLinks.stream().filter(input -> input != null && input.getType().equals(convertType(link.getType()))).findFirst();
        if (previousLink.isPresent()) {
            previousLink.get().setHref(link.getHref());
            dbClient.projectLinkDao().update(session, previousLink.get());
        } else {
            dbClient.projectLinkDao().insert(session, new ProjectLinkDto().setUuid(uuidFactory.create()).setProjectUuid(componentUuid).setType(type).setHref(link.getHref()));
        }
    });
    previousLinks.stream().filter(dto -> !linkType.contains(dto.getType())).filter(dto -> ProjectLinkDto.PROVIDED_TYPES.contains(dto.getType())).forEach(dto -> dbClient.projectLinkDao().delete(session, dto.getUuid()));
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) UuidFactory(org.sonar.core.util.UuidFactory) Set(java.util.Set) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) DbSession(org.sonar.db.DbSession) ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) AnalysisMetadataHolder(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder) HashSet(java.util.HashSet) ComponentLinkType(org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType) DbClient(org.sonar.db.DbClient) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ComputationStep(org.sonar.ce.task.step.ComputationStep) Map(java.util.Map) BatchReportReader(org.sonar.ce.task.projectanalysis.batch.BatchReportReader) TreeRootHolder(org.sonar.ce.task.projectanalysis.component.TreeRootHolder) Optional(java.util.Optional) ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) HashSet(java.util.HashSet)

Example 89 with Component

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

the class UpdateNeedIssueSyncStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Component project = treeRootHolder.getRoot();
        dbClient.branchDao().updateNeedIssueSync(dbSession, project.getUuid(), false);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 90 with Component

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

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