diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-11-11 15:54:18 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-11-11 15:54:18 +0100 |
commit | 15e9f443eed5c74be9abe4738b07d62fe335c8e6 (patch) | |
tree | f8a3f00e91c202b615cd391ddc84470db8ca09c0 /sonar-scanner-engine | |
parent | 129d630f52bd531f070969d806166f8c70593751 (diff) | |
download | sonarqube-15e9f443eed5c74be9abe4738b07d62fe335c8e6.tar.gz sonarqube-15e9f443eed5c74be9abe4738b07d62fe335c8e6.zip |
Fix Quality flaws about complexity
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java index b3e43598e91..851df664962 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java @@ -198,36 +198,37 @@ public class DefaultIndex { public Measure addMeasure(Resource resource, Measure measure) { Bucket bucket = getBucket(resource); - if (bucket != null) { - if (sensorStorage.isDeprecatedMetric(measure.getMetricKey())) { - // Ignore deprecated metrics - return measure; - } - org.sonar.api.batch.measure.Metric<?> metric = metricFinder.findByKey(measure.getMetricKey()); - if (metric == null) { - throw new UnsupportedOperationException("Unknown metric: " + measure.getMetricKey()); - } - DefaultMeasure<?> newMeasure; - if (Boolean.class.equals(metric.valueType())) { - newMeasure = new DefaultMeasure<Boolean>().forMetric((Metric<Boolean>) metric) - .withValue(measure.getValue() != 0.0); - } else if (Integer.class.equals(metric.valueType())) { - newMeasure = new DefaultMeasure<Integer>().forMetric((Metric<Integer>) metric) - .withValue(measure.getValue().intValue()); - } else if (Double.class.equals(metric.valueType())) { - newMeasure = new DefaultMeasure<Double>().forMetric((Metric<Double>) metric) - .withValue(measure.getValue()); - } else if (String.class.equals(metric.valueType())) { - newMeasure = new DefaultMeasure<String>().forMetric((Metric<String>) metric) - .withValue(measure.getData()); - } else if (Long.class.equals(metric.valueType())) { - newMeasure = new DefaultMeasure<Long>().forMetric((Metric<Long>) metric) - .withValue(measure.getValue().longValue()); - } else { - throw new UnsupportedOperationException("Unsupported type :" + metric.valueType()); - } - sensorStorage.saveMeasure(componentCache.get(resource).inputComponent(), newMeasure); + if (bucket == null) { + return measure; + } + if (sensorStorage.isDeprecatedMetric(measure.getMetricKey())) { + // Ignore deprecated metrics + return measure; + } + org.sonar.api.batch.measure.Metric<?> metric = metricFinder.findByKey(measure.getMetricKey()); + if (metric == null) { + throw new UnsupportedOperationException("Unknown metric: " + measure.getMetricKey()); + } + DefaultMeasure<?> newMeasure; + if (Boolean.class.equals(metric.valueType())) { + newMeasure = new DefaultMeasure<Boolean>().forMetric((Metric<Boolean>) metric) + .withValue(measure.getValue() != 0.0); + } else if (Integer.class.equals(metric.valueType())) { + newMeasure = new DefaultMeasure<Integer>().forMetric((Metric<Integer>) metric) + .withValue(measure.getValue().intValue()); + } else if (Double.class.equals(metric.valueType())) { + newMeasure = new DefaultMeasure<Double>().forMetric((Metric<Double>) metric) + .withValue(measure.getValue()); + } else if (String.class.equals(metric.valueType())) { + newMeasure = new DefaultMeasure<String>().forMetric((Metric<String>) metric) + .withValue(measure.getData()); + } else if (Long.class.equals(metric.valueType())) { + newMeasure = new DefaultMeasure<Long>().forMetric((Metric<Long>) metric) + .withValue(measure.getValue().longValue()); + } else { + throw new UnsupportedOperationException("Unsupported type :" + metric.valueType()); } + sensorStorage.saveMeasure(componentCache.get(resource).inputComponent(), newMeasure); return measure; } |