aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-10-18 14:46:06 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2016-10-18 16:00:26 +0200
commit84fcbdd5a897a26faf0177e57f30c8f611fdd732 (patch)
tree65ce916439369b0760645b3711edfe933d32653f /sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor
parentbea3be1e67ee4ae99359356480cd460fccd058f5 (diff)
downloadsonarqube-84fcbdd5a897a26faf0177e57f30c8f611fdd732.tar.gz
sonarqube-84fcbdd5a897a26faf0177e57f30c8f611fdd732.zip
SONAR-7875 Log a warning when a metric should not be saved by a Sensor
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java42
1 files changed, 25 insertions, 17 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java
index dab6d71dcbc..7efd4e8ce5e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java
@@ -97,7 +97,7 @@ import static org.sonar.api.measures.CoreMetrics.IT_LINES_TO_COVER;
import static org.sonar.api.measures.CoreMetrics.IT_LINE_COVERAGE;
import static org.sonar.api.measures.CoreMetrics.IT_UNCOVERED_CONDITIONS;
import static org.sonar.api.measures.CoreMetrics.IT_UNCOVERED_LINES;
-import static org.sonar.api.measures.CoreMetrics.LINES;
+import static org.sonar.api.measures.CoreMetrics.LINES_KEY;
import static org.sonar.api.measures.CoreMetrics.LINES_TO_COVER;
import static org.sonar.api.measures.CoreMetrics.LINE_COVERAGE;
import static org.sonar.api.measures.CoreMetrics.OVERALL_BRANCH_COVERAGE;
@@ -119,10 +119,6 @@ public class DefaultSensorStorage implements SensorStorage {
private static final Logger LOG = LoggerFactory.getLogger(DefaultSensorStorage.class);
- private static final List<Metric<?>> INTERNAL_METRICS = Arrays.<Metric<?>>asList(
- // Computed by LinesSensor
- LINES);
-
private static final List<String> DEPRECATED_METRICS_KEYS = Arrays.asList(
DEPENDENCY_MATRIX_KEY,
DIRECTORY_CYCLES_KEY,
@@ -139,7 +135,10 @@ public class DefaultSensorStorage implements SensorStorage {
COMMENTED_OUT_CODE_LINES_KEY);
// Some Sensors still save those metrics
- private static final List<String> COMPUTED_ON_CE_SIDE_METRICS_KEYS = Arrays.asList(
+ private static final List<String> PLATFORM_METRICS_KEYS = Arrays.asList(
+ // Computed on Scanner side
+ LINES_KEY,
+ // Computed on CE side
TEST_SUCCESS_DENSITY_KEY,
PUBLIC_DOCUMENTED_API_DENSITY_KEY);
@@ -156,6 +155,7 @@ public class DefaultSensorStorage implements SensorStorage {
private final Map<Metric<?>, Metric<?>> deprecatedCoverageMetricMapping = new IdentityHashMap<>();
private final Set<Metric<?>> coverageMetrics = new HashSet<>();
private final Set<Metric<?>> byLineMetrics = new HashSet<>();
+ private Set<String> alreadyLogged = new HashSet<>();
public DefaultSensorStorage(MetricFinder metricFinder, ModuleIssues moduleIssues,
Settings settings,
@@ -212,30 +212,38 @@ public class DefaultSensorStorage implements SensorStorage {
saveMeasure(newMeasure.inputComponent(), (DefaultMeasure<?>) newMeasure);
}
+ private void logOnce(String metricKey, String msg, Object... params) {
+ if (!alreadyLogged.contains(metricKey)) {
+ LOG.warn(msg, params);
+ alreadyLogged.add(metricKey);
+ }
+ }
+
public void saveMeasure(InputComponent component, DefaultMeasure<?> measure) {
- if (isDeprecatedMetric(measure.metric().key()) || isComputedOnCeMetric(measure.metric().key())) {
- LOG.debug("Metric '{}' should not be saved by Sensors. It will be ignored.", measure.metric().key());
- // Ignore deprecated and CE side metrics
+ if (isDeprecatedMetric(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 (!scannerMetrics.getMetrics().contains(metric)) {
- throw new UnsupportedOperationException("Metric '" + metric.key() + "' should not be computed by a Sensor");
- }
- if (!measure.isFromCore() && INTERNAL_METRICS.contains(metric)) {
- LOG.debug("Metric " + metric.key() + " is an internal metric computed by SonarQube. Provided value is ignored.");
+ if (!measure.isFromCore() && isPlatformMetric(measure.metric().key())) {
+ logOnce(measure.metric().key(), "Metric '{}' is an internal metric computed by SonarQube. Provided value is ignored.", measure.metric().key());
return;
}
if (deprecatedCoverageMetricMapping.containsKey(metric)) {
metric = deprecatedCoverageMetricMapping.get(metric);
}
+ if (!scannerMetrics.getMetrics().contains(metric)) {
+ throw new UnsupportedOperationException("Metric '" + metric.key() + "' should not be computed by a Sensor");
+ }
if (coverageMetrics.contains(metric)) {
+ logOnce(metric.key(), "Coverage measure for metric '{}' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.",
+ metric.key());
if (!component.isFile()) {
- throw new UnsupportedOperationException("Saving coverage metric is only allowed on files. Attempt to save '" + metric.key() + "' on '" + component.key() + "'");
+ throw new UnsupportedOperationException("Saving coverage measure is only allowed on files. Attempt to save '" + metric.key() + "' on '" + component.key() + "'");
}
if (coverageExclusions.isExcluded((InputFile) component)) {
return;
@@ -298,8 +306,8 @@ public class DefaultSensorStorage implements SensorStorage {
return DEPRECATED_METRICS_KEYS.contains(metricKey);
}
- public boolean isComputedOnCeMetric(String metricKey) {
- return COMPUTED_ON_CE_SIDE_METRICS_KEYS.contains(metricKey);
+ public boolean isPlatformMetric(String metricKey) {
+ return PLATFORM_METRICS_KEYS.contains(metricKey);
}
private boolean isLineMetrics(Metric<?> metric) {