aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java21
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/SensorContextAdaptor.java (renamed from sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java)57
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java22
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerIssueCache.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerMeasureCache.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java55
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultFileLinesContext.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java7
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureSensor.java (renamed from sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureAnalyzer.java)25
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivitySensor.java (renamed from sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivityAnalyzer.java)17
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java19
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/SensorContextAdapterTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/scan/AnalyzerContextAdapterTest.java)29
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java14
23 files changed, 200 insertions, 194 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
index 0ec11fc5973..fdbdc536eaf 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
@@ -22,9 +22,8 @@ package org.sonar.batch.bootstrap;
import com.google.common.collect.Lists;
import org.apache.commons.lang.ClassUtils;
import org.sonar.api.batch.CheckProject;
-import org.sonar.api.batch.Sensor;
-import org.sonar.api.batch.analyzer.Analyzer;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.batch.scan.SensorWrapper;
@@ -40,10 +39,10 @@ import java.util.List;
*/
public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensionDictionnary {
- private AnalyzerContext context;
+ private SensorContext context;
private AnalyzerOptimizer analyzerOptimizer;
- public BatchExtensionDictionnary(ComponentContainer componentContainer, AnalyzerContext context, AnalyzerOptimizer analyzerOptimizer) {
+ public BatchExtensionDictionnary(ComponentContainer componentContainer, SensorContext context, AnalyzerOptimizer analyzerOptimizer) {
super(componentContainer);
this.context = context;
this.analyzerOptimizer = analyzerOptimizer;
@@ -60,17 +59,17 @@ public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensio
private <T> List<T> getFilteredExtensions(Class<T> type, @Nullable Project project, @Nullable ExtensionMatcher matcher) {
List<T> result = Lists.newArrayList();
for (Object extension : getExtensions(type)) {
- if (Sensor.class.equals(type) && extension instanceof Analyzer) {
- extension = new SensorWrapper((Analyzer) extension, context, analyzerOptimizer);
+ if (org.sonar.api.batch.Sensor.class.equals(type) && extension instanceof Sensor) {
+ extension = new SensorWrapper((Sensor) extension, context, analyzerOptimizer);
}
if (shouldKeep(type, extension, project, matcher)) {
result.add((T) extension);
}
}
- if (Sensor.class.equals(type)) {
+ if (org.sonar.api.batch.Sensor.class.equals(type)) {
// Retrieve Analyzer and wrap then in SensorWrapper
- for (Object extension : getExtensions(Analyzer.class)) {
- extension = new SensorWrapper((Analyzer) extension, context, analyzerOptimizer);
+ for (Object extension : getExtensions(Sensor.class)) {
+ extension = new SensorWrapper((Sensor) extension, context, analyzerOptimizer);
if (shouldKeep(type, extension, project, matcher)) {
result.add((T) extension);
}
@@ -81,7 +80,7 @@ public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensio
private boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) {
boolean keep = (ClassUtils.isAssignable(extension.getClass(), type)
- || (Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Analyzer.class)))
+ || (Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class)))
&& (matcher == null || matcher.accept(extension));
if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) {
keep = ((CheckProject) extension).shouldExecuteOnProject(project);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java
index f20917fe971..9a96da2b2aa 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java
@@ -19,10 +19,11 @@
*/
package org.sonar.batch.mediumtest;
+import org.sonar.api.batch.sensor.issue.Issue;
+import org.sonar.api.batch.sensor.measure.Measure;
+
import org.apache.commons.io.IOUtils;
import org.sonar.api.SonarPlugin;
-import org.sonar.api.batch.analyzer.issue.AnalyzerIssue;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.batch.debt.internal.DefaultDebtModel;
import org.sonar.api.batch.fs.InputFile;
@@ -194,17 +195,17 @@ public class AnalyzerMediumTester {
}
public static class TaskResult implements ScanTaskObserver {
- private List<AnalyzerIssue> issues = new ArrayList<AnalyzerIssue>();
- private List<AnalyzerMeasure> measures = new ArrayList<AnalyzerMeasure>();
+ private List<Issue> issues = new ArrayList<Issue>();
+ private List<Measure> measures = new ArrayList<Measure>();
private List<InputFile> inputFiles = new ArrayList<InputFile>();
@Override
public void scanTaskCompleted(ProjectScanContainer container) {
- for (AnalyzerIssue issue : container.getComponentByType(AnalyzerIssueCache.class).all()) {
+ for (Issue issue : container.getComponentByType(AnalyzerIssueCache.class).all()) {
issues.add(issue);
}
- for (AnalyzerMeasure<?> measure : container.getComponentByType(AnalyzerMeasureCache.class).all()) {
+ for (Measure<?> measure : container.getComponentByType(AnalyzerMeasureCache.class).all()) {
measures.add(measure);
}
@@ -214,11 +215,11 @@ public class AnalyzerMediumTester {
}
}
- public List<AnalyzerIssue> issues() {
+ public List<Issue> issues() {
return issues;
}
- public List<AnalyzerMeasure> measures() {
+ public List<Measure> measures() {
return measures;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java
index 169683b4235..37fde7a3495 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java
@@ -19,8 +19,6 @@
*/
package org.sonar.batch.phases;
-import org.sonar.api.batch.analyzer.Analyzer;
-
import org.apache.commons.lang.ClassUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.InstantiationStrategy;
@@ -38,7 +36,7 @@ public abstract class SensorMatcher implements BatchExtension, ExtensionMatcher
@Override
public final boolean accept(Object extension) {
return ClassUtils.isAssignable(extension.getClass(), Sensor.class)
- && acceptSensor((Sensor) extension) || ClassUtils.isAssignable(extension.getClass(), Analyzer.class);
+ && acceptSensor((Sensor) extension) || ClassUtils.isAssignable(extension.getClass(), Sensor.class);
}
public abstract boolean acceptSensor(Sensor sensor);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
index 455567e5e68..733a8237dd8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
@@ -120,7 +120,7 @@ public class ModuleScanContainer extends ComponentContainer {
TimeMachineConfiguration.class,
DefaultSensorContext.class,
- AnalyzerContextAdaptor.class,
+ SensorContextAdaptor.class,
BatchExtensionDictionnary.class,
DefaultTimeMachine.class,
ViolationFilters.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorContextAdaptor.java
index 8b883db4483..4798b492526 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorContextAdaptor.java
@@ -19,24 +19,22 @@
*/
package org.sonar.batch.scan;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.analyzer.issue.AnalyzerIssue;
-import org.sonar.api.batch.analyzer.issue.AnalyzerIssueBuilder;
-import org.sonar.api.batch.analyzer.issue.internal.DefaultAnalyzerIssueBuilder;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder;
-import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.issue.Issue;
+import org.sonar.api.batch.sensor.issue.IssueBuilder;
+import org.sonar.api.batch.sensor.issue.internal.DefaultIssueBuilder;
+import org.sonar.api.batch.sensor.measure.Measure;
+import org.sonar.api.batch.sensor.measure.MeasureBuilder;
+import org.sonar.api.batch.sensor.measure.internal.DefaultMeasureBuilder;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.config.Settings;
import org.sonar.api.issue.Issuable;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.measures.Formula;
-import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.measures.PersistenceMode;
import org.sonar.api.measures.SumChildDistributionFormula;
@@ -45,17 +43,16 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
import org.sonar.api.rule.RuleKey;
-import org.sonar.core.issue.DefaultIssueBuilder;
import java.io.Serializable;
/**
- * Implements {@link AnalyzerContext} but forward everything to {@link SensorContext} for backward compatibility.
+ * Implements {@link SensorContext} but forward everything to {@link org.sonar.api.batch.SensorContext} for backward compatibility.
*
*/
-public class AnalyzerContextAdaptor implements AnalyzerContext {
+public class SensorContextAdaptor implements SensorContext {
- private SensorContext sensorContext;
+ private org.sonar.api.batch.SensorContext sensorContext;
private MetricFinder metricFinder;
private Project project;
private ResourcePerspectives perspectives;
@@ -63,7 +60,7 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
private FileSystem fs;
private ActiveRules activeRules;
- public AnalyzerContextAdaptor(SensorContext sensorContext, MetricFinder metricFinder, Project project, ResourcePerspectives perspectives,
+ public SensorContextAdaptor(org.sonar.api.batch.SensorContext sensorContext, MetricFinder metricFinder, Project project, ResourcePerspectives perspectives,
Settings settings, FileSystem fs, ActiveRules activeRules) {
this.sensorContext = sensorContext;
this.metricFinder = metricFinder;
@@ -90,20 +87,20 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
}
@Override
- public <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder() {
- return new DefaultAnalyzerMeasureBuilder<G>();
+ public <G extends Serializable> MeasureBuilder<G> measureBuilder() {
+ return new DefaultMeasureBuilder<G>();
}
@Override
- public AnalyzerMeasure getMeasure(String metricKey) {
+ public Measure getMeasure(String metricKey) {
Metric<?> m = findMetricOrFail(metricKey);
return getMeasure(m);
}
@Override
- public <G extends Serializable> AnalyzerMeasure<G> getMeasure(Metric<G> metric) {
+ public <G extends Serializable> Measure<G> getMeasure(Metric<G> metric) {
org.sonar.api.measures.Metric<G> m = (org.sonar.api.measures.Metric<G>) findMetricOrFail(metric.key());
- Measure<G> measure = sensorContext.getMeasure(m);
+ org.sonar.api.measures.Measure<G> measure = sensorContext.getMeasure(m);
if (measure == null) {
return null;
}
@@ -115,7 +112,7 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
}
@Override
- public AnalyzerMeasure getMeasure(InputFile file, String metricKey) {
+ public Measure getMeasure(InputFile file, String metricKey) {
Metric<?> m = findMetricOrFail(metricKey);
return getMeasure(file, m);
}
@@ -129,10 +126,10 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
}
@Override
- public <G extends Serializable> AnalyzerMeasure<G> getMeasure(InputFile file, Metric<G> metric) {
+ public <G extends Serializable> Measure<G> getMeasure(InputFile file, Metric<G> metric) {
File fileRes = File.create(file.relativePath());
org.sonar.api.measures.Metric<G> m = (org.sonar.api.measures.Metric<G>) findMetricOrFail(metric.key());
- Measure<G> measure = sensorContext.getMeasure(fileRes, m);
+ org.sonar.api.measures.Measure<G> measure = sensorContext.getMeasure(fileRes, m);
if (measure == null) {
return null;
}
@@ -144,13 +141,13 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
}
@Override
- public void addMeasure(AnalyzerMeasure<?> measure) {
+ public void addMeasure(Measure<?> measure) {
org.sonar.api.measures.Metric<?> m = metricFinder.findByKey(measure.metric().key());
if (m == null) {
throw new IllegalStateException("Unknow metric with key: " + measure.metric().key());
}
- Measure measureToSave = new Measure(m);
+ org.sonar.api.measures.Measure measureToSave = new org.sonar.api.measures.Measure(m);
setValueAccordingToMetricType(measure, m, measureToSave);
if (measure.inputFile() != null) {
Formula formula = measure.metric() instanceof org.sonar.api.measures.Metric ?
@@ -165,7 +162,7 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
}
}
- private void setValueAccordingToMetricType(AnalyzerMeasure<?> measure, org.sonar.api.measures.Metric<?> m, Measure measureToSave) {
+ private void setValueAccordingToMetricType(Measure<?> measure, org.sonar.api.measures.Metric<?> m, org.sonar.api.measures.Measure measureToSave) {
switch (m.getType()) {
case BOOL:
measureToSave.setValue(Boolean.TRUE.equals(measure.value()) ? 1.0 : 0.0);
@@ -200,12 +197,12 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
}
@Override
- public AnalyzerIssueBuilder issueBuilder() {
- return new DefaultAnalyzerIssueBuilder();
+ public IssueBuilder issueBuilder() {
+ return new DefaultIssueBuilder();
}
@Override
- public boolean addIssue(AnalyzerIssue issue) {
+ public boolean addIssue(Issue issue) {
Resource r;
InputFile inputFile = issue.inputFile();
if (inputFile != null) {
@@ -217,8 +214,8 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
return issuable.addIssue(toDefaultIssue(project.getKey(), r.getKey(), issue));
}
- public static DefaultIssue toDefaultIssue(String projectKey, String componentKey, AnalyzerIssue issue) {
- return new DefaultIssueBuilder()
+ public static DefaultIssue toDefaultIssue(String projectKey, String componentKey, Issue issue) {
+ return new org.sonar.core.issue.DefaultIssueBuilder()
.componentKey(componentKey)
.projectKey(projectKey)
.ruleKey(RuleKey.of(issue.ruleKey().repository(), issue.ruleKey().rule()))
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 5489b9da528..617ade05f3f 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,29 +21,27 @@ package org.sonar.batch.scan;
import org.sonar.api.batch.DependedUpon;
import org.sonar.api.batch.DependsUpon;
-import org.sonar.api.batch.Sensor;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.analyzer.Analyzer;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor;
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 Sensor {
+public class SensorWrapper implements org.sonar.api.batch.Sensor {
- private Analyzer analyzer;
- private AnalyzerContext adaptor;
- private DefaultAnalyzerDescriptor descriptor;
+ private Sensor analyzer;
+ private SensorContext adaptor;
+ private DefaultSensorDescriptor descriptor;
private AnalyzerOptimizer optimizer;
- public SensorWrapper(Analyzer analyzer, AnalyzerContext adaptor, AnalyzerOptimizer optimizer) {
+ public SensorWrapper(Sensor analyzer, SensorContext adaptor, AnalyzerOptimizer optimizer) {
this.analyzer = analyzer;
this.optimizer = optimizer;
- descriptor = new DefaultAnalyzerDescriptor();
+ descriptor = new DefaultSensorDescriptor();
analyzer.describe(descriptor);
this.adaptor = adaptor;
}
@@ -64,7 +62,7 @@ public class SensorWrapper implements Sensor {
}
@Override
- public void analyse(Project module, SensorContext context) {
+ public void analyse(Project module, org.sonar.api.batch.SensorContext context) {
analyzer.analyse(adaptor);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java
index c422da9a3c3..cfd03f82e59 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java
@@ -19,12 +19,13 @@
*/
package org.sonar.batch.scan2;
+import org.sonar.api.batch.sensor.issue.Issue;
+import org.sonar.api.batch.sensor.measure.Measure;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.analyzer.issue.AnalyzerIssue;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
@@ -97,7 +98,7 @@ public final class AnalysisPublisher {
jsonWriter
.beginObject().name("issues")
.beginArray();
- for (AnalyzerIssue issue : issueCache.byModule(def.getKey())) {
+ for (Issue issue : issueCache.byModule(def.getKey())) {
jsonWriter.beginObject()
.prop("repository", issue.ruleKey().repository())
.prop("rule", issue.ruleKey().rule());
@@ -128,7 +129,7 @@ public final class AnalysisPublisher {
jsonWriter
.beginObject().name("measures")
.beginArray();
- for (AnalyzerMeasure<?> measure : measureCache.byModule(def.getKey())) {
+ for (Measure<?> measure : measureCache.byModule(def.getKey())) {
jsonWriter.beginObject()
.prop("metricKey", measure.metric().key());
if (measure.inputFile() != null) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerIssueCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerIssueCache.java
index 4adc383a00d..9b0fd3f6d60 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerIssueCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerIssueCache.java
@@ -19,8 +19,9 @@
*/
package org.sonar.batch.scan2;
+import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
+
import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.analyzer.issue.internal.DefaultAnalyzerIssue;
import org.sonar.batch.index.Cache;
import org.sonar.batch.index.Caches;
@@ -30,26 +31,26 @@ import org.sonar.batch.index.Caches;
public class AnalyzerIssueCache implements BatchComponent {
// project key -> resource key -> issue key -> issue
- private final Cache<DefaultAnalyzerIssue> cache;
+ private final Cache<DefaultIssue> cache;
public AnalyzerIssueCache(Caches caches) {
cache = caches.createCache("issues");
}
- public Iterable<DefaultAnalyzerIssue> byComponent(String projectKey, String resourceKey) {
+ public Iterable<DefaultIssue> byComponent(String projectKey, String resourceKey) {
return cache.values(projectKey, resourceKey);
}
- public Iterable<DefaultAnalyzerIssue> all() {
+ public Iterable<DefaultIssue> all() {
return cache.values();
}
- public AnalyzerIssueCache put(String projectKey, String resourceKey, DefaultAnalyzerIssue issue) {
+ public AnalyzerIssueCache put(String projectKey, String resourceKey, DefaultIssue issue) {
cache.put(projectKey, resourceKey, issue.key(), issue);
return this;
}
- public Iterable<DefaultAnalyzerIssue> byModule(String projectKey) {
+ public Iterable<DefaultIssue> byModule(String projectKey) {
return cache.values(projectKey);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerMeasureCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerMeasureCache.java
index 030ff3e6ccc..75d0e31932c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerMeasureCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerMeasureCache.java
@@ -19,9 +19,10 @@
*/
package org.sonar.batch.scan2;
+import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
+
import com.google.common.base.Preconditions;
import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasure;
import org.sonar.batch.index.Cache;
import org.sonar.batch.index.Cache.Entry;
import org.sonar.batch.index.Caches;
@@ -32,25 +33,25 @@ import org.sonar.batch.index.Caches;
public class AnalyzerMeasureCache implements BatchComponent {
// project key -> component key -> metric key -> measure
- private final Cache<DefaultAnalyzerMeasure> cache;
+ private final Cache<DefaultMeasure> cache;
public AnalyzerMeasureCache(Caches caches) {
cache = caches.createCache("measures");
}
- public Iterable<Entry<DefaultAnalyzerMeasure>> entries() {
+ public Iterable<Entry<DefaultMeasure>> entries() {
return cache.entries();
}
- public Iterable<DefaultAnalyzerMeasure> byModule(String projectKey) {
+ public Iterable<DefaultMeasure> byModule(String projectKey) {
return cache.values(projectKey);
}
- public DefaultAnalyzerMeasure<?> byMetric(String projectKey, String resourceKey, String metricKey) {
+ public DefaultMeasure<?> byMetric(String projectKey, String resourceKey, String metricKey) {
return cache.get(projectKey, resourceKey, metricKey);
}
- public AnalyzerMeasureCache put(String projectKey, String resourceKey, DefaultAnalyzerMeasure<?> measure) {
+ public AnalyzerMeasureCache put(String projectKey, String resourceKey, DefaultMeasure<?> measure) {
Preconditions.checkNotNull(projectKey);
Preconditions.checkNotNull(resourceKey);
Preconditions.checkNotNull(measure);
@@ -58,14 +59,14 @@ public class AnalyzerMeasureCache implements BatchComponent {
return this;
}
- public boolean contains(String projectKey, String resourceKey, DefaultAnalyzerMeasure<?> measure) {
+ public boolean contains(String projectKey, String resourceKey, DefaultMeasure<?> measure) {
Preconditions.checkNotNull(projectKey);
Preconditions.checkNotNull(resourceKey);
Preconditions.checkNotNull(measure);
return cache.containsKey(projectKey, resourceKey, measure.metric().key());
}
- public Iterable<DefaultAnalyzerMeasure> all() {
+ public Iterable<DefaultMeasure> all() {
return cache.values();
}
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 0e875360743..fb461854c69 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
@@ -19,8 +19,9 @@
*/
package org.sonar.batch.scan2;
+import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+
import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
@@ -39,14 +40,14 @@ public class AnalyzerOptimizer implements BatchComponent {
/**
* Decide if the given Analyzer should be executed.
*/
- public boolean shouldExecute(DefaultAnalyzerDescriptor descriptor) {
+ public boolean shouldExecute(DefaultSensorDescriptor descriptor) {
// FS Conditions
boolean fsCondition = fsCondition(descriptor);
boolean activeRulesCondition = activeRulesCondition(descriptor);
return fsCondition && activeRulesCondition;
}
- private boolean activeRulesCondition(DefaultAnalyzerDescriptor descriptor) {
+ private boolean activeRulesCondition(DefaultSensorDescriptor descriptor) {
if (!descriptor.ruleRepositories().isEmpty()) {
for (String repoKey : descriptor.ruleRepositories()) {
if (!activeRules.findByRepository(repoKey).isEmpty()) {
@@ -58,7 +59,7 @@ public class AnalyzerOptimizer implements BatchComponent {
return true;
}
- private boolean fsCondition(DefaultAnalyzerDescriptor descriptor) {
+ private boolean fsCondition(DefaultSensorDescriptor descriptor) {
if (!descriptor.languages().isEmpty() || !descriptor.types().isEmpty()) {
FilePredicate langPredicate = descriptor.languages().isEmpty() ? fs.predicates().all() : fs.predicates().hasLanguages(descriptor.languages());
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java
index 7bb802e301c..f8b8aef6c70 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java
@@ -19,12 +19,13 @@
*/
package org.sonar.batch.scan2;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.analyzer.Analyzer;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
import java.util.Collection;
@@ -41,12 +42,12 @@ public class AnalyzersExecutor implements BatchComponent {
this.optimizer = optimizer;
}
- public void execute(AnalyzerContext context) {
- Collection<Analyzer> analyzers = selector.select(Analyzer.class, null, true, null);
+ public void execute(SensorContext context) {
+ Collection<Sensor> analyzers = selector.select(Sensor.class, null, true, null);
- for (Analyzer analyzer : analyzers) {
+ for (Sensor analyzer : analyzers) {
- DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor();
+ DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
analyzer.describe(descriptor);
if (!optimizer.shouldExecute(descriptor)) {
@@ -61,7 +62,7 @@ public class AnalyzersExecutor implements BatchComponent {
}
- private void executeSensor(AnalyzerContext context, Analyzer analyzer) {
+ private void executeSensor(SensorContext context, Sensor analyzer) {
analyzer.analyse(context);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java
index 7c495df931c..ea323742c0b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java
@@ -19,15 +19,16 @@
*/
package org.sonar.batch.scan2;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.analyzer.issue.AnalyzerIssue;
-import org.sonar.api.batch.analyzer.issue.AnalyzerIssueBuilder;
-import org.sonar.api.batch.analyzer.issue.internal.DefaultAnalyzerIssue;
-import org.sonar.api.batch.analyzer.issue.internal.DefaultAnalyzerIssueBuilder;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder;
-import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasure;
-import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.issue.Issue;
+import org.sonar.api.batch.sensor.issue.IssueBuilder;
+import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
+import org.sonar.api.batch.sensor.issue.internal.DefaultIssueBuilder;
+import org.sonar.api.batch.sensor.measure.Measure;
+import org.sonar.api.batch.sensor.measure.MeasureBuilder;
+import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
+import org.sonar.api.batch.sensor.measure.internal.DefaultMeasureBuilder;
+
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
@@ -35,12 +36,12 @@ import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.config.Settings;
import org.sonar.batch.issue.IssueFilters;
-import org.sonar.batch.scan.AnalyzerContextAdaptor;
+import org.sonar.batch.scan.SensorContextAdaptor;
import org.sonar.core.component.ComponentKeys;
import java.io.Serializable;
-public class DefaultAnalyzerContext implements AnalyzerContext {
+public class DefaultAnalyzerContext implements SensorContext {
private final AnalyzerMeasureCache measureCache;
private final AnalyzerIssueCache issueCache;
@@ -77,46 +78,46 @@ public class DefaultAnalyzerContext implements AnalyzerContext {
}
@Override
- public <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder() {
- return new DefaultAnalyzerMeasureBuilder<G>();
+ public <G extends Serializable> MeasureBuilder<G> measureBuilder() {
+ return new DefaultMeasureBuilder<G>();
}
@Override
- public AnalyzerMeasure getMeasure(String metricKey) {
+ public Measure getMeasure(String metricKey) {
return measureCache.byMetric(def.getKey(), def.getKey(), metricKey);
}
@Override
- public <G extends Serializable> AnalyzerMeasure<G> getMeasure(Metric<G> metric) {
- return (AnalyzerMeasure<G>) measureCache.byMetric(def.getKey(), def.getKey(), metric.key());
+ public <G extends Serializable> Measure<G> getMeasure(Metric<G> metric) {
+ return (Measure<G>) measureCache.byMetric(def.getKey(), def.getKey(), metric.key());
}
@Override
- public AnalyzerMeasure getMeasure(InputFile file, String metricKey) {
+ public Measure getMeasure(InputFile file, String metricKey) {
return measureCache.byMetric(def.getKey(), ComponentKeys.createEffectiveKey(def.getKey(), file), metricKey);
}
@Override
- public <G extends Serializable> AnalyzerMeasure<G> getMeasure(InputFile file, Metric<G> metric) {
- return (AnalyzerMeasure<G>) measureCache.byMetric(def.getKey(), ComponentKeys.createEffectiveKey(def.getKey(), file), metric.key());
+ public <G extends Serializable> Measure<G> getMeasure(InputFile file, Metric<G> metric) {
+ return (Measure<G>) measureCache.byMetric(def.getKey(), ComponentKeys.createEffectiveKey(def.getKey(), file), metric.key());
}
@Override
- public void addMeasure(AnalyzerMeasure<?> measure) {
+ public void addMeasure(Measure<?> measure) {
if (measure.inputFile() != null) {
- measureCache.put(def.getKey(), ComponentKeys.createEffectiveKey(def.getKey(), measure.inputFile()), (DefaultAnalyzerMeasure) measure);
+ measureCache.put(def.getKey(), ComponentKeys.createEffectiveKey(def.getKey(), measure.inputFile()), (DefaultMeasure) measure);
} else {
- measureCache.put(def.getKey(), def.getKey(), (DefaultAnalyzerMeasure) measure);
+ measureCache.put(def.getKey(), def.getKey(), (DefaultMeasure) measure);
}
}
@Override
- public AnalyzerIssueBuilder issueBuilder() {
- return new DefaultAnalyzerIssueBuilder();
+ public IssueBuilder issueBuilder() {
+ return new DefaultIssueBuilder();
}
@Override
- public boolean addIssue(AnalyzerIssue issue) {
+ public boolean addIssue(Issue issue) {
String resourceKey;
if (issue.inputFile() != null) {
resourceKey = ComponentKeys.createEffectiveKey(def.getKey(), issue.inputFile());
@@ -124,8 +125,8 @@ public class DefaultAnalyzerContext implements AnalyzerContext {
resourceKey = def.getKey();
}
// TODO Lot of things to do. See ModuleIssues::initAndAddIssue
- if (issueFilters.accept(AnalyzerContextAdaptor.toDefaultIssue(def.getKey(), resourceKey, issue), null)) {
- issueCache.put(def.getKey(), resourceKey, (DefaultAnalyzerIssue) issue);
+ if (issueFilters.accept(SensorContextAdaptor.toDefaultIssue(def.getKey(), resourceKey, issue), null)) {
+ issueCache.put(def.getKey(), resourceKey, (DefaultIssue) issue);
return true;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultFileLinesContext.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultFileLinesContext.java
index e8cb04faf3b..f3bd801717f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultFileLinesContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultFileLinesContext.java
@@ -19,12 +19,13 @@
*/
package org.sonar.batch.scan2;
+import org.sonar.api.batch.sensor.measure.Measure;
+import org.sonar.api.batch.sensor.measure.internal.DefaultMeasureBuilder;
+
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure;
-import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.measures.FileLinesContext;
@@ -118,7 +119,7 @@ public class DefaultFileLinesContext implements FileLinesContext {
Map<Integer, Object> lines = entry.getValue();
if (shouldSave(lines)) {
String data = KeyValueFormat.format(lines);
- measureCache.put(projectKey, ComponentKeys.createEffectiveKey(projectKey, inputFile), new DefaultAnalyzerMeasureBuilder<String>()
+ measureCache.put(projectKey, ComponentKeys.createEffectiveKey(projectKey, inputFile), new DefaultMeasureBuilder<String>()
.forMetric(metric)
.onFile(inputFile)
.withValue(data)
@@ -129,7 +130,7 @@ public class DefaultFileLinesContext implements FileLinesContext {
}
private Map loadData(String metricKey, Converter converter) {
- AnalyzerMeasure measure = measureCache.byMetric(projectKey, ComponentKeys.createEffectiveKey(projectKey, inputFile), metricKey);
+ Measure measure = measureCache.byMetric(projectKey, ComponentKeys.createEffectiveKey(projectKey, inputFile), metricKey);
if (measure == null) {
// no such measure
return ImmutableMap.of();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java
index 15e78df740c..0f96f195698 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java
@@ -19,8 +19,9 @@
*/
package org.sonar.batch.scan2;
+import org.sonar.api.batch.sensor.SensorContext;
+
import com.google.common.collect.Lists;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader;
import org.sonar.batch.phases.SensorsExecutor;
@@ -33,7 +34,7 @@ import java.util.Collection;
public final class ModuleScanExecutor {
private final AnalyzersExecutor analyzersExecutor;
- private final AnalyzerContext analyzerContext;
+ private final SensorContext analyzerContext;
private final FileSystemLogger fsLogger;
private final DefaultModuleFileSystem fs;
private final QProfileVerifier profileVerifier;
@@ -42,7 +43,7 @@ public final class ModuleScanExecutor {
private AnalysisPublisher analyzisPublisher;
public ModuleScanExecutor(AnalyzersExecutor analyzersExecutor,
- AnalyzerContext analyzerContext,
+ SensorContext analyzerContext,
FileSystemLogger fsLogger, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
IssueExclusionsLoader issueExclusionsLoader, AnalysisPublisher analyzisPublisher) {
this.analyzersExecutor = analyzersExecutor;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
index 796408efea0..b0c2e3076d6 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
@@ -22,8 +22,7 @@ package org.sonar.batch.bootstrap;
import org.junit.Test;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.Sensor;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
+import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.batch.scan2.AnalyzerOptimizer;
@@ -42,7 +41,7 @@ public class BatchExtensionDictionnaryTest {
for (BatchExtension extension : extensions) {
iocContainer.addSingleton(extension);
}
- return new BatchExtensionDictionnary(iocContainer, mock(AnalyzerContext.class), mock(AnalyzerOptimizer.class));
+ return new BatchExtensionDictionnary(iocContainer, mock(SensorContext.class), mock(AnalyzerOptimizer.class));
}
@Test
@@ -63,10 +62,12 @@ public class BatchExtensionDictionnaryTest {
class FakeSensor implements Sensor {
- public void analyse(Project project, SensorContext context) {
+ @Override
+ public void analyse(Project project, org.sonar.api.batch.SensorContext context) {
}
+ @Override
public boolean shouldExecuteOnProject(Project project) {
return true;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
index 26cc47ff793..90ff20508fe 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
@@ -19,13 +19,14 @@
*/
package org.sonar.batch.mediumtest.issues;
+import org.sonar.api.batch.sensor.issue.Issue;
+
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.analyzer.issue.AnalyzerIssue;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.batch.mediumtest.AnalyzerMediumTester;
import org.sonar.batch.mediumtest.AnalyzerMediumTester.TaskResult;
@@ -110,7 +111,7 @@ public class IssuesMediumTest {
assertThat(result.issues()).hasSize(20);
boolean foundIssueAtLine1 = false;
- for (AnalyzerIssue issue : result.issues()) {
+ for (Issue issue : result.issues()) {
if (issue.line() == 1) {
foundIssueAtLine1 = true;
assertThat(issue.inputFile()).isEqualTo(new DefaultInputFile("src/sample.xoo"));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
index 31064275b70..975999bd352 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
@@ -19,13 +19,14 @@
*/
package org.sonar.batch.mediumtest.measures;
+import org.sonar.api.batch.sensor.measure.internal.DefaultMeasureBuilder;
+
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.batch.mediumtest.AnalyzerMediumTester;
@@ -95,7 +96,7 @@ public class MeasuresMediumTest {
assertThat(result.measures()).hasSize(1);
- assertThat(result.measures()).contains(new DefaultAnalyzerMeasureBuilder<Integer>()
+ assertThat(result.measures()).contains(new DefaultMeasureBuilder<Integer>()
.forMetric(CoreMetrics.LINES)
.onFile(new DefaultInputFile("src/sample.xoo"))
.withValue(20)
@@ -138,13 +139,13 @@ public class MeasuresMediumTest {
assertThat(result.measures()).hasSize(4);
- assertThat(result.measures()).contains(new DefaultAnalyzerMeasureBuilder<Integer>()
+ assertThat(result.measures()).contains(new DefaultMeasureBuilder<Integer>()
.forMetric(CoreMetrics.LINES)
.onFile(new DefaultInputFile("src/sample.xoo"))
.withValue(5)
.build());
- assertThat(result.measures()).contains(new DefaultAnalyzerMeasureBuilder<String>()
+ assertThat(result.measures()).contains(new DefaultMeasureBuilder<String>()
.forMetric(CoreMetrics.SCM_AUTHORS_BY_LINE)
.onFile(new DefaultInputFile("src/sample.xoo"))
.withValue("1=julien;2=julien;3=julien;4=julien;5=simon")
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java
index ff113906138..00bfc6b5a41 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java
@@ -21,8 +21,8 @@ package org.sonar.batch.mediumtest.xoo.plugin;
import org.sonar.api.SonarPlugin;
import org.sonar.batch.mediumtest.xoo.plugin.base.Xoo;
-import org.sonar.batch.mediumtest.xoo.plugin.lang.MeasureAnalyzer;
-import org.sonar.batch.mediumtest.xoo.plugin.lang.ScmActivityAnalyzer;
+import org.sonar.batch.mediumtest.xoo.plugin.lang.MeasureSensor;
+import org.sonar.batch.mediumtest.xoo.plugin.lang.ScmActivitySensor;
import org.sonar.batch.mediumtest.xoo.plugin.rule.OneIssuePerLineAnalyzer;
import java.util.Arrays;
@@ -34,8 +34,8 @@ public final class XooPlugin extends SonarPlugin {
public List getExtensions() {
return Arrays.asList(
// language
- MeasureAnalyzer.class,
- ScmActivityAnalyzer.class,
+ MeasureSensor.class,
+ ScmActivitySensor.class,
Xoo.class,
// rules
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureAnalyzer.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureSensor.java
index 92d00406c48..2f56da1b7a8 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureAnalyzer.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureSensor.java
@@ -19,13 +19,14 @@
*/
package org.sonar.batch.mediumtest.xoo.plugin.lang;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.batch.sensor.measure.Measure;
+import org.sonar.api.batch.sensor.measure.MeasureBuilder;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.analyzer.Analyzer;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.analyzer.AnalyzerDescriptor;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.measures.CoreMetrics;
@@ -40,17 +41,17 @@ import java.util.List;
/**
* Parse files *.xoo.measures
*/
-public class MeasureAnalyzer implements Analyzer {
+public class MeasureSensor implements Sensor {
private static final String MEASURES_EXTENSION = ".measures";
private MetricFinder metricFinder;
- public MeasureAnalyzer(MetricFinder metricFinder) {
+ public MeasureSensor(MetricFinder metricFinder) {
this.metricFinder = metricFinder;
}
- private void processFileMeasures(InputFile inputFile, AnalyzerContext context) {
+ private void processFileMeasures(InputFile inputFile, SensorContext context) {
File ioFile = inputFile.file();
File measureFile = new File(ioFile.getParentFile(), ioFile.getName() + MEASURES_EXTENSION);
if (measureFile.exists()) {
@@ -80,9 +81,9 @@ public class MeasureAnalyzer implements Analyzer {
}
}
- private AnalyzerMeasure<?> createMeasure(AnalyzerContext context, InputFile xooFile, String metricKey, String value) {
+ private Measure<?> createMeasure(SensorContext context, InputFile xooFile, String metricKey, String value) {
org.sonar.api.batch.measure.Metric<Serializable> metric = metricFinder.findByKey(metricKey);
- AnalyzerMeasureBuilder<Serializable> builder = context.measureBuilder()
+ MeasureBuilder<Serializable> builder = context.measureBuilder()
.forMetric(metric)
.onFile(xooFile);
if (Boolean.class.equals(metric.valueType())) {
@@ -102,7 +103,7 @@ public class MeasureAnalyzer implements Analyzer {
}
@Override
- public void describe(AnalyzerDescriptor descriptor) {
+ public void describe(SensorDescriptor descriptor) {
descriptor
.name("Xoo Measure Analyzer")
.provides(CoreMetrics.LINES)
@@ -111,7 +112,7 @@ public class MeasureAnalyzer implements Analyzer {
}
@Override
- public void analyse(AnalyzerContext context) {
+ public void analyse(SensorContext context) {
for (InputFile file : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguages(Xoo.KEY))) {
processFileMeasures(file, context);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivityAnalyzer.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivitySensor.java
index 346036a52ff..ecf05f862a2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivityAnalyzer.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivitySensor.java
@@ -19,15 +19,16 @@
*/
package org.sonar.batch.mediumtest.xoo.plugin.lang;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.analyzer.Analyzer;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.analyzer.AnalyzerDescriptor;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.measures.CoreMetrics;
@@ -41,22 +42,22 @@ import java.io.IOException;
import java.util.Date;
import java.util.List;
-public class ScmActivityAnalyzer implements Analyzer {
+public class ScmActivitySensor implements Sensor {
- private static final Logger LOG = LoggerFactory.getLogger(ScmActivityAnalyzer.class);
+ private static final Logger LOG = LoggerFactory.getLogger(ScmActivitySensor.class);
private static final String SCM_EXTENSION = ".scm";
private final FileSystem fs;
private final FileLinesContextFactory fileLinesContextFactory;
- public ScmActivityAnalyzer(FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem) {
+ public ScmActivitySensor(FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem) {
this.fs = fileSystem;
this.fileLinesContextFactory = fileLinesContextFactory;
}
@Override
- public void describe(AnalyzerDescriptor descriptor) {
+ public void describe(SensorDescriptor descriptor) {
descriptor
.name(this.getClass().getSimpleName())
.provides(CoreMetrics.SCM_AUTHORS_BY_LINE,
@@ -66,7 +67,7 @@ public class ScmActivityAnalyzer implements Analyzer {
}
@Override
- public void analyse(AnalyzerContext context) {
+ public void analyse(SensorContext context) {
for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(Xoo.KEY))) {
processFile(inputFile);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java
index 522ad3b6b53..f55e7b7bb40 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java
@@ -19,24 +19,25 @@
*/
package org.sonar.batch.mediumtest.xoo.plugin.rule;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.batch.sensor.measure.Measure;
+
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.analyzer.Analyzer;
-import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.analyzer.AnalyzerDescriptor;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.rule.RuleKey;
import org.sonar.batch.mediumtest.xoo.plugin.base.Xoo;
import org.sonar.batch.mediumtest.xoo.plugin.base.XooConstants;
-public class OneIssuePerLineAnalyzer implements Analyzer {
+public class OneIssuePerLineAnalyzer implements Sensor {
public static final String RULE_KEY = "OneIssuePerLine";
private static final String EFFORT_TO_FIX_PROPERTY = "sonar.oneIssuePerLine.effortToFix";
@Override
- public void describe(AnalyzerDescriptor descriptor) {
+ public void describe(SensorDescriptor descriptor) {
descriptor
.name("One Issue Per Line")
.dependsOn(CoreMetrics.LINES)
@@ -45,15 +46,15 @@ public class OneIssuePerLineAnalyzer implements Analyzer {
}
@Override
- public void analyse(AnalyzerContext context) {
+ public void analyse(SensorContext context) {
for (InputFile file : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguages(Xoo.KEY))) {
createIssues(file, context);
}
}
- private void createIssues(InputFile file, AnalyzerContext context) {
+ private void createIssues(InputFile file, SensorContext context) {
RuleKey ruleKey = RuleKey.of(XooConstants.REPOSITORY_KEY, RULE_KEY);
- AnalyzerMeasure<Integer> linesMeasure = context.getMeasure(file, CoreMetrics.LINES);
+ Measure<Integer> linesMeasure = context.getMeasure(file, CoreMetrics.LINES);
if (linesMeasure == null) {
LoggerFactory.getLogger(getClass()).warn("Missing measure " + CoreMetrics.LINES_KEY + " on " + file);
} else {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/AnalyzerContextAdapterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/SensorContextAdapterTest.java
index f20f9304baa..b4a8fdab7f0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/AnalyzerContextAdapterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/SensorContextAdapterTest.java
@@ -25,20 +25,19 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.analyzer.issue.internal.DefaultAnalyzerIssueBuilder;
-import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure;
-import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
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.issue.internal.DefaultIssueBuilder;
+import org.sonar.api.batch.sensor.measure.Measure;
+import org.sonar.api.batch.sensor.measure.internal.DefaultMeasureBuilder;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.config.Settings;
import org.sonar.api.issue.Issuable;
import org.sonar.api.issue.Issue;
import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
@@ -49,14 +48,14 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class AnalyzerContextAdapterTest {
+public class SensorContextAdapterTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private ActiveRules activeRules;
private DefaultFileSystem fs;
- private AnalyzerContextAdaptor adaptor;
+ private SensorContextAdaptor adaptor;
private SensorContext sensorContext;
private Settings settings;
private ResourcePerspectives resourcePerspectives;
@@ -70,7 +69,7 @@ public class AnalyzerContextAdapterTest {
sensorContext = mock(SensorContext.class);
settings = new Settings();
resourcePerspectives = mock(ResourcePerspectives.class);
- adaptor = new AnalyzerContextAdaptor(sensorContext, metricFinder, new Project("myProject"),
+ adaptor = new SensorContextAdaptor(sensorContext, metricFinder, new Project("myProject"),
resourcePerspectives, settings, fs, activeRules);
}
@@ -86,10 +85,10 @@ public class AnalyzerContextAdapterTest {
@Test
public void shouldRedirectProjectMeasuresToSensorContext() {
- AnalyzerMeasure<Integer> measure = adaptor.getMeasure(CoreMetrics.NCLOC_KEY);
+ Measure<Integer> measure = adaptor.getMeasure(CoreMetrics.NCLOC_KEY);
assertThat(measure).isNull();
- when(sensorContext.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure<Integer>(CoreMetrics.NCLOC, 10.0));
+ when(sensorContext.getMeasure(CoreMetrics.NCLOC)).thenReturn(new org.sonar.api.measures.Measure<Integer>(CoreMetrics.NCLOC, 10.0));
measure = adaptor.getMeasure(CoreMetrics.NCLOC);
assertThat(measure.metric()).isEqualTo(CoreMetrics.NCLOC);
@@ -105,10 +104,10 @@ public class AnalyzerContextAdapterTest {
public void shouldRedirectFileMeasuresToSensorContext() {
InputFile file = new DefaultInputFile("src/Foo.php");
- AnalyzerMeasure<Integer> measure = adaptor.getMeasure(file, CoreMetrics.NCLOC_KEY);
+ Measure<Integer> measure = adaptor.getMeasure(file, CoreMetrics.NCLOC_KEY);
assertThat(measure).isNull();
- when(sensorContext.getMeasure(File.create("src/Foo.php"), CoreMetrics.NCLOC)).thenReturn(new Measure<Integer>(CoreMetrics.NCLOC, 10.0));
+ when(sensorContext.getMeasure(File.create("src/Foo.php"), CoreMetrics.NCLOC)).thenReturn(new org.sonar.api.measures.Measure<Integer>(CoreMetrics.NCLOC, 10.0));
measure = adaptor.getMeasure(file, CoreMetrics.NCLOC);
assertThat(measure.metric()).isEqualTo(CoreMetrics.NCLOC);
@@ -120,16 +119,16 @@ public class AnalyzerContextAdapterTest {
public void shouldAddMeasureToSensorContext() {
InputFile file = new DefaultInputFile("src/Foo.php");
- ArgumentCaptor<Measure> argumentCaptor = ArgumentCaptor.forClass(Measure.class);
+ ArgumentCaptor<org.sonar.api.measures.Measure> argumentCaptor = ArgumentCaptor.forClass(org.sonar.api.measures.Measure.class);
when(sensorContext.saveMeasure(eq(file), argumentCaptor.capture())).thenReturn(null);
- adaptor.addMeasure(new DefaultAnalyzerMeasureBuilder()
+ adaptor.addMeasure(new DefaultMeasureBuilder()
.onFile(file)
.forMetric(CoreMetrics.NCLOC)
.withValue(10)
.build());
- Measure m = argumentCaptor.getValue();
+ org.sonar.api.measures.Measure m = argumentCaptor.getValue();
assertThat(m.getValue()).isEqualTo(10.0);
assertThat(m.getMetric()).isEqualTo(CoreMetrics.NCLOC);
}
@@ -145,7 +144,7 @@ public class AnalyzerContextAdapterTest {
when(issuable.addIssue(argumentCaptor.capture())).thenReturn(true);
- adaptor.addIssue(new DefaultAnalyzerIssueBuilder()
+ adaptor.addIssue(new DefaultIssueBuilder()
.onFile(file)
.ruleKey(RuleKey.of("foo", "bar"))
.message("Foo")
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 8940c3dd2fc..6c21f0c1184 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
@@ -19,18 +19,18 @@
*/
package org.sonar.batch.scan2;
+import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
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.rule.RuleKey;
-
import static org.fest.assertions.Assertions.assertThat;
public class AnalyzerOptimizerTest {
@@ -48,14 +48,14 @@ public class AnalyzerOptimizerTest {
@Test
public void should_run_analyzer_with_no_metadata() throws Exception {
- DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor();
+ DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
@Test
public void should_optimize_on_language() throws Exception {
- DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor()
+ DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
.workOnLanguages("java", "php");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
@@ -65,7 +65,7 @@ public class AnalyzerOptimizerTest {
@Test
public void should_optimize_on_type() throws Exception {
- DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor()
+ DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
.workOnFileTypes(InputFile.Type.MAIN);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
@@ -78,7 +78,7 @@ public class AnalyzerOptimizerTest {
@Test
public void should_optimize_on_both_type_and_language() throws Exception {
- DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor()
+ DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
.workOnLanguages("java", "php")
.workOnFileTypes(InputFile.Type.MAIN);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
@@ -93,7 +93,7 @@ public class AnalyzerOptimizerTest {
@Test
public void should_optimize_on_repository() throws Exception {
- DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor()
+ DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
.createIssuesForRuleRepositories("squid");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();