diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-10-22 10:57:55 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-10-22 13:08:06 +0200 |
commit | 0dc21da0c4d4f29e91637bc778b2cbf16b657d80 (patch) | |
tree | ecdc74162bb3ab436699785f92c98980f4139f59 /plugins | |
parent | eff6a172cbef2cfecbcd6e40f99106370a365848 (diff) | |
download | sonarqube-0dc21da0c4d4f29e91637bc778b2cbf16b657d80.tar.gz sonarqube-0dc21da0c4d4f29e91637bc778b2cbf16b657d80.zip |
Add a medium test for float measures precision on batch side
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/ConstantFloatMeasureSensor.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/ConstantFloatMeasureSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/ConstantFloatMeasureSensor.java index 85e139f86e1..416efe2bc39 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/ConstantFloatMeasureSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/ConstantFloatMeasureSensor.java @@ -24,6 +24,7 @@ import org.sonar.api.batch.Sensor; import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.config.Settings; import org.sonar.api.measures.Measure; import org.sonar.api.resources.Project; import org.sonar.xoo.Xoo; @@ -33,22 +34,30 @@ import org.sonar.xoo.Xoo; */ public class ConstantFloatMeasureSensor implements Sensor { - private static final double CONSTANT_VALUE = 1.2345678910111213d; + public static final String SONAR_XOO_ENABLE_FLOAT_SENSOR = "sonar.xoo.enableFloatSensor"; + public static final String SONAR_XOO_FLOAT_PRECISION = "sonar.xoo.floatPrecision"; + + public static final double CONSTANT_VALUE = 1.2345678910111213d; private final FileSystem fs; + private final Settings settings; - public ConstantFloatMeasureSensor(FileSystem fs) { + public ConstantFloatMeasureSensor(FileSystem fs, Settings settings) { this.fs = fs; + this.settings = settings; } @Override public boolean shouldExecuteOnProject(Project project) { - return fs.hasFiles(fs.predicates().hasLanguage(Xoo.KEY)); + return fs.hasFiles(fs.predicates().hasLanguage(Xoo.KEY)) && settings.getBoolean( + SONAR_XOO_ENABLE_FLOAT_SENSOR); } @Override public void analyse(Project project, SensorContext context) { - Measure<?> floatMeasure = new Measure<>(XooMetrics.CONSTANT_FLOAT_MEASURE, CONSTANT_VALUE); + Measure<?> floatMeasure = settings.hasKey(SONAR_XOO_FLOAT_PRECISION) + ? new Measure<>(XooMetrics.CONSTANT_FLOAT_MEASURE, CONSTANT_VALUE, settings.getInt(SONAR_XOO_FLOAT_PRECISION)) + : new Measure<>(XooMetrics.CONSTANT_FLOAT_MEASURE, CONSTANT_VALUE); for (InputFile inputFile : getSourceFiles()) { context.saveMeasure(inputFile, floatMeasure); } |