Search in sources :

Example 1 with VisitorsCrawler

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

the class ViewsMeasureComputersVisitorTest method compute_plugin_measure.

@Test
public void compute_plugin_measure() {
    treeRootHolder.setRoot(TREE_WITH_SUB_VIEWS);
    addRawMeasure(PROJECT_VIEW_1_REF, NCLOC_KEY, 10);
    addRawMeasure(PROJECT_VIEW_1_REF, COMMENT_LINES_KEY, 2);
    addRawMeasure(PROJECT_VIEW_2_REF, NCLOC_KEY, 40);
    addRawMeasure(PROJECT_VIEW_2_REF, COMMENT_LINES_KEY, 5);
    addRawMeasure(SUB_SUBVIEW_REF, NCLOC_KEY, 50);
    addRawMeasure(SUB_SUBVIEW_REF, COMMENT_LINES_KEY, 7);
    addRawMeasure(VIEW_REF, NCLOC_KEY, 50);
    addRawMeasure(VIEW_REF, COMMENT_LINES_KEY, 7);
    addRawMeasure(ROOT_REF, NCLOC_KEY, 50);
    addRawMeasure(ROOT_REF, COMMENT_LINES_KEY, 7);
    measureComputersHolder.addMeasureComputer(MEASURE_COMPUTER);
    VisitorsCrawler visitorsCrawler = new VisitorsCrawler(Arrays.asList(new MeasureComputersVisitor(metricRepository, measureRepository, null, measureComputersHolder, componentIssuesRepository)));
    visitorsCrawler.visit(treeRootHolder.getRoot());
    assertNoAddedRawMeasureOnProjectViews();
    assertAddedRawMeasure(57, SUB_SUBVIEW_REF, NEW_METRIC_KEY);
    assertAddedRawMeasure(57, VIEW_REF, NEW_METRIC_KEY);
    assertAddedRawMeasure(57, ROOT_REF, NEW_METRIC_KEY);
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) Test(org.junit.Test)

Example 2 with VisitorsCrawler

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

the class ViewsMeasureComputersVisitorTest method nothing_to_compute_when_no_project_view.

@Test
public void nothing_to_compute_when_no_project_view() {
    treeRootHolder.setRoot(builder(VIEW, ROOT_REF).addChildren(builder(SUBVIEW, VIEW_REF).addChildren(builder(SUBVIEW, SUB_SUBVIEW_REF).build()).build()).build());
    measureComputersHolder.addMeasureComputer(MEASURE_COMPUTER);
    VisitorsCrawler visitorsCrawler = new VisitorsCrawler(Arrays.asList(new MeasureComputersVisitor(metricRepository, measureRepository, null, measureComputersHolder, componentIssuesRepository)));
    visitorsCrawler.visit(treeRootHolder.getRoot());
    assertNoAddedRawMeasureOnProjectViews();
    assertNoAddedRawMeasure(SUB_SUBVIEW_REF);
    assertNoAddedRawMeasure(VIEW_REF);
    assertNoAddedRawMeasure(ROOT_REF);
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) Test(org.junit.Test)

Example 3 with VisitorsCrawler

use of org.sonar.ce.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(DIRECTORY, DIR_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.newArrayList(visitor));
    underTest.visit(project);
    assertDate(DIR_1_REF, FILE_2_DATE);
    assertDate(DIR_2_REF, FILE_3_DATE);
    assertDate(DIR_REF, FILE_3_DATE);
    // project
    assertDate(PROJECT_REF, FILE_3_DATE);
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 4 with VisitorsCrawler

use of org.sonar.ce.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.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);
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Test(org.junit.Test)

Example 5 with VisitorsCrawler

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

the class MaintainabilityMeasuresVisitorTest method setUp.

@Before
public void setUp() {
    // assumes rating configuration is consistent
    when(ratingSettings.getDebtRatingGrid()).thenReturn(new DebtRatingGrid(RATING_GRID));
    when(ratingSettings.getDevCost(LANGUAGE_KEY_1)).thenReturn(DEV_COST_LANGUAGE_1);
    when(ratingSettings.getDevCost(LANGUAGE_KEY_2)).thenReturn(DEV_COST_LANGUAGE_2);
    underTest = new VisitorsCrawler(singletonList(new MaintainabilityMeasuresVisitor(metricRepository, measureRepository, ratingSettings)));
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) DebtRatingGrid(org.sonar.server.measure.DebtRatingGrid) Before(org.junit.Before)

Aggregations

VisitorsCrawler (org.sonar.ce.task.projectanalysis.component.VisitorsCrawler)14 Test (org.junit.Test)10 Before (org.junit.Before)3 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)3 ViewsComponent (org.sonar.ce.task.projectanalysis.component.ViewsComponent)2 DebtRatingGrid (org.sonar.server.measure.DebtRatingGrid)2 MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)1 MeasureComputerDefinitionImpl (org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerDefinitionImpl)1 MeasureComputerWrapper (org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper)1 Component (org.sonar.ce.task.projectanalysis.component.Component)1 Measure (org.sonar.ce.task.projectanalysis.measure.Measure)1