Search in sources :

Example 11 with FileAttributes

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

the class ReportPersistComponentsStepTest method persist_components_of_existing_branch.

@Test
public void persist_components_of_existing_branch() {
    ComponentDto project = prepareBranch("feature/foo");
    Component file = builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java").setName("src/main/java/dir/Foo.java").setShortName("Foo.java").setFileAttributes(new FileAttributes(false, "java", 1)).build();
    Component directory = builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir").setName("src/main/java/dir").setShortName("dir").addChildren(file).build();
    Component treeRoot = asTreeRoot(project).addChildren(directory).build();
    treeRootHolder.setRoot(treeRoot);
    underTest.execute(new TestComputationStepContext());
    assertThat(db.countRowsOfTable("components")).isEqualTo(3);
    ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
    assertThat(directoryDto.name()).isEqualTo("dir");
    assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir");
    assertThat(directoryDto.description()).isNull();
    assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
    assertThat(directoryDto.uuid()).isEqualTo("CDEF");
    assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + project.uuid() + UUID_PATH_SEPARATOR);
    assertThat(directoryDto.moduleUuid()).isEqualTo(project.uuid());
    assertThat(directoryDto.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
    assertThat(directoryDto.getMainBranchProjectUuid()).isEqualTo(project.uuid());
    assertThat(directoryDto.projectUuid()).isEqualTo(project.uuid());
    assertThat(directoryDto.qualifier()).isEqualTo("DIR");
    assertThat(directoryDto.scope()).isEqualTo("DIR");
    assertThat(directoryDto.getRootUuid()).isEqualTo(project.uuid());
    assertThat(directoryDto.getCreatedAt()).isEqualTo(now);
    ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
    assertThat(fileDto.name()).isEqualTo("Foo.java");
    assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java");
    assertThat(fileDto.description()).isNull();
    assertThat(fileDto.path()).isEqualTo("src/main/java/dir/Foo.java");
    assertThat(fileDto.language()).isEqualTo("java");
    assertThat(fileDto.uuid()).isEqualTo("DEFG");
    assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
    assertThat(fileDto.moduleUuid()).isEqualTo(project.uuid());
    assertThat(fileDto.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
    assertThat(fileDto.getMainBranchProjectUuid()).isEqualTo(project.uuid());
    assertThat(fileDto.projectUuid()).isEqualTo(project.uuid());
    assertThat(fileDto.qualifier()).isEqualTo("FIL");
    assertThat(fileDto.scope()).isEqualTo("FIL");
    assertThat(fileDto.getRootUuid()).isEqualTo(project.uuid());
    assertThat(fileDto.getCreatedAt()).isEqualTo(now);
}
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) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 12 with FileAttributes

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

the class ReportPersistComponentsStepTest method update_file_to_directory_change_scope.

@Test
public void update_file_to_directory_change_scope() {
    ComponentDto project = prepareProject();
    ComponentDto directory = ComponentTesting.newDirectory(project, "src").setUuid("CDEF").setDbKey("PROJECT_KEY:src");
    ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/foo").setName("foo").setDbKey("PROJECT_KEY:src/foo");
    dbClient.componentDao().insert(db.getSession(), directory, file);
    db.getSession().commit();
    assertThat(dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/foo").get().scope()).isEqualTo("FIL");
    treeRootHolder.setRoot(asTreeRoot(project).addChildren(builder(DIRECTORY, 2).setUuid("CDEF").setKey(PROJECT_KEY + ":src").setName("src").addChildren(builder(DIRECTORY, 3).setUuid("DEFG").setKey(PROJECT_KEY + ":src/foo").setName("foo").addChildren(builder(FILE, 4).setUuid("HIJK").setKey(PROJECT_KEY + ":src/foo/FooTest.java").setName("src/foo/FooTest.java").setShortName("FooTest.java").setFileAttributes(new FileAttributes(false, null, 1)).build()).build()).build()).build());
    underTest.execute(new TestComputationStepContext());
    // commit the functional transaction
    dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
    db.commit();
    assertThat(dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/foo").get().scope()).isEqualTo("DIR");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 13 with FileAttributes

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

the class PersistFileSourcesStepTest method initBasicReport.

private void initBasicReport(int numberOfLines) {
    ReportComponent root = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(fileComponent().setFileAttributes(new FileAttributes(false, null, numberOfLines)).build()).build();
    treeRootHolder.setRoots(root, root);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes)

Example 14 with FileAttributes

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

the class NewMaintainabilityMeasuresVisitorTest method leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt.

@Test
public void leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt() {
    when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
    Component file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build();
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(DIRECTORY, 111).addChildren(file).build()).build());
    Measure newDebtMeasure = createNewDebtMeasure(50);
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
    measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150));
    measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250));
    // 4 lines file, only first one is not ncloc
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    // first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date
    setNewLines(file, 3, 4);
    underTest.visit(treeRootHolder.getRoot());
    assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33);
    assertNewDebtRatioValues(111, 83.33);
    assertNewDebtRatioValues(ROOT_REF, 83.33);
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 15 with FileAttributes

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

the class NewMaintainabilityMeasuresVisitorTest method compute_new_development_cost.

@Test
public void compute_new_development_cost() {
    ReportComponent file1 = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 4)).build();
    ReportComponent file2 = builder(FILE, 22_222).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 6)).build();
    when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(DIRECTORY, 111).addChildren(file1, file2).build()).build());
    // 4 lines file, only first one is not ncloc
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    // first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date
    setNewLines(file1, 3, 4);
    // 6 lines file, only last one is not ncloc
    measureRepository.addRawMeasure(22_222, NCLOC_DATA_KEY, createNclocDataMeasure(1, 2, 3, 4, 5));
    // first 2 lines are before all snapshots, 4 last lines are after PERIOD 2's snapshot date
    setNewLines(file2, 3, 4, 5, 6);
    underTest.visit(treeRootHolder.getRoot());
    assertNewDevelopmentCostValues(ROOT_REF, 5 * LANGUAGE_1_DEV_COST);
    assertNewDevelopmentCostValues(LANGUAGE_1_FILE_REF, 2 * LANGUAGE_1_DEV_COST);
    assertNewDevelopmentCostValues(22_222, 3 * LANGUAGE_1_DEV_COST);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Aggregations

FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)20 Test (org.junit.Test)17 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)12 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)8 Component (org.sonar.ce.task.projectanalysis.component.Component)6 ComponentDto (org.sonar.db.component.ComponentDto)5 Measure (org.sonar.ce.task.projectanalysis.measure.Measure)3 DefaultIssue (org.sonar.core.issue.DefaultIssue)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Block (org.sonar.duplications.block.Block)1 ByteArray (org.sonar.duplications.block.ByteArray)1