Search in sources :

Example 1 with MeasureComputerWrapper

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

the class MeasureComputersVisitor method visitAny.

@Override
public void visitAny(org.sonar.server.computation.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.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputerContextImpl(org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerContextImpl) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer)

Example 2 with MeasureComputerWrapper

use of org.sonar.server.computation.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() {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Measure computers have already been initialized");
    MeasureComputerWrapper measureComputer = mock(MeasureComputerWrapper.class);
    underTest.setMeasureComputers(Collections.singletonList(measureComputer));
    underTest.setMeasureComputers(Collections.singletonList(measureComputer));
}
Also used : MeasureComputerWrapper(org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) Test(org.junit.Test)

Example 3 with MeasureComputerWrapper

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

the class MeasureComputersHolderImplTest method get_measure_computers.

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

Example 4 with MeasureComputerWrapper

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

the class MeasureComputersHolderRule method addMeasureComputer.

public void addMeasureComputer(MeasureComputer measureComputer) {
    requireNonNull(measureComputer, "Measure computer cannot be null");
    MeasureComputer.MeasureComputerDefinition definition = measureComputer.define(context);
    this.measureComputers.add(new MeasureComputerWrapper(measureComputer, definition));
}
Also used : MeasureComputerWrapper(org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer)

Example 5 with MeasureComputerWrapper

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

the class ReportMeasureComputersVisitorTest method compute_plugin_measure.

@Test
public void compute_plugin_measure() throws Exception {
    addRawMeasure(FILE_1_REF, NCLOC_KEY, 10);
    addRawMeasure(FILE_1_REF, COMMENT_LINES_KEY, 2);
    addRawMeasure(FILE_2_REF, NCLOC_KEY, 40);
    addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, 5);
    addRawMeasure(DIRECTORY_REF, NCLOC_KEY, 50);
    addRawMeasure(DIRECTORY_REF, COMMENT_LINES_KEY, 7);
    addRawMeasure(MODULE_REF, NCLOC_KEY, 50);
    addRawMeasure(MODULE_REF, COMMENT_LINES_KEY, 7);
    addRawMeasure(ROOT_REF, NCLOC_KEY, 50);
    addRawMeasure(ROOT_REF, COMMENT_LINES_KEY, 7);
    final MeasureComputer.MeasureComputerDefinition definition = new MeasureComputerDefinitionImpl.BuilderImpl().setInputMetrics(NCLOC_KEY, COMMENT_LINES_KEY).setOutputMetrics(NEW_METRIC_KEY).build();
    measureComputersHolder.setMeasureComputers(newArrayList(new MeasureComputerWrapper(new MeasureComputer() {

        @Override
        public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
            return definition;
        }

        @Override
        public void compute(MeasureComputerContext context) {
            org.sonar.api.ce.measure.Measure ncloc = context.getMeasure(NCLOC_KEY);
            org.sonar.api.ce.measure.Measure comment = context.getMeasure(COMMENT_LINES_KEY);
            if (ncloc != null && comment != null) {
                context.addMeasure(NEW_METRIC_KEY, ncloc.getIntValue() + comment.getIntValue());
            }
        }
    }, definition)));
    VisitorsCrawler visitorsCrawler = new VisitorsCrawler(Arrays.<ComponentVisitor>asList(new MeasureComputersVisitor(metricRepository, measureRepository, null, measureComputersHolder, componentIssuesRepository)));
    visitorsCrawler.visit(ROOT);
    assertAddedRawMeasure(12, FILE_1_REF, NEW_METRIC_KEY);
    assertAddedRawMeasure(45, FILE_2_REF, NEW_METRIC_KEY);
    assertAddedRawMeasure(57, DIRECTORY_REF, NEW_METRIC_KEY);
    assertAddedRawMeasure(57, MODULE_REF, NEW_METRIC_KEY);
    assertAddedRawMeasure(57, ROOT_REF, NEW_METRIC_KEY);
}
Also used : MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) MeasureComputerWrapper(org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputerDefinitionImpl(org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerDefinitionImpl) VisitorsCrawler(org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler) Test(org.junit.Test)

Aggregations

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