Search in sources :

Example 81 with Component

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

the class SignificantCodeRepositoryTest method return_null_for_lines_without_information.

@Test
public void return_null_for_lines_without_information() {
    Component component = createComponent(5);
    List<ScannerReport.LineSgnificantCode> significantCode = new ArrayList<>();
    // line 3 and 5 missing
    significantCode.add(createLineSignificantCode(1, 1, 2));
    significantCode.add(createLineSignificantCode(2, 1, 2));
    significantCode.add(createLineSignificantCode(4, 1, 2));
    reportReader.putSignificantCode(component.getReportAttributes().getRef(), significantCode);
    assertThat(underTest.getRangesPerLine(component)).isNotEmpty();
    LineRange[] lines = underTest.getRangesPerLine(component).get();
    assertThat(lines).hasSize(5);
    assertThat(lines[0]).isNotNull();
    assertThat(lines[1]).isNotNull();
    assertThat(lines[2]).isNull();
    assertThat(lines[3]).isNotNull();
    assertThat(lines[4]).isNull();
}
Also used : ArrayList(java.util.ArrayList) Component(org.sonar.ce.task.projectanalysis.component.Component) LineRange(org.sonar.core.hash.LineRange) LineSgnificantCode(org.sonar.scanner.protocol.output.ScannerReport.LineSgnificantCode) Test(org.junit.Test)

Example 82 with Component

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

the class SourceLinesDiffImplTest method should_find_diff_with_reference_branch_for_prs.

@Test
public void should_find_diff_with_reference_branch_for_prs() {
    periodHolder.setPeriod(null);
    Component component = fileComponent(FILE_REF);
    mockLineHashesInDb(2, CONTENT);
    setLineHashesInReport(component, CONTENT);
    when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
    when(referenceBranchComponentUuids.getComponentUuid(component.getKey())).thenReturn("uuid_2");
    assertThat(underTest.computeMatchingLines(component)).containsExactly(1, 2, 3, 4, 5, 6, 7);
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 83 with Component

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

the class SourceLinesDiffImplTest method should_find_no_diff_when_report_and_db_content_are_identical.

@Test
public void should_find_no_diff_when_report_and_db_content_are_identical() {
    periodHolder.setPeriod(null);
    Component component = fileComponent(FILE_REF);
    mockLineHashesInDb(FILE_REF, CONTENT);
    setLineHashesInReport(component, CONTENT);
    assertThat(underTest.computeMatchingLines(component)).containsExactly(1, 2, 3, 4, 5, 6, 7);
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 84 with Component

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

the class NewEffortAggregator method beforeComponent.

@Override
public void beforeComponent(Component component) {
    counter = new NewEffortCounter();
    counterByComponentUuid.put(component.getUuid(), counter);
    for (Component child : component.getChildren()) {
        NewEffortCounter childSum = counterByComponentUuid.remove(child.getUuid());
        if (childSum != null) {
            counter.add(childSum);
        }
    }
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 85 with Component

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

the class IssueCounter method beforeComponent.

@Override
public void beforeComponent(Component component) {
    currentCounters = new Counters();
    countersByComponentUuid.put(component.getUuid(), currentCounters);
    // aggregate children counters
    for (Component child : component.getChildren()) {
        Counters childCounters = countersByComponentUuid.remove(child.getUuid());
        currentCounters.add(childCounters);
    }
}
Also used : 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