Search in sources :

Example 1 with MeasureComputerWrapper

use of org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper in project sonarqube by SonarSource.

the class MeasureComputersVisitor method visitAny.

@Override
public void visitAny(org.sonar.ce.task.projectanalysis.component.Component component) {
    MeasureComputerContextImpl context = new MeasureComputerContextImpl(component, settings, measureRepository, metricRepository, componentIssuesRepository);
    for (MeasureComputerWrapper measureComputerWrapper : measureComputersHolder.getMeasureComputers()) {
        context.setDefinition(measureComputerWrapper.getDefinition());
        MeasureComputer measureComputer = measureComputerWrapper.getComputer();
        LOGGER.trace("Measure computer '{}' is computing component {}", measureComputer, component);
        measureComputer.compute(context);
    }
}
Also used : MeasureComputerWrapper(org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputerContextImpl(org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerContextImpl) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer)

Example 2 with MeasureComputerWrapper

use of org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method sort_computers_when_one_computer_has_no_input_metric.

@Test
public void sort_computers_when_one_computer_has_no_input_metric() {
    // Should be the last to be executed
    MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
    // Should be the first to be executed
    MeasureComputer measureComputer2 = newMeasureComputer(new String[] {}, array(NEW_METRIC_2));
    // Should be the second to be executed
    MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
    MeasureComputer[] computers = new MeasureComputer[] { measureComputer1, measureComputer2, measureComputer3 };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
    underTest.execute(new TestComputationStepContext());
    List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
    assertThat(result).hasSize(3);
    assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
    assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
    assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
}
Also used : MeasureComputerWrapper(org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 3 with MeasureComputerWrapper

use of org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper in project sonarqube by SonarSource.

the class LoadMeasureComputersStepTest method sort_computers.

@Test
public void sort_computers() {
    // Should be the last to be executed
    MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
    // Should be the first to be executed
    MeasureComputer measureComputer2 = newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2));
    // Should be the second to be executed
    MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
    MeasureComputer[] computers = new MeasureComputer[] { measureComputer1, measureComputer2, measureComputer3 };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
    underTest.execute(new TestComputationStepContext());
    List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
    assertThat(result).hasSize(3);
    assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
    assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
    assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
}
Also used : MeasureComputerWrapper(org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 4 with MeasureComputerWrapper

use of org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper in project sonarqube by SonarSource.

the class MeasureComputersHolderImplTest method set_measure_computers_throws_ISE_if_already_initialized.

@Test
public void set_measure_computers_throws_ISE_if_already_initialized() {
    assertThatThrownBy(() -> {
        MeasureComputerWrapper measureComputer = mock(MeasureComputerWrapper.class);
        underTest.setMeasureComputers(Collections.singletonList(measureComputer));
        underTest.setMeasureComputers(Collections.singletonList(measureComputer));
    }).isInstanceOf(IllegalStateException.class).hasMessage("Measure computers have already been initialized");
}
Also used : MeasureComputerWrapper(org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) Test(org.junit.Test)

Example 5 with MeasureComputerWrapper

use of org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper in project sonarqube by SonarSource.

the class MeasureComputersHolderImplTest method get_measure_computers.

@Test
public void get_measure_computers() {
    MeasureComputerWrapper measureComputer = mock(MeasureComputerWrapper.class);
    underTest.setMeasureComputers(Collections.singletonList(measureComputer));
    assertThat(underTest.getMeasureComputers()).containsOnly(measureComputer);
}
Also used : MeasureComputerWrapper(org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) Test(org.junit.Test)

Aggregations

MeasureComputerWrapper (org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper)8 Test (org.junit.Test)5 MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)5 ComputationStep (org.sonar.ce.task.step.ComputationStep)2 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)2 HashMap (java.util.HashMap)1 DirectAcyclicGraph (org.sonar.api.utils.dag.DirectAcyclicGraph)1 MeasureComputerContextImpl (org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerContextImpl)1 MeasureComputerDefinitionImpl (org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerDefinitionImpl)1 VisitorsCrawler (org.sonar.ce.task.projectanalysis.component.VisitorsCrawler)1