use of org.sonar.api.batch.measure.Metric in project sonarqube by SonarSource.
the class DefaultSensorStorage method saveMeasure.
private void saveMeasure(InputComponent component, DefaultMeasure<?> measure) {
if (component.isFile()) {
DefaultInputFile defaultInputFile = (DefaultInputFile) component;
defaultInputFile.setPublished(true);
}
if (component instanceof InputDir || (component instanceof DefaultInputModule && ((DefaultInputModule) component).definition().getParent() != null)) {
logOnce(measure.metric().key(), "Storing measures on folders or modules is deprecated. Provided value of metric '{}' is ignored.", measure.metric().key());
return;
}
if (DEPRECATED_METRICS_KEYS.contains(measure.metric().key())) {
logOnce(measure.metric().key(), "Metric '{}' is deprecated. Provided value is ignored.", measure.metric().key());
return;
}
Metric metric = metricFinder.findByKey(measure.metric().key());
if (metric == null) {
throw new UnsupportedOperationException("Unknown metric: " + measure.metric().key());
}
if (!measure.isFromCore() && NEWLY_CORE_METRICS_KEYS.contains(measure.metric().key())) {
logOnce(measure.metric().key(), "Metric '{}' is an internal metric computed by SonarQube/SonarCloud. Provided value is ignored.", measure.metric().key());
return;
}
if (!scannerMetrics.getMetrics().contains(metric)) {
throw new UnsupportedOperationException("Metric '" + metric.key() + "' should not be computed by a Sensor");
}
if (((DefaultInputComponent) component).hasMeasureFor(metric)) {
throw new UnsupportedOperationException("Can not add the same measure twice on " + component + ": " + measure);
}
((DefaultInputComponent) component).setHasMeasureFor(metric);
if (metric.key().equals(CoreMetrics.EXECUTABLE_LINES_DATA_KEY)) {
if (component.isFile()) {
((DefaultInputFile) component).setExecutableLines(KeyValueFormat.parseIntInt((String) measure.value()).entrySet().stream().filter(e -> e.getValue() > 0).map(Map.Entry::getKey).collect(Collectors.toSet()));
} else {
throw new IllegalArgumentException("Executable lines can only be saved on files");
}
}
reportPublisher.getWriter().appendComponentMeasure(((DefaultInputComponent) component).scannerId(), toReportMeasure(measure));
}
Aggregations