use of org.sonar.api.ce.measure.MeasureComputer in project sonarqube by SonarSource.
the class LoadMeasureComputersStepTest method fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric.
@Test
public void fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Metric 'metric1' cannot be used as an output metric as no plugin declare this metric");
MeasureComputer[] computers = new MeasureComputer[] { newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1)) };
ComputationStep underTest = new LoadMeasureComputersStep(holder, computers);
underTest.execute();
}
use of org.sonar.api.ce.measure.MeasureComputer in project sonarqube by SonarSource.
the class LoadMeasureComputersStepTest method support_core_metrics_as_input_metrics.
@Test
public void support_core_metrics_as_input_metrics() {
MeasureComputer[] computers = new MeasureComputer[] { newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1)) };
ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
underTest.execute(new TestComputationStepContext());
assertThat(holder.getMeasureComputers()).hasSize(1);
}
use of org.sonar.api.ce.measure.MeasureComputer in project sonarqube by SonarSource.
the class ReportMeasureComputersVisitorTest method compute_plugin_measure.
@Test
public void compute_plugin_measure() {
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(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.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, ROOT_REF, NEW_METRIC_KEY);
}
use of org.sonar.api.ce.measure.MeasureComputer 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));
}
use of org.sonar.api.ce.measure.MeasureComputer in project sonarqube by SonarSource.
the class LoadMeasureComputersStepTest method fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric.
@Test
public void fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric() {
assertThatThrownBy(() -> {
MeasureComputer[] computers = new MeasureComputer[] { newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1)) };
ComputationStep underTest = new LoadMeasureComputersStep(holder, computers);
underTest.execute(new TestComputationStepContext());
}).isInstanceOf(IllegalStateException.class).hasMessage("Metric 'metric1' cannot be used as an output metric because no plugins declare this metric");
}
Aggregations