From: Julien Lancelot Date: Wed, 21 Oct 2015 13:29:38 +0000 (+0200) Subject: Create a Xoo sensor to compute float measure X-Git-Tag: 5.3-RC1~470 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eff6a172cbef2cfecbcd6e40f99106370a365848;p=sonarqube.git Create a Xoo sensor to compute float measure --- diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java index fe8a123a6da..a74dd0c8d5b 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java @@ -19,12 +19,8 @@ */ 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 index 00000000000..85e139f86e1 --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/ConstantFloatMeasureSensor.java @@ -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 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 index 00000000000..511baf2761c --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/XooMetrics.java @@ -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 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 getMetrics() { + return Lists.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 index 00000000000..53dbecc35dc --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/measures/package-info.java @@ -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; +