use of org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper in project sonarqube by SonarSource.
the class LoadMeasureComputersStepTest method sort_computers.
@Test
public void sort_computers() throws Exception {
// 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();
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);
}
use of org.sonar.server.computation.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() throws Exception {
// 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();
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);
}
use of org.sonar.server.computation.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper in project sonarqube by SonarSource.
the class LoadMeasureComputersStep method sortComputers.
private static Iterable<MeasureComputerWrapper> sortComputers(List<MeasureComputerWrapper> wrappers) {
Map<String, MeasureComputerWrapper> computersByOutputMetric = new HashMap<>();
Map<String, MeasureComputerWrapper> computersByInputMetric = new HashMap<>();
feedComputersByMetric(wrappers, computersByOutputMetric, computersByInputMetric);
ToComputerByKey toComputerByOutputMetricKey = new ToComputerByKey(computersByOutputMetric);
ToComputerByKey toComputerByInputMetricKey = new ToComputerByKey(computersByInputMetric);
DirectAcyclicGraph dag = new DirectAcyclicGraph();
for (MeasureComputerWrapper computer : wrappers) {
dag.add(computer);
for (MeasureComputerWrapper dependency : getDependencies(computer, toComputerByOutputMetricKey)) {
dag.add(computer, dependency);
}
for (MeasureComputerWrapper generates : getDependents(computer, toComputerByInputMetricKey)) {
dag.add(generates, computer);
}
}
return dag.sort();
}
Aggregations