Search in sources :

Example 6 with Component

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

the class NewEffortAggregator method beforeComponent.

@Override
public void beforeComponent(Component component) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<IssueChangeDto> changes = dbClient.issueChangeDao().selectChangelogOfNonClosedIssuesByComponent(dbSession, component.getUuid());
        for (IssueChangeDto change : changes) {
            changesByIssueUuid.put(change.getIssueKey(), change);
        }
    }
    counter = new NewEffortCounter(calculator);
    counterByComponentRef.put(component.getReportAttributes().getRef(), counter);
    for (Component child : component.getChildren()) {
        NewEffortCounter childSum = counterByComponentRef.remove(child.getReportAttributes().getRef());
        if (childSum != null) {
            counter.add(childSum);
        }
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) DbSession(org.sonar.db.DbSession) Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 7 with Component

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

the class PersistCrossProjectDuplicationIndexStep method execute.

@Override
public void execute() {
    if (!crossProjectDuplicationStatusHolder.isEnabled()) {
        return;
    }
    try (DbSession dbSession = dbClient.openSession(true)) {
        Component project = treeRootHolder.getRoot();
        new DepthTraversalTypeAwareCrawler(new DuplicationVisitor(dbSession, analysisMetadataHolder.getUuid())).visit(project);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 8 with Component

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

the class UpdateQualityProfilesLastUsedDateStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(true)) {
        Component root = treeRootHolder.getRoot();
        Metric metric = metricRepository.getByKey(QUALITY_PROFILES_KEY);
        Set<QualityProfile> qualityProfiles = parseQualityProfiles(measureRepository.getRawMeasure(root, metric));
        if (qualityProfiles.isEmpty()) {
            return;
        }
        List<QualityProfileDto> dtos = dbClient.qualityProfileDao().selectByKeys(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
        dtos.addAll(getAncestors(dbSession, dtos));
        long analysisDate = analysisMetadataHolder.getAnalysisDate();
        dtos.forEach(dto -> {
            dto.setLastUsed(analysisDate);
            dbClient.qualityProfileDao().update(dbSession, dto);
        });
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Component(org.sonar.server.computation.task.projectanalysis.component.Component) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 9 with Component

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

the class ValidateProjectStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Component root = treeRootHolder.getRoot();
        List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey());
        Map<String, ComponentDto> baseModulesByKey = from(baseModules).uniqueIndex(ComponentDto::key);
        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 : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 10 with Component

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

the class IntegrateCrossProjectDuplicationsTest method add_duplication_for_java_even_when_no_token.

@Test
public void add_duplication_for_java_even_when_no_token() {
    Component javaFile = builder(FILE, 1).setKey(ORIGIN_FILE_KEY).setFileAttributes(new FileAttributes(false, "java", 10)).build();
    Collection<Block> originBlocks = singletonList(// This block contains 0 token
    new Block.Builder().setResourceId(ORIGIN_FILE_KEY).setBlockHash(new ByteArray("a8998353e96320ec")).setIndexInFile(0).setLines(30, 45).setUnit(0, 0).build());
    Collection<Block> duplicatedBlocks = singletonList(new Block.Builder().setResourceId(OTHER_FILE_KEY).setBlockHash(new ByteArray("a8998353e96320ec")).setIndexInFile(0).setLines(40, 55).build());
    underTest.computeCpd(javaFile, originBlocks, duplicatedBlocks);
    assertThat(duplicationRepository.getDuplications(ORIGIN_FILE)).containsExactly(crossProjectDuplication(new TextBlock(30, 45), OTHER_FILE_KEY, new TextBlock(40, 55)));
}
Also used : Block(org.sonar.duplications.block.Block) ByteArray(org.sonar.duplications.block.ByteArray) Component(org.sonar.server.computation.task.projectanalysis.component.Component) FileAttributes(org.sonar.server.computation.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

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