Search in sources :

Example 21 with Component

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

the class PurgeDatastoresStepTest method call_purge_method_of_the_purge_task_for_project.

@Test
public void call_purge_method_of_the_purge_task_for_project() {
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).build();
    verify_call_purge_method_of_the_purge_task(project);
}
Also used : ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 22 with Component

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

the class EffortAggregator method beforeComponent.

@Override
public void beforeComponent(Component component) {
    effortCounter = new EffortCounter();
    effortsByComponentUuid.put(component.getUuid(), effortCounter);
    // aggregate children counters
    for (Component child : component.getChildren()) {
        // no need to keep the children in memory. They can be garbage-collected.
        EffortCounter childEffortCounter = effortsByComponentUuid.remove(child.getUuid());
        if (childEffortCounter != null) {
            effortCounter.add(childEffortCounter);
        }
    }
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 23 with Component

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

the class FileMoveDetectionStepTest method execute_detects_no_move_if_two_files_are_empty_in_DB.

@Test
public void execute_detects_no_move_if_two_files_are_empty_in_DB() {
    analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
    Component file1 = fileComponent(FILE_1_REF, null);
    Component file2 = fileComponent(FILE_2_REF, null);
    insertFiles(file1.getUuid(), file2.getUuid());
    insertContentOfFileInDb(file1.getUuid(), null);
    insertContentOfFileInDb(file2.getUuid(), null);
    setFilesInReport(file1, file2);
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
    assertThat(scoreMatrixDumper.scoreMatrix).isNull();
    assertThat(addedFileRepository.getComponents()).isEmpty();
    verifyStatistics(context, 2, 2, 0, null);
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 24 with Component

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

the class FileMoveDetectionStepTest method execute_detects_move_if_content_of_file_is_same_in_DB_and_report.

@Test
public void execute_detects_move_if_content_of_file_is_same_in_DB_and_report() {
    analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
    Component file1 = fileComponent(FILE_1_REF, null);
    Component file2 = fileComponent(FILE_2_REF, CONTENT1);
    ComponentDto[] dtos = insertFiles(file1.getUuid());
    insertContentOfFileInDb(file1.getUuid(), CONTENT1);
    setFilesInReport(file2);
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    assertThat(movedFilesRepository.getComponentsWithOriginal()).containsExactly(file2);
    MovedFilesRepository.OriginalFile originalFile = movedFilesRepository.getOriginalFile(file2).get();
    assertThat(originalFile.getKey()).isEqualTo(dtos[0].getDbKey());
    assertThat(originalFile.getUuid()).isEqualTo(dtos[0].uuid());
    assertThat(addedFileRepository.getComponents()).isEmpty();
    verifyStatistics(context, 1, 1, 1, 1);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 25 with Component

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

the class FileMoveDetectionStepTest method execute_does_not_compute_any_distance_if_all_files_sizes_are_all_too_different.

@Test
public void execute_does_not_compute_any_distance_if_all_files_sizes_are_all_too_different() {
    analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
    Component file1 = fileComponent(FILE_1_REF, null);
    Component file2 = fileComponent(FILE_2_REF, null);
    Component file3 = fileComponent(FILE_3_REF, arrayOf(118));
    Component file4 = fileComponent(5, arrayOf(25));
    insertFiles(file1.getDbKey(), file2.getDbKey());
    insertContentOfFileInDb(file1.getDbKey(), arrayOf(100));
    insertContentOfFileInDb(file2.getDbKey(), arrayOf(30));
    setFilesInReport(file3, file4);
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty();
    assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isZero();
    verifyStatistics(context, 2, 2, 2, 0);
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

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