aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-11-28 12:10:44 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:03 +0100
commit7be847605deb32e28afadd8dd53397ff4b5842c8 (patch)
tree0d94fa9c1e6dbdff4903aad40c80d81ee39653a3 /plugins
parente05aea1ebbba8d94c78afdbfac7230563d6df01f (diff)
downloadsonarqube-7be847605deb32e28afadd8dd53397ff4b5842c8.tar.gz
sonarqube-7be847605deb32e28afadd8dd53397ff4b5842c8.zip
SONAR-11509 Ignore module and folder level measures in Sensor API
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java6
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java23
2 files changed, 28 insertions, 1 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 18d801397c4..0a839a7692d 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
@@ -26,6 +26,7 @@ import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.InputComponent;
+import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.batch.sensor.Sensor;
@@ -119,6 +120,11 @@ public class MeasureSensor implements Sensor {
File ioFile = file.file();
File measureFile = new File(ioFile.getParentFile(), ioFile.getName() + MEASURES_EXTENSION);
processFileMeasures(file, measureFile, context);
+
+ InputDir inputDir = context.fileSystem().inputDir(ioFile.getParentFile());
+ if (inputDir != null) {
+ processFileMeasures(inputDir, new File(ioFile.getParentFile(), "folder" + MEASURES_EXTENSION), context);
+ }
}
processFileMeasures(context.module(), new File(context.fileSystem().baseDir(), "module" + MEASURES_EXTENSION), context);
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
index 4415a058c23..7ed38d42e0e 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
@@ -21,6 +21,7 @@ package org.sonar.xoo.lang;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
@@ -76,7 +77,7 @@ public class MeasureSensorTest {
@Test
public void testExecution() throws IOException {
File measures = new File(baseDir, "src/foo.xoo.measures");
- FileUtils.write(measures, "ncloc:12\nbranch_coverage:5.3\nsqale_index:300\nbool:true\n\n#comment");
+ FileUtils.write(measures, "ncloc:12\nbranch_coverage:5.3\nsqale_index:300\nbool:true\n\n#comment", StandardCharsets.UTF_8);
InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
context.fileSystem().add(inputFile);
@@ -97,6 +98,26 @@ public class MeasureSensorTest {
}
@Test
+ public void testExecutionForFoldersMeasures_no_measures() throws IOException {
+ File measures = new File(baseDir, "src/folder.measures");
+ FileUtils.write(measures, "ncloc:12\nbranch_coverage:5.3\nsqale_index:300\nbool:true\n\n#comment", StandardCharsets.UTF_8);
+ InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
+ context.fileSystem().add(inputFile);
+
+ Metric<Boolean> booleanMetric = new Metric.Builder("bool", "Bool", Metric.ValueType.BOOL)
+ .create();
+
+ when(metricFinder.<Integer>findByKey("ncloc")).thenReturn(CoreMetrics.NCLOC);
+ when(metricFinder.<Double>findByKey("branch_coverage")).thenReturn(CoreMetrics.BRANCH_COVERAGE);
+ when(metricFinder.<Long>findByKey("sqale_index")).thenReturn(CoreMetrics.TECHNICAL_DEBT);
+ when(metricFinder.<Boolean>findByKey("bool")).thenReturn(booleanMetric);
+
+ sensor.execute(context);
+
+ assertThat(context.measure("foo:src", CoreMetrics.NCLOC)).isNull();
+ }
+
+ @Test
public void failIfMetricNotFound() throws IOException {
File measures = new File(baseDir, "src/foo.xoo.measures");
FileUtils.write(measures, "unknow:12\n\n#comment");