use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes 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)));
}
use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.
the class CommonRuleEngineImplTest method do_not_process_files_with_unknown_language.
@Test
public void do_not_process_files_with_unknown_language() throws Exception {
ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, null, 1)).build();
Collection<DefaultIssue> issues = underTest.process(file);
assertThat(issues).isEmpty();
verifyZeroInteractions(rule1, rule2);
}
use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.
the class MaintainabilityMeasuresVisitorTest method compute_development_cost.
@Test
public void compute_development_cost() {
ReportComponent root = builder(PROJECT, 1).addChildren(builder(MODULE, 11).addChildren(builder(DIRECTORY, 111).addChildren(createFileComponent(LANGUAGE_KEY_1, 1111), createFileComponent(LANGUAGE_KEY_2, 1112), // Unit test should not be ignored
builder(FILE, 1113).setFileAttributes(new FileAttributes(true, LANGUAGE_KEY_1, 1)).build()).build(), builder(DIRECTORY, 112).addChildren(createFileComponent(LANGUAGE_KEY_2, 1121)).build()).build(), builder(MODULE, 12).addChildren(builder(DIRECTORY, 121).addChildren(createFileComponent(LANGUAGE_KEY_1, 1211)).build(), builder(DIRECTORY, 122).build()).build(), builder(MODULE, 13).build()).build();
treeRootHolder.setRoot(root);
int ncloc1111 = 10;
addRawMeasure(NCLOC_KEY, 1111, ncloc1111);
int ncloc1112 = 12;
addRawMeasure(NCLOC_KEY, 1112, ncloc1112);
int ncloc1113 = 15;
addRawMeasure(NCLOC_KEY, 1113, ncloc1113);
int nclocValue1121 = 30;
addRawMeasure(NCLOC_KEY, 1121, nclocValue1121);
int ncloc1211 = 20;
addRawMeasure(NCLOC_KEY, 1211, ncloc1211);
underTest.visit(root);
// verify measures on files
verifyAddedRawMeasure(1111, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(1112, DEVELOPMENT_COST_KEY, Long.toString(ncloc1112 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(1113, DEVELOPMENT_COST_KEY, Long.toString(ncloc1113 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(1121, DEVELOPMENT_COST_KEY, Long.toString(nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(1211, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
// directory has no children => no file => 0 everywhere and A rating
verifyAddedRawMeasure(122, DEVELOPMENT_COST_KEY, "0");
// directory has children => dev cost is aggregated
verifyAddedRawMeasure(111, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1 + ncloc1112 * DEV_COST_LANGUAGE_2 + ncloc1113 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(112, DEVELOPMENT_COST_KEY, Long.toString(nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(121, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
// just for fun, we didn't define any debt on module => they must all have rating A
verifyAddedRawMeasure(11, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1 + ncloc1112 * DEV_COST_LANGUAGE_2 + ncloc1113 * DEV_COST_LANGUAGE_1 + nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(12, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(13, DEVELOPMENT_COST_KEY, "0");
verifyAddedRawMeasure(1, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1 + ncloc1112 * DEV_COST_LANGUAGE_2 + ncloc1113 * DEV_COST_LANGUAGE_1 + nclocValue1121 * DEV_COST_LANGUAGE_2 + ncloc1211 * DEV_COST_LANGUAGE_1));
}
use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.
the class NewMaintainabilityMeasuresVisitorTest method setupOneFileAloneInAProject.
private void setupOneFileAloneInAProject(int newDebt, Flag isUnitTest, Flag withNclocLines, Flag withChangeSets) {
checkArgument(isUnitTest == Flag.UT_FILE || isUnitTest == Flag.SRC_FILE);
checkArgument(withNclocLines == Flag.WITH_NCLOC || withNclocLines == Flag.NO_NCLOC || withNclocLines == Flag.MISSING_MEASURE_NCLOC);
checkArgument(withChangeSets == Flag.WITH_CHANGESET || withChangeSets == Flag.NO_CHANGESET);
treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(isUnitTest == Flag.UT_FILE, LANGUAGE_1_KEY, 1)).build()).build());
Measure newDebtMeasure = createNewDebtMeasure(newDebt);
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
if (withNclocLines == Flag.WITH_NCLOC) {
// 4 lines file, only first one is not ncloc
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
} else if (withNclocLines == Flag.NO_NCLOC) {
// 4 lines file, none of which is ncloc
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNoNclocDataMeasure(4));
}
if (withChangeSets == Flag.WITH_CHANGESET) {
// first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date
scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_SNAPSHOT_DATE - 100, 2, PERIOD_SNAPSHOT_DATE + 100, 2));
}
}
use of org.sonar.server.computation.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.
the class ReportPersistComponentsStepTest method persist_unit_test.
@Test
public void persist_unit_test() {
treeRootHolder.setRoot(builder(PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setName("Project").addChildren(builder(DIRECTORY, 2).setUuid("CDEF").setKey(PROJECT_KEY + ":src/test/java/dir").setPath("src/test/java/dir").addChildren(builder(FILE, 3).setUuid("DEFG").setKey(PROJECT_KEY + ":src/test/java/dir/FooTest.java").setPath("src/test/java/dir/FooTest.java").setFileAttributes(new FileAttributes(true, null, 1)).build()).build()).build());
underTest.execute();
ComponentDto file = dbClient.componentDao().selectByKey(dbTester.getSession(), PROJECT_KEY + ":src/test/java/dir/FooTest.java").get();
assertThat(file.name()).isEqualTo("FooTest.java");
assertThat(file.path()).isEqualTo("src/test/java/dir/FooTest.java");
assertThat(file.qualifier()).isEqualTo("UTS");
assertThat(file.scope()).isEqualTo("FIL");
}
Aggregations