aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-08-27 10:31:46 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-08-27 10:31:46 +0200
commitb5e8fd0ef143c9309c30854ce6d8a1d19c2b138d (patch)
treebe35b3d2b27d4d7e484c942026fd4e30aab83634 /plugins
parent400386a676630f8ac4e51e568981c652bc11b56f (diff)
downloadsonarqube-b5e8fd0ef143c9309c30854ce6d8a1d19c2b138d.tar.gz
sonarqube-b5e8fd0ef143c9309c30854ce6d8a1d19c2b138d.zip
Fix some quality flaws
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java28
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java4
2 files changed, 19 insertions, 13 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
index 56e013b3716..bc796808f19 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
@@ -60,28 +60,32 @@ public class MeasureSensor implements Sensor {
int lineNumber = 0;
for (String line : lines) {
lineNumber++;
- if (StringUtils.isBlank(line)) {
+ if (StringUtils.isBlank(line) || line.startsWith("#")) {
continue;
}
- if (line.startsWith("#")) {
- continue;
- }
- try {
- String metricKey = StringUtils.substringBefore(line, ":");
- String value = line.substring(metricKey.length() + 1);
- context.addMeasure(createMeasure(context, inputFile, metricKey, value));
- } catch (Exception e) {
- throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
- }
+ processMeasure(inputFile, context, measureFile, lineNumber, line);
}
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new IllegalStateException(e);
}
}
}
+ private void processMeasure(InputFile inputFile, SensorContext context, File measureFile, int lineNumber, String line) {
+ try {
+ String metricKey = StringUtils.substringBefore(line, ":");
+ String value = line.substring(metricKey.length() + 1);
+ context.addMeasure(createMeasure(context, inputFile, metricKey, value));
+ } catch (Exception e) {
+ throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
+ }
+ }
+
private Measure<?> createMeasure(SensorContext context, InputFile xooFile, String metricKey, String value) {
org.sonar.api.batch.measure.Metric<Serializable> metric = metricFinder.findByKey(metricKey);
+ if (metric == null) {
+ throw new IllegalStateException("Unknow metric with key: " + metricKey);
+ }
MeasureBuilder<Serializable> builder = context.measureBuilder()
.forMetric(metric)
.onFile(xooFile);
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
index 0ae23954442..ca2f6b5e0ac 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
@@ -19,6 +19,8 @@
*/
package org.sonar.xoo.lang;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
+
import com.google.common.base.Splitter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
@@ -64,7 +66,7 @@ public class SyntaxHighlightingSensor implements Sensor {
Iterator<String> split = Splitter.on(":").split(line).iterator();
int startOffset = Integer.parseInt(split.next());
int endOffset = Integer.parseInt(split.next());
- HighlightingBuilder.TypeOfText type = HighlightingBuilder.TypeOfText.forCssClass(split.next());
+ TypeOfText type = TypeOfText.forCssClass(split.next());
highlightingBuilder.highlight(startOffset, endOffset, type);
} catch (Exception e) {
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + highlightingFile.getAbsolutePath(), e);