use of org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler in project sonarqube by SonarSource.
the class ExecuteVisitorsStep method execute.
@Override
public void execute() {
VisitorsCrawler visitorsCrawler = new VisitorsCrawler(visitors, LOGGER.isDebugEnabled());
visitorsCrawler.visit(treeRootHolder.getRoot());
logVisitorExecutionDurations(visitors, visitorsCrawler);
}
use of org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler in project sonarqube by SonarSource.
the class LastCommitVisitorTest method compute_date_of_file_from_scm_repo.
@Test
public void compute_date_of_file_from_scm_repo() throws Exception {
VisitorsCrawler underTest = new VisitorsCrawler(Lists.<ComponentVisitor>newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
scmInfoRepository.setScmInfo(FILE_1_REF, Changeset.newChangesetBuilder().setAuthor("john").setDate(1_500_000_000_000L).setRevision("rev-1").build(), Changeset.newChangesetBuilder().setAuthor("tom").setDate(1_600_000_000_000L).setRevision("rev-2").build(), Changeset.newChangesetBuilder().setAuthor("john").setDate(1_500_000_000_000L).setRevision("rev-1").build());
ReportComponent file = createFileComponent(FILE_1_REF);
treeRootHolder.setRoot(file);
underTest.visit(file);
assertDate(FILE_1_REF, 1_600_000_000_000L);
}
use of org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler in project sonarqube by SonarSource.
the class LastCommitVisitorTest method aggregate_date_of_last_commit_to_views.
@Test
public void aggregate_date_of_last_commit_to_views() {
final int VIEW_REF = 1;
final int SUBVIEW_1_REF = 2;
final int SUBVIEW_2_REF = 3;
final int SUBVIEW_3_REF = 4;
final int PROJECT_1_REF = 5;
final int PROJECT_2_REF = 6;
final int PROJECT_3_REF = 7;
final long PROJECT_1_DATE = 1_500_000_000_000L;
// the second project has the most recent commit date
final long PROJECT_2_DATE = 1_700_000_000_000L;
final long PROJECT_3_DATE = 1_600_000_000_000L;
// view with 3 nested sub-views and 3 projects
ViewsComponent view = ViewsComponent.builder(VIEW, VIEW_REF).addChildren(builder(SUBVIEW, SUBVIEW_1_REF).addChildren(builder(SUBVIEW, SUBVIEW_2_REF).addChildren(builder(PROJECT_VIEW, PROJECT_1_REF).build(), builder(PROJECT_VIEW, PROJECT_2_REF).build()).build(), builder(SUBVIEW, SUBVIEW_3_REF).addChildren(builder(PROJECT_VIEW, PROJECT_3_REF).build()).build()).build()).build();
treeRootHolder.setRoot(view);
measureRepository.addRawMeasure(PROJECT_1_REF, LAST_COMMIT_DATE_KEY, newMeasureBuilder().create(PROJECT_1_DATE));
measureRepository.addRawMeasure(PROJECT_2_REF, LAST_COMMIT_DATE_KEY, newMeasureBuilder().create(PROJECT_2_DATE));
measureRepository.addRawMeasure(PROJECT_3_REF, LAST_COMMIT_DATE_KEY, newMeasureBuilder().create(PROJECT_3_DATE));
VisitorsCrawler underTest = new VisitorsCrawler(Lists.<ComponentVisitor>newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
underTest.visit(view);
// second level of sub-views
assertDate(SUBVIEW_2_REF, PROJECT_2_DATE);
assertDate(SUBVIEW_3_REF, PROJECT_3_DATE);
// first level of sub-views
assertDate(SUBVIEW_1_REF, PROJECT_2_DATE);
// view
assertDate(VIEW_REF, PROJECT_2_DATE);
}
use of org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler in project sonarqube by SonarSource.
the class LastCommitVisitorTest method date_is_not_computed_on_file_if_blame_is_not_in_scm_repo.
@Test
public void date_is_not_computed_on_file_if_blame_is_not_in_scm_repo() throws Exception {
VisitorsCrawler underTest = new VisitorsCrawler(Lists.<ComponentVisitor>newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
ReportComponent file = createFileComponent(FILE_1_REF);
treeRootHolder.setRoot(file);
underTest.visit(file);
Optional<Measure> measure = measureRepository.getAddedRawMeasure(FILE_1_REF, LAST_COMMIT_DATE_KEY);
assertThat(measure.isPresent()).isFalse();
}
use of org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler in project sonarqube by SonarSource.
the class LastCommitVisitorTest method aggregate_date_of_last_commit_to_directories_and_project.
@Test
public void aggregate_date_of_last_commit_to_directories_and_project() {
final long FILE_1_DATE = 1_100_000_000_000L;
// FILE_2 is the most recent file in DIR_1
final long FILE_2_DATE = 1_200_000_000_000L;
// FILE_3 is the most recent file in the project
final long FILE_3_DATE = 1_300_000_000_000L;
// simulate the output of visitFile()
LastCommitVisitor visitor = new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository) {
@Override
public void visitFile(Component file, Path<LastCommit> path) {
long fileDate;
switch(file.getReportAttributes().getRef()) {
case FILE_1_REF:
fileDate = FILE_1_DATE;
break;
case FILE_2_REF:
fileDate = FILE_2_DATE;
break;
case FILE_3_REF:
fileDate = FILE_3_DATE;
break;
default:
throw new IllegalArgumentException();
}
path.parent().addDate(fileDate);
}
};
// project with 1 module, 2 directories and 3 files
ReportComponent project = ReportComponent.builder(PROJECT, PROJECT_REF).addChildren(ReportComponent.builder(MODULE, MODULE_REF).addChildren(ReportComponent.builder(DIRECTORY, DIR_1_REF).addChildren(createFileComponent(FILE_1_REF), createFileComponent(FILE_2_REF)).build(), ReportComponent.builder(DIRECTORY, DIR_2_REF).addChildren(createFileComponent(FILE_3_REF)).build()).build()).build();
treeRootHolder.setRoot(project);
VisitorsCrawler underTest = new VisitorsCrawler(Lists.<ComponentVisitor>newArrayList(visitor));
underTest.visit(project);
assertDate(DIR_1_REF, FILE_2_DATE);
assertDate(DIR_2_REF, FILE_3_DATE);
// module = most recent commit date of directories
assertDate(MODULE_REF, FILE_3_DATE);
// project
assertDate(PROJECT_REF, FILE_3_DATE);
}
Aggregations