aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizerSensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java16
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java30
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java28
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java12
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java53
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java55
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java20
18 files changed, 135 insertions, 125 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java
index e16829385c8..e9963f83845 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java
@@ -98,8 +98,8 @@ public class CoveragePerTestSensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("Xoo Coverage Per Test Sensor")
- .workOnLanguages(Xoo.KEY)
- .workOnFileTypes(InputFile.Type.TEST);
+ .onlyOnLanguages(Xoo.KEY)
+ .onlyOnFileType(InputFile.Type.TEST);
}
@Override
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java
index 7ffca61bb62..a1012002896 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java
@@ -91,8 +91,8 @@ public class DependencySensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("Xoo Dependency Sensor")
- .workOnLanguages(Xoo.KEY)
- .workOnFileTypes(InputFile.Type.MAIN);
+ .onlyOnLanguages(Xoo.KEY)
+ .onlyOnFileType(InputFile.Type.MAIN);
}
@Override
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 5ec2190ce2d..471a5835639 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
@@ -112,8 +112,8 @@ public class MeasureSensor implements Sensor {
descriptor
.name("Xoo Measure Sensor")
.provides(CoreMetrics.LINES)
- .workOnLanguages(Xoo.KEY)
- .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST);
+ .onlyOnLanguages(Xoo.KEY)
+ .onOnFileType(InputFile.Type.MAIN, InputFile.Type.TEST);
}
@Override
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
index 61131e8b87a..fbff5f75641 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
@@ -87,8 +87,8 @@ public class SymbolReferencesSensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("Xoo Symbol Reference Sensor")
- .workOnLanguages(Xoo.KEY)
- .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST);
+ .onlyOnLanguages(Xoo.KEY)
+ .onOnFileType(InputFile.Type.MAIN, InputFile.Type.TEST);
}
@Override
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
index a930c9c8f4c..d72b50b4089 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
@@ -85,8 +85,8 @@ public class SyntaxHighlightingSensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("Xoo Highlighting Sensor")
- .workOnLanguages(Xoo.KEY)
- .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST);
+ .onlyOnLanguages(Xoo.KEY)
+ .onOnFileType(InputFile.Type.MAIN, InputFile.Type.TEST);
}
@Override
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java
index bd297b61172..a406a20a9ca 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java
@@ -97,8 +97,8 @@ public class TestCaseSensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("Xoo TestPlan Sensor")
- .workOnLanguages(Xoo.KEY)
- .workOnFileTypes(InputFile.Type.TEST);
+ .onlyOnLanguages(Xoo.KEY)
+ .onlyOnFileType(InputFile.Type.TEST);
}
@Override
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizerSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizerSensor.java
index ae1c7e2820a..3190c9d7712 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizerSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizerSensor.java
@@ -61,8 +61,8 @@ public class XooTokenizerSensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("Xoo Tokenizer Sensor")
- .workOnLanguages(Xoo.KEY)
- .workOnFileTypes(InputFile.Type.MAIN);
+ .onlyOnLanguages(Xoo.KEY)
+ .onlyOnFileType(InputFile.Type.MAIN);
}
@Override
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java
index 01b2f8168bd..04dc7be446f 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java
@@ -34,9 +34,9 @@ public class CreateIssueByInternalKeySensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("CreateIssueByInternalKeySensor")
- .workOnLanguages(Xoo.KEY)
+ .onlyOnLanguages(Xoo.KEY)
.createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY)
- .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST);
+ .onOnFileType(InputFile.Type.MAIN, InputFile.Type.TEST);
}
@Override
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java
index 7a2161b1049..548b596c300 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java
@@ -35,9 +35,9 @@ public class OneIssueOnDirPerFileSensor implements Sensor {
public void describe(SensorDescriptor descriptor) {
descriptor
.name("One Issue On Dir Per File")
- .workOnLanguages(Xoo.KEY)
+ .onlyOnLanguages(Xoo.KEY)
.createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY)
- .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST);
+ .onOnFileType(InputFile.Type.MAIN, InputFile.Type.TEST);
}
@Override
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
index 31db08c01f2..081bb1a0a2b 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
@@ -39,9 +39,9 @@ public class OneIssuePerLineSensor implements Sensor {
descriptor
.name("One Issue Per Line")
.dependsOn(CoreMetrics.LINES)
- .workOnLanguages(Xoo.KEY)
+ .onlyOnLanguages(Xoo.KEY)
.createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY)
- .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST);
+ .onOnFileType(InputFile.Type.MAIN, InputFile.Type.TEST);
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java
index 4639a8fbd83..c316078f714 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java
@@ -21,18 +21,12 @@ package org.sonar.batch.scan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.batch.DependsUpon;
-import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.api.resources.Project;
import org.sonar.batch.scan2.AnalyzerOptimizer;
-import java.util.Arrays;
-import java.util.List;
-
public class SensorWrapper implements org.sonar.api.batch.Sensor {
private static final Logger LOG = LoggerFactory.getLogger(SensorWrapper.class);
@@ -54,16 +48,6 @@ public class SensorWrapper implements org.sonar.api.batch.Sensor {
return wrappedSensor;
}
- @DependedUpon
- public List<Metric> provides() {
- return Arrays.asList(descriptor.provides());
- }
-
- @DependsUpon
- public List<Metric> depends() {
- return Arrays.asList(descriptor.dependsOn());
- }
-
@Override
public boolean shouldExecuteOnProject(Project project) {
return optimizer.shouldExecute(descriptor);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java
index 4ae3ddfce09..c149a7aea15 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java
@@ -24,9 +24,9 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+import org.sonar.api.config.Settings;
public class AnalyzerOptimizer implements BatchComponent {
@@ -34,10 +34,12 @@ public class AnalyzerOptimizer implements BatchComponent {
private final FileSystem fs;
private final ActiveRules activeRules;
+ private final Settings settings;
- public AnalyzerOptimizer(FileSystem fs, ActiveRules activeRules) {
+ public AnalyzerOptimizer(FileSystem fs, ActiveRules activeRules, Settings settings) {
this.fs = fs;
this.activeRules = activeRules;
+ this.settings = settings;
}
/**
@@ -52,6 +54,21 @@ public class AnalyzerOptimizer implements BatchComponent {
LOG.debug("'{}' skipped because there is no related rule activated in the quality profile", descriptor.name());
return false;
}
+ if (!settingsCondition(descriptor)) {
+ LOG.debug("'{}' skipped because one of the required properties is missing", descriptor.name());
+ return false;
+ }
+ return true;
+ }
+
+ private boolean settingsCondition(DefaultSensorDescriptor descriptor) {
+ if (!descriptor.properties().isEmpty()) {
+ for (String propertyKey : descriptor.properties()) {
+ if (!settings.hasKey(propertyKey)) {
+ return false;
+ }
+ }
+ }
return true;
}
@@ -68,15 +85,10 @@ public class AnalyzerOptimizer implements BatchComponent {
}
private boolean fsCondition(DefaultSensorDescriptor descriptor) {
- if (!descriptor.languages().isEmpty() || !descriptor.types().isEmpty()) {
+ if (!descriptor.languages().isEmpty() || descriptor.type() != null) {
FilePredicate langPredicate = descriptor.languages().isEmpty() ? fs.predicates().all() : fs.predicates().hasLanguages(descriptor.languages());
- FilePredicate typePredicate = descriptor.types().isEmpty() ? fs.predicates().all() : fs.predicates().none();
- for (InputFile.Type type : descriptor.types()) {
- typePredicate = fs.predicates().or(
- typePredicate,
- fs.predicates().hasType(type));
- }
+ FilePredicate typePredicate = descriptor.type() == null ? fs.predicates().all() : fs.predicates().hasType(descriptor.type());
return fs.hasFiles(fs.predicates().and(langPredicate, typePredicate));
}
return true;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
index bbfcbdaa6f1..56e477ec9c7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
@@ -59,11 +59,7 @@ public final class ScmSensor implements Sensor {
@Override
public void describe(SensorDescriptor descriptor) {
- descriptor
- .name("SCM Sensor")
- .provides(CoreMetrics.SCM_AUTHORS_BY_LINE,
- CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE,
- CoreMetrics.SCM_REVISIONS_BY_LINE);
+ descriptor.name("SCM Sensor");
}
@Override
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java
index b26434d3048..b056715e260 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java
@@ -29,6 +29,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+import org.sonar.api.config.Settings;
import org.sonar.api.rule.RuleKey;
import static org.assertj.core.api.Assertions.assertThat;
@@ -41,9 +42,12 @@ public class AnalyzerOptimizerTest {
public ExpectedException thrown = ExpectedException.none();
private AnalyzerOptimizer optimizer;
+ private Settings settings;
+
@Before
public void prepare() {
- optimizer = new AnalyzerOptimizer(fs, new ActiveRulesBuilder().build());
+ settings = new Settings();
+ optimizer = new AnalyzerOptimizer(fs, new ActiveRulesBuilder().build(), settings);
}
@Test
@@ -56,7 +60,7 @@ public class AnalyzerOptimizerTest {
@Test
public void should_optimize_on_language() throws Exception {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
- .workOnLanguages("java", "php");
+ .onlyOnLanguages("java", "php");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
fs.add(new DefaultInputFile("foo", "src/Foo.java").setLanguage("java"));
@@ -66,7 +70,7 @@ public class AnalyzerOptimizerTest {
@Test
public void should_optimize_on_type() throws Exception {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
- .workOnFileTypes(InputFile.Type.MAIN);
+ .onlyOnFileType(InputFile.Type.MAIN);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
fs.add(new DefaultInputFile("foo", "tests/FooTest.java").setType(InputFile.Type.TEST));
@@ -79,8 +83,8 @@ public class AnalyzerOptimizerTest {
@Test
public void should_optimize_on_both_type_and_language() throws Exception {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
- .workOnLanguages("java", "php")
- .workOnFileTypes(InputFile.Type.MAIN);
+ .onlyOnLanguages("java", "php")
+ .onlyOnFileType(InputFile.Type.MAIN);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
fs.add(new DefaultInputFile("foo", "tests/FooTest.java").setLanguage("java").setType(InputFile.Type.TEST));
@@ -101,7 +105,7 @@ public class AnalyzerOptimizerTest {
.create(RuleKey.of("repo1", "foo"))
.activate()
.build();
- optimizer = new AnalyzerOptimizer(fs, activeRules);
+ optimizer = new AnalyzerOptimizer(fs, activeRules, settings);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
@@ -111,7 +115,17 @@ public class AnalyzerOptimizerTest {
.create(RuleKey.of("squid", "rule"))
.activate()
.build();
- optimizer = new AnalyzerOptimizer(fs, activeRules);
+ optimizer = new AnalyzerOptimizer(fs, activeRules, settings);
+ assertThat(optimizer.shouldExecute(descriptor)).isTrue();
+ }
+
+ @Test
+ public void should_optimize_on_settings() throws Exception {
+ DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
+ .requireProperty("sonar.foo.reportPath");
+ assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+ settings.setProperty("sonar.foo.reportPath", "foo");
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
index 34c5d6bbdbd..e81f3509a55 100644
--- a/sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
@@ -26,8 +26,6 @@ import org.apache.commons.lang.ClassUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.maven.DependsUponMavenPlugin;
import org.sonar.api.batch.maven.MavenPluginHandler;
-import org.sonar.api.batch.sensor.Sensor;
-import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.AnnotationUtils;
@@ -148,11 +146,6 @@ public class BatchExtensionDictionnary {
private <T> List<Object> getDependencies(T extension) {
List<Object> result = new ArrayList<Object>();
result.addAll(evaluateAnnotatedClasses(extension, DependsUpon.class));
- if (ClassUtils.isAssignable(extension.getClass(), Sensor.class)) {
- DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
- ((Sensor) extension).describe(descriptor);
- result.addAll(Arrays.asList(descriptor.dependsOn()));
- }
return result;
}
@@ -162,11 +155,6 @@ public class BatchExtensionDictionnary {
public <T> List<Object> getDependents(T extension) {
List<Object> result = new ArrayList<Object>();
result.addAll(evaluateAnnotatedClasses(extension, DependedUpon.class));
- if (ClassUtils.isAssignable(extension.getClass(), Sensor.class)) {
- DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
- ((Sensor) extension).describe(descriptor);
- result.addAll(Arrays.asList(descriptor.provides()));
- }
return result;
}
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 a2187c13c49..06abd08f58c 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
@@ -20,50 +20,63 @@
package org.sonar.api.batch.sensor;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.measure.Metric;
/**
- * Describe what an {@link Sensor} is doing. Information may be used by the platform
+ * Describe what a {@link 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.0
+ * @since 5.1
*/
public interface SensorDescriptor {
/**
- * Name of the {@link Sensor}. Will be displayed in logs.
+ * Displayable name of the {@link Sensor}. Will be displayed in logs.
*/
- SensorDescriptor name(String name);
+ SensorDescriptor name(String sensorName);
/**
- * List {@link Metric} this {@link Sensor} depends on. Will be used to execute sensors in correct order.
+ * Language this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
+ * no file for given languages are present in the project.
+ * Default is to execute sensor for all languages.
*/
- SensorDescriptor dependsOn(Metric<?>... metrics);
+ SensorDescriptor onlyOnLanguage(String languageKey);
/**
- * List {@link Metric} this {@link Sensor} provides. Will be used to execute sensors in correct order.
+ * List languages this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
+ * no file for given languages are present in the project.
+ * Default is to execute sensor for all languages.
*/
- SensorDescriptor provides(Metric<?>... metrics);
+ SensorDescriptor onlyOnLanguages(String... languageKeys);
/**
- * List languages this {@link Sensor} work on. May be used by the platform to skip execution of the {@link Sensor} when
- * no file for given languages are present in the project.
- * If no language is provided then it will be executed for all languages.
+ * {@link InputFile.Type} this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
+ * no file for given type are present in the project.
+ * Default is to execute sensor whatever are the available file types.
*/
- SensorDescriptor workOnLanguages(String... languageKeys);
+ SensorDescriptor onlyOnFileType(InputFile.Type type);
/**
- * List {@link InputFile.Type} this {@link Sensor} work on. May be used by the platform to skip execution of the {@link Sensor} when
- * no file for given type are present in the project.
- * If you don't call this method then it means sensor is working on all input file types.
+ * Rule repository this {@link Sensor} create issues for. Used by the platform to skip execution of the {@link Sensor} when
+ * no rule is activated for the given repository.
*/
- SensorDescriptor workOnFileTypes(InputFile.Type... types);
+ SensorDescriptor createIssuesForRuleRepository(String... repositoryKey);
/**
- * List {@link InputFile.Type} this {@link Sensor} work on. May be used by the platform to skip execution of the {@link Sensor} when
- * no file for given type are present in the project.
- * If not type is provided then it will be executed for all types.
+ * List rule repositories this {@link Sensor} create issues for. Used by the platform to skip execution of the {@link Sensor} when
+ * no rule is activated for the given repositories.
*/
SensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys);
+ /**
+ * Property this {@link Sensor} depends on. Used by the platform to skip execution of the {@link Sensor} when
+ * property is not set.
+ */
+ SensorDescriptor requireProperty(String... propertyKey);
+
+ /**
+ * List properties this {@link Sensor} depends on. Used by the platform to skip execution of the {@link Sensor} when
+ * property is not set.
+ */
+ SensorDescriptor requireProperties(String... propertyKeys);
+
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java
index a371fc57fb8..8f6925f814d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java
@@ -19,10 +19,10 @@
*/
package org.sonar.api.batch.sensor.internal;
+import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.SensorDescriptor;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.measure.Metric;
+import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
@@ -30,36 +30,32 @@ import java.util.Collection;
public class DefaultSensorDescriptor implements SensorDescriptor {
private String name;
- private Metric<?>[] dependsOn = new Metric<?>[0];
- private Metric<?>[] provides = new Metric<?>[0];
private String[] languages = new String[0];
- private InputFile.Type[] types = new InputFile.Type[0];
+ private InputFile.Type type = null;
private String[] ruleRepositories = new String[0];
+ private String[] properties = new String[0];
public String name() {
return name;
}
- public Metric[] dependsOn() {
- return dependsOn;
- }
-
- public Metric[] provides() {
- return provides;
- }
-
public Collection<String> languages() {
return Arrays.asList(languages);
}
- public Collection<InputFile.Type> types() {
- return Arrays.asList(types);
+ @Nullable
+ public InputFile.Type type() {
+ return type;
}
public Collection<String> ruleRepositories() {
return Arrays.asList(ruleRepositories);
}
+ public Collection<String> properties() {
+ return Arrays.asList(properties);
+ }
+
@Override
public DefaultSensorDescriptor name(String name) {
this.name = name;
@@ -67,27 +63,25 @@ public class DefaultSensorDescriptor implements SensorDescriptor {
}
@Override
- public DefaultSensorDescriptor dependsOn(Metric<?>... metrics) {
- this.dependsOn = metrics;
- return this;
+ public DefaultSensorDescriptor onlyOnLanguage(String languageKey) {
+ return onlyOnLanguages(languageKey);
}
@Override
- public DefaultSensorDescriptor provides(Metric<?>... metrics) {
- this.provides = metrics;
+ public DefaultSensorDescriptor onlyOnLanguages(String... languageKeys) {
+ this.languages = languageKeys;
return this;
}
@Override
- public DefaultSensorDescriptor workOnLanguages(String... languageKeys) {
- this.languages = languageKeys;
+ public DefaultSensorDescriptor onlyOnFileType(InputFile.Type type) {
+ this.type = type;
return this;
}
@Override
- public DefaultSensorDescriptor workOnFileTypes(InputFile.Type... types) {
- this.types = types;
- return this;
+ public DefaultSensorDescriptor createIssuesForRuleRepository(String... repositoryKey) {
+ return createIssuesForRuleRepositories(repositoryKey);
}
@Override
@@ -96,4 +90,15 @@ public class DefaultSensorDescriptor implements SensorDescriptor {
return this;
}
+ @Override
+ public DefaultSensorDescriptor requireProperty(String... propertyKey) {
+ return requireProperties(propertyKey);
+ }
+
+ @Override
+ public DefaultSensorDescriptor requireProperties(String... propertyKeys) {
+ this.properties = propertyKeys;
+ return this;
+ }
+
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java
index 5b890818f8a..ebad1ccdbcb 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java
@@ -19,11 +19,9 @@
*/
package org.sonar.api.batch.sensor.internal;
-import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-
import org.junit.Test;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.measures.CoreMetrics;
+
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultSensorDescriptorTest {
@@ -33,16 +31,16 @@ public class DefaultSensorDescriptorTest {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
descriptor
.name("Foo")
- .dependsOn(CoreMetrics.NCLOC)
- .provides(CoreMetrics.BLOCKER_VIOLATIONS)
- .workOnLanguages("java", "php")
- .workOnFileTypes(InputFile.Type.MAIN);
+ .onlyOnLanguage("java")
+ .onlyOnFileType(InputFile.Type.MAIN)
+ .requireProperty("sonar.foo.reportPath")
+ .createIssuesForRuleRepository("squid-java");
assertThat(descriptor.name()).isEqualTo("Foo");
- assertThat(descriptor.dependsOn()).containsOnly(CoreMetrics.NCLOC);
- assertThat(descriptor.provides()).containsOnly(CoreMetrics.BLOCKER_VIOLATIONS);
- assertThat(descriptor.languages()).containsOnly("java", "php");
- assertThat(descriptor.types()).containsOnly(InputFile.Type.MAIN);
+ assertThat(descriptor.languages()).containsOnly("java");
+ assertThat(descriptor.type()).isEqualTo(InputFile.Type.MAIN);
+ assertThat(descriptor.properties()).containsOnly("sonar.foo.reportPath");
+ assertThat(descriptor.ruleRepositories()).containsOnly("squid-java");
}
}