aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-12-04 14:51:21 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:05 +0100
commit4660315c13ba09f58f5034ca99b855ece9f75e25 (patch)
tree97152755ad675a2b77ca36d9889558c280988e14 /sonar-plugin-api
parent19a03e51f75d342155079b808fa879ece194a196 (diff)
downloadsonarqube-4660315c13ba09f58f5034ca99b855ece9f75e25.tar.gz
sonarqube-4660315c13ba09f58f5034ca99b855ece9f75e25.zip
SONAR-11465 Add project level Sensor EP
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/Sensor.java53
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/package-info.java21
5 files changed, 82 insertions, 4 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java
index 5786229a165..ee04d993594 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java
@@ -33,6 +33,7 @@ import org.sonarsource.api.sonarlint.SonarLintSide;
*
* For testing purpose you can use {@link SensorContextTester}
* @since 5.1
+ * @since 7.6 use {@link org.sonar.api.scanner.sensor.Sensor} instead to make your Sensor run only once per analysis, and no more once per module
*/
@ScannerSide
@SonarLintSide
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
index f207b2680c9..98cb74c0d15 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
@@ -59,13 +59,13 @@ public interface SensorContext {
Settings settings();
/**
- * Get settings of the current module, or of the project for a global Sensor.
+ * Get settings of the project.
* @since 6.5
*/
Configuration config();
/**
- * Get filesystem of the current module.
+ * Get filesystem of the project.
*/
FileSystem fileSystem();
@@ -77,6 +77,7 @@ public interface SensorContext {
/**
* @since 5.5
* @deprecated since 7.6 modules are deprecated. Use {@link #project()} instead.
+ * @throws UnsupportedOperationException for global {@link org.sonar.api.scanner.sensor.Sensor}s
*/
@Deprecated
InputModule module();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java
index 56f5df73987..133766139d3 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java
@@ -24,7 +24,7 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.config.Configuration;
/**
- * Describe what a {@link Sensor} is doing. Information may be used by the platform
+ * Describe what a {@link org.sonar.api.scanner.sensor.Sensor} is doing. Information may be used by the platform
* to log interesting information or perform some optimization.
* See {@link Sensor#describe(SensorDescriptor)}
* @since 5.1
@@ -88,11 +88,13 @@ public interface SensorDescriptor {
/**
* This sensor should be executed at the project level, instead of per-module.
* @since 6.4
+ * @deprecated since 7.6 change your {@link Sensor} to a {@link org.sonar.api.scanner.sensor.Sensor} instead
*/
+ @Deprecated
SensorDescriptor global();
/**
- * Predicate that will be evaluated on current module/project {@link Configuration} by the platform to decide if execution of the {@link Sensor} should be skipped.
+ * Predicate that will be evaluated on current project {@link Configuration} by the platform to decide if execution of the {@link Sensor} should be skipped.
* @since 6.5
*/
SensorDescriptor onlyWhenConfiguration(Predicate<Configuration> predicate);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/Sensor.java b/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/Sensor.java
new file mode 100644
index 00000000000..ededb64909a
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/Sensor.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.api.scanner.sensor;
+
+import org.sonar.api.ExtensionPoint;
+import org.sonar.api.scanner.ScannerSide;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.batch.sensor.internal.SensorContextTester;
+import org.sonarsource.api.sonarlint.SonarLintSide;
+
+/**
+ * <p>
+ * A sensor is invoked once for each project analysis. Sensors are mainly used to add measures and issues on {@link org.sonar.api.batch.fs.InputFile}s.
+ * <p>
+ * For example the Cobertura Sensor parses Cobertura report and saves the first-level of measures on files.
+ *
+ * For testing purpose you can use {@link SensorContextTester}
+ * @since 7.6
+ */
+@ScannerSide
+@SonarLintSide
+@ExtensionPoint
+public interface Sensor {
+
+ /**
+ * Populate {@link SensorDescriptor} of this sensor.
+ */
+ void describe(SensorDescriptor descriptor);
+
+ /**
+ * The actual sensor code.
+ */
+ void execute(SensorContext context);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/package-info.java
new file mode 100644
index 00000000000..e1130f2e7e5
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.api.scanner.sensor;