use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class RemoveProcessedComponentsVisitorTest method also_remove_moved_files.
@Test
public void also_remove_moved_files() {
String uuid2 = "uuid2";
OriginalFile movedFile = new OriginalFile(uuid2, "key");
when(movedFilesRepository.getOriginalFile(any(Component.class))).thenReturn(Optional.of(movedFile));
underTest.afterComponent(component);
verify(movedFilesRepository).getOriginalFile(component);
verify(componentsWithUnprocessedIssues).remove(UUID);
verify(componentsWithUnprocessedIssues).remove(uuid2);
verifyNoMoreInteractions(componentsWithUnprocessedIssues);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ComponentIssuesRepositoryRule method getIssues.
public List<DefaultIssue> getIssues(int componentRef) {
checkState(this.component != null && this.issues != null, "Issues have not been initialized");
Component component = treeRootHolder.getComponentByRef(componentRef);
checkArgument(component != null, String.format("Component '%s' does not exists in the report ", componentRef));
checkArgument(component == this.component, String.format("Only issues from component '%s' are available, but wanted component is '%s'.", this.component.getReportAttributes().getRef(), component.getReportAttributes().getRef()));
return issues;
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ReportPersistAnalysisStepTest method persist_snapshots_with_new_code_period.
@Test
public void persist_snapshots_with_new_code_period() {
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project");
dbTester.components().insertComponent(projectDto);
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime());
dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto);
dbTester.getSession().commit();
periodsHolder.setPeriod(new Period("NUMBER_OF_DAYS", "10", analysisDate));
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build();
treeRootHolder.setRoot(project);
underTest.execute(new TestComputationStepContext());
SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
assertThat(projectSnapshot.getPeriodMode()).isEqualTo("NUMBER_OF_DAYS");
assertThat(projectSnapshot.getPeriodDate()).isEqualTo(analysisDate);
assertThat(projectSnapshot.getPeriodModeParameter()).isNotNull();
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ReportPersistAnalysisStepTest method persist_analysis.
@Test
public void persist_analysis() {
String projectVersion = randomAlphabetic(10);
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project");
dbTester.components().insertComponent(projectDto);
ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setDbKey("MODULE_KEY").setName("Module");
dbTester.components().insertComponent(moduleDto);
ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setDbKey("MODULE_KEY:src/main/java/dir");
dbTester.components().insertComponent(directoryDto);
ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setDbKey("MODULE_KEY:src/main/java/dir/Foo.java");
dbTester.components().insertComponent(fileDto);
dbTester.getSession().commit();
Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
String buildString = Optional.ofNullable(projectVersion).map(v -> randomAlphabetic(7)).orElse(null);
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setProjectVersion(projectVersion).setBuildString(buildString).setScmRevisionId(REVISION_ID).addChildren(directory).build();
treeRootHolder.setRoot(project);
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("snapshots")).isOne();
SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid());
assertThat(projectSnapshot.getProjectVersion()).isEqualTo(projectVersion);
assertThat(projectSnapshot.getBuildString()).isEqualTo(buildString);
assertThat(projectSnapshot.getLast()).isFalse();
assertThat(projectSnapshot.getStatus()).isEqualTo("U");
assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate);
assertThat(projectSnapshot.getBuildDate()).isEqualTo(now);
assertThat(projectSnapshot.getRevision()).isEqualTo(REVISION_ID);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ReportPersistAnalysisStepTest method only_persist_snapshots_with_new_code_period_on_project_and_module.
@Test
public void only_persist_snapshots_with_new_code_period_on_project_and_module() {
periodsHolder.setPeriod(new Period("PREVIOUS_VERSION", null, analysisDate));
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project");
dbTester.components().insertComponent(projectDto);
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto);
dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot);
ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setDbKey("MODULE_KEY").setName("Module");
dbTester.components().insertComponent(moduleDto);
ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setDbKey("MODULE_KEY:src/main/java/dir");
dbTester.components().insertComponent(directoryDto);
ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setDbKey("MODULE_KEY:src/main/java/dir/Foo.java");
dbTester.components().insertComponent(fileDto);
dbTester.getSession().commit();
Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(directory).build();
treeRootHolder.setRoot(project);
underTest.execute(new TestComputationStepContext());
SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
assertThat(newProjectSnapshot.getPeriodMode()).isEqualTo("PREVIOUS_VERSION");
}
Aggregations