]> source.dussan.org Git - sonarqube.git/commitdiff
Create a Xoo sensor to compute float measure
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 21 Oct 2015 13:29:38 +0000 (15:29 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 22 Oct 2015 10:06:16 +0000 (12:06 +0200)
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/ConstantFloatMeasureSensor.java [new file with mode: 0644]
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/XooMetrics.java [new file with mode: 0644]
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/package-info.java [new file with mode: 0644]

index fe8a123a6da27a7df63b01b12500069622254718..a74dd0c8d5b6e5e53c407f5dfce39ed6a66957dd 100644 (file)
  */
 package org.sonar.xoo;
 
-import org.sonar.xoo.rule.OneBlockerIssuePerFileSensor;
-
-import org.sonar.xoo.rule.HasTagSensor;
-import org.sonar.xoo.rule.OneIssuePerModuleSensor;
-import org.sonar.xoo.rule.OneIssuePerFileSensor;
-import org.sonar.xoo.rule.Xoo2BasicProfile;
+import java.util.Arrays;
+import java.util.List;
 import org.sonar.api.SonarPlugin;
 import org.sonar.xoo.coverage.ItCoverageSensor;
 import org.sonar.xoo.coverage.OverallCoverageSensor;
@@ -36,27 +32,31 @@ import org.sonar.xoo.lang.SymbolReferencesSensor;
 import org.sonar.xoo.lang.SyntaxHighlightingSensor;
 import org.sonar.xoo.lang.XooCpdMapping;
 import org.sonar.xoo.lang.XooTokenizer;
+import org.sonar.xoo.measures.ConstantFloatMeasureSensor;
+import org.sonar.xoo.measures.XooMetrics;
 import org.sonar.xoo.rule.ChecksSensor;
 import org.sonar.xoo.rule.CreateIssueByInternalKeySensor;
 import org.sonar.xoo.rule.DeprecatedResourceApiSensor;
+import org.sonar.xoo.rule.HasTagSensor;
 import org.sonar.xoo.rule.MultilineIssuesSensor;
+import org.sonar.xoo.rule.OneBlockerIssuePerFileSensor;
 import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor;
+import org.sonar.xoo.rule.OneIssuePerFileSensor;
 import org.sonar.xoo.rule.OneIssuePerLineSensor;
+import org.sonar.xoo.rule.OneIssuePerModuleSensor;
 import org.sonar.xoo.rule.RandomAccessSensor;
+import org.sonar.xoo.rule.Xoo2BasicProfile;
+import org.sonar.xoo.rule.XooBasicProfile;
 import org.sonar.xoo.rule.XooEmptyProfile;
 import org.sonar.xoo.rule.XooFakeExporter;
 import org.sonar.xoo.rule.XooFakeImporter;
 import org.sonar.xoo.rule.XooFakeImporterWithMessages;
-import org.sonar.xoo.rule.XooBasicProfile;
 import org.sonar.xoo.rule.XooRulesDefinition;
 import org.sonar.xoo.scm.XooBlameCommand;
 import org.sonar.xoo.scm.XooScmProvider;
 import org.sonar.xoo.test.CoveragePerTestSensor;
 import org.sonar.xoo.test.TestExecutionSensor;
 
-import java.util.Arrays;
-import java.util.List;
-
 /**
  * Plugin entry-point, as declared in pom.xml.
  */
@@ -113,6 +113,10 @@ public class XooPlugin extends SonarPlugin {
       TestExecutionSensor.class,
       CoveragePerTestSensor.class,
 
+      // Measures
+      XooMetrics.class,
+      ConstantFloatMeasureSensor.class,
+
       // Other
       XooProjectBuilder.class,
       XooPostJob.class);
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
new file mode 100644 (file)
index 0000000..85e139f
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.xoo.measures;
+
+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.measures.Measure;
+import org.sonar.api.resources.Project;
+import org.sonar.xoo.Xoo;
+
+/**
+ * Save a constant float measure on each XOO source file
+ */
+public class ConstantFloatMeasureSensor implements Sensor {
+
+  private static final double CONSTANT_VALUE = 1.2345678910111213d;
+
+  private final FileSystem fs;
+
+  public ConstantFloatMeasureSensor(FileSystem fs) {
+    this.fs = fs;
+  }
+
+  @Override
+  public boolean shouldExecuteOnProject(Project project) {
+    return fs.hasFiles(fs.predicates().hasLanguage(Xoo.KEY));
+  }
+
+  @Override
+  public void analyse(Project project, SensorContext context) {
+    Measure<?> floatMeasure = new Measure<>(XooMetrics.CONSTANT_FLOAT_MEASURE, CONSTANT_VALUE);
+    for (InputFile inputFile : getSourceFiles()) {
+      context.saveMeasure(inputFile, floatMeasure);
+    }
+  }
+
+  private Iterable<InputFile> getSourceFiles() {
+    return fs.inputFiles(fs.predicates().and(fs.predicates().hasLanguage(Xoo.KEY), fs.predicates().hasType(InputFile.Type.MAIN)));
+  }
+
+  @Override
+  public String toString() {
+    return getClass().getSimpleName();
+  }
+}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/XooMetrics.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/XooMetrics.java
new file mode 100644 (file)
index 0000000..511baf2
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.xoo.measures;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.Metrics;
+
+public final class XooMetrics implements Metrics {
+
+  public static final String CONSTANT_FLOAT_MEASURE_KEY = "xoo_constant_float_measure";
+
+  public static final Metric<Float> CONSTANT_FLOAT_MEASURE = new Metric.Builder(CONSTANT_FLOAT_MEASURE_KEY, "Constant float measure", Metric.ValueType.FLOAT)
+    .setDescription("Return always the same float measure for every components")
+    .setDirection(Metric.DIRECTION_WORST)
+    .setDomain(CoreMetrics.DOMAIN_GENERAL)
+    .create();
+
+  @Override
+  public List<Metric> getMetrics() {
+    return Lists.<Metric>newArrayList(CONSTANT_FLOAT_MEASURE);
+  }
+}
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/package-info.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/package-info.java
new file mode 100644 (file)
index 0000000..53dbecc
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.xoo.measures;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+