diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-21 15:52:34 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-21 15:53:14 +0200 |
commit | 1b642da7883702abcc6f93b590cfe4cd3c271d4d (patch) | |
tree | ceb30d9cc8bf4c43bfd88fc4eb3d5571fd818050 | |
parent | c170323815e752c67977d68fb99cb27a95c61482 (diff) | |
download | sonarqube-1b642da7883702abcc6f93b590cfe4cd3c271d4d.tar.gz sonarqube-1b642da7883702abcc6f93b590cfe4cd3c271d4d.zip |
SONAR-5389 Rename Analyzer -> Sensor
48 files changed, 370 insertions, 349 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(); 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 556ea373b9c..ffd90b34de2 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 @@ -19,13 +19,14 @@ */ package org.sonar.api.batch; +import org.sonar.api.batch.sensor.Sensor; +import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; + import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import org.apache.commons.lang.ClassUtils; import org.sonar.api.BatchExtension; -import org.sonar.api.batch.analyzer.Analyzer; -import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor; import org.sonar.api.batch.maven.DependsUponMavenPlugin; import org.sonar.api.batch.maven.MavenPluginHandler; import org.sonar.api.platform.ComponentContainer; @@ -148,9 +149,9 @@ 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(), Analyzer.class)) { - DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor(); - ((Analyzer) extension).describe(descriptor); + if (ClassUtils.isAssignable(extension.getClass(), Sensor.class)) { + DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); + ((Sensor) extension).describe(descriptor); result.addAll(Arrays.asList(descriptor.dependsOn())); } return result; @@ -162,9 +163,9 @@ 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(), Analyzer.class)) { - DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor(); - ((Analyzer) extension).describe(descriptor); + 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.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Sensor.java index fc055e6da5c..7a82bc24015 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Sensor.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Sensor.java @@ -40,7 +40,9 @@ import org.sonar.api.resources.Project; * </p> * * @since 1.10 + * @deprecated since 4.5 use {@link org.sonar.api.batch.sensor.Sensor} */ +@Deprecated public interface Sensor extends BatchExtension, CheckProject { /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java index ccdec2dbf2f..2c8332ee0c5 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java @@ -38,6 +38,7 @@ import java.util.Set; /** * @since 1.10 + * @deprecated since 4.5 */ public interface SensorContext { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/package-info.java deleted file mode 100644 index a508e1eacb0..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.analyzer.measure.internal; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/Analyzer.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java index c551226895c..17a963e54c4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/Analyzer.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java @@ -17,7 +17,7 @@ * 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.batch.analyzer; +package org.sonar.api.batch.sensor; import com.google.common.annotations.Beta; import org.sonar.api.BatchExtension; @@ -35,16 +35,16 @@ import org.sonar.api.BatchExtension; * @since 4.4 */ @Beta -public interface Analyzer extends BatchExtension { +public interface Sensor extends BatchExtension { /** - * Populate {@link AnalyzerDescriptor} of this analyzer. + * Populate {@link SensorDescriptor} of this analyzer. */ - void describe(AnalyzerDescriptor descriptor); + void describe(SensorDescriptor descriptor); /** * The actual analyzer code. */ - void analyse(AnalyzerContext context); + void analyse(SensorContext context); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/AnalyzerContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index 244d0f93001..873fed63243 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/AnalyzerContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -17,13 +17,14 @@ * 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.batch.analyzer; +package org.sonar.api.batch.sensor; + +import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.batch.sensor.issue.IssueBuilder; +import org.sonar.api.batch.sensor.measure.Measure; +import org.sonar.api.batch.sensor.measure.MeasureBuilder; import com.google.common.annotations.Beta; -import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; -import org.sonar.api.batch.analyzer.issue.AnalyzerIssueBuilder; -import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; -import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; @@ -38,7 +39,7 @@ import java.io.Serializable; * @since 4.4 */ @Beta -public interface AnalyzerContext { +public interface SensorContext { /** * Get settings of the current project. @@ -58,50 +59,50 @@ public interface AnalyzerContext { // ----------- MEASURES -------------- /** - * Builder to create a new {@link AnalyzerMeasure}. + * Builder to create a new {@link Measure}. */ - <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder(); + <G extends Serializable> MeasureBuilder<G> measureBuilder(); /** * Find a project measure. */ @CheckForNull - AnalyzerMeasure getMeasure(String metricKey); + Measure getMeasure(String metricKey); /** * Find a project measure. */ @CheckForNull - <G extends Serializable> AnalyzerMeasure<G> getMeasure(Metric<G> metric); + <G extends Serializable> Measure<G> getMeasure(Metric<G> metric); /** * Find a file measure. */ @CheckForNull - AnalyzerMeasure getMeasure(InputFile file, String metricKey); + Measure getMeasure(InputFile file, String metricKey); /** * Find a file measure. */ @CheckForNull - <G extends Serializable> AnalyzerMeasure<G> getMeasure(InputFile file, Metric<G> metric); + <G extends Serializable> Measure<G> getMeasure(InputFile file, Metric<G> metric); /** * Add a measure. Use {@link #measureBuilder()} to create the new measure. */ - void addMeasure(AnalyzerMeasure<?> measure); + void addMeasure(Measure<?> measure); // ----------- ISSUES -------------- /** - * Builder to create a new {@link AnalyzerIssue}. + * Builder to create a new {@link Issue}. */ - AnalyzerIssueBuilder issueBuilder(); + IssueBuilder issueBuilder(); /** * Add an issue. Use {@link #issueBuilder()} to create the new issue. * @return true if the new issue is registered, false if the related rule does not exist or is disabled in the Quality profile. */ - boolean addIssue(AnalyzerIssue issue); + boolean addIssue(Issue issue); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/AnalyzerDescriptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java index 3e38e5da708..b25f00ef2ec 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/AnalyzerDescriptor.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java @@ -17,54 +17,54 @@ * 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.batch.analyzer; +package org.sonar.api.batch.sensor; import com.google.common.annotations.Beta; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; /** - * Describe what an {@link Analyzer} is doing. Information may be used by the platform + * Describe what an {@link Sensor} is doing. Information may be used by the platform * to log interesting information or perform some optimization. * @since 4.4 */ @Beta -public interface AnalyzerDescriptor { +public interface SensorDescriptor { /** - * Name of the {@link Analyzer}. Will be displayed in logs. + * Name of the {@link Sensor}. Will be displayed in logs. */ - AnalyzerDescriptor name(String name); + SensorDescriptor name(String name); /** - * List {@link Metric} this {@link Analyzer} depends on. Will be used to execute Analyzers in correct order. + * List {@link Metric} this {@link Sensor} depends on. Will be used to execute Analyzers in correct order. */ - AnalyzerDescriptor dependsOn(Metric<?>... metrics); + SensorDescriptor dependsOn(Metric<?>... metrics); /** - * List {@link Metric} this {@link Analyzer} provides. Will be used to execute Analyzers in correct order. + * List {@link Metric} this {@link Sensor} provides. Will be used to execute Analyzers in correct order. */ - AnalyzerDescriptor provides(Metric<?>... metrics); + SensorDescriptor provides(Metric<?>... metrics); /** - * List languages this {@link Analyzer} work on. May be used by the platform to skip execution of the {@link Analyzer} when + * 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. */ - AnalyzerDescriptor workOnLanguages(String... languageKeys); + SensorDescriptor workOnLanguages(String... languageKeys); /** - * List {@link InputFile.Type} this {@link Analyzer} work on. May be used by the platform to skip execution of the {@link Analyzer} when + * 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. */ - AnalyzerDescriptor workOnFileTypes(InputFile.Type... types); + SensorDescriptor workOnFileTypes(InputFile.Type... types); /** - * List {@link InputFile.Type} this {@link Analyzer} work on. May be used by the platform to skip execution of the {@link Analyzer} when + * 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. */ - AnalyzerDescriptor createIssuesForRuleRepositories(String... repositoryKeys); + SensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/internal/DefaultAnalyzerDescriptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java index 3f793c98a64..a371fc57fb8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/internal/DefaultAnalyzerDescriptor.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java @@ -17,16 +17,17 @@ * 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.batch.analyzer.internal; +package org.sonar.api.batch.sensor.internal; + +import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.api.batch.analyzer.AnalyzerDescriptor; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; import java.util.Arrays; import java.util.Collection; -public class DefaultAnalyzerDescriptor implements AnalyzerDescriptor { +public class DefaultSensorDescriptor implements SensorDescriptor { private String name; private Metric<?>[] dependsOn = new Metric<?>[0]; @@ -60,37 +61,37 @@ public class DefaultAnalyzerDescriptor implements AnalyzerDescriptor { } @Override - public DefaultAnalyzerDescriptor name(String name) { + public DefaultSensorDescriptor name(String name) { this.name = name; return this; } @Override - public DefaultAnalyzerDescriptor dependsOn(Metric<?>... metrics) { + public DefaultSensorDescriptor dependsOn(Metric<?>... metrics) { this.dependsOn = metrics; return this; } @Override - public DefaultAnalyzerDescriptor provides(Metric<?>... metrics) { + public DefaultSensorDescriptor provides(Metric<?>... metrics) { this.provides = metrics; return this; } @Override - public DefaultAnalyzerDescriptor workOnLanguages(String... languageKeys) { + public DefaultSensorDescriptor workOnLanguages(String... languageKeys) { this.languages = languageKeys; return this; } @Override - public DefaultAnalyzerDescriptor workOnFileTypes(InputFile.Type... types) { + public DefaultSensorDescriptor workOnFileTypes(InputFile.Type... types) { this.types = types; return this; } @Override - public DefaultAnalyzerDescriptor createIssuesForRuleRepositories(String... repositoryKeys) { + public DefaultSensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys) { this.ruleRepositories = repositoryKeys; return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/package-info.java index a72c5a175f1..9b5158a8767 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/package-info.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/package-info.java @@ -18,4 +18,4 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.analyzer.measure; +package org.sonar.api.batch.sensor.internal; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/AnalyzerIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java index 9a9ce1bcaee..713b86d6ba3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/AnalyzerIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java @@ -17,22 +17,23 @@ * 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.batch.analyzer.issue; +package org.sonar.api.batch.sensor.issue; + +import org.sonar.api.batch.sensor.Sensor; import com.google.common.annotations.Beta; -import org.sonar.api.batch.analyzer.Analyzer; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.rule.RuleKey; import javax.annotation.Nullable; /** - * Issue reported by an {@link Analyzer} + * Issue reported by an {@link Sensor} * * @since 4.4 */ @Beta -public interface AnalyzerIssue { +public interface Issue { /** * The {@link InputFile} this issue belongs to. Returns null if issue is global to the project. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/AnalyzerIssueBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueBuilder.java index 12969a5f574..6b962d6bdcf 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/AnalyzerIssueBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueBuilder.java @@ -17,7 +17,7 @@ * 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.batch.analyzer.issue; +package org.sonar.api.batch.sensor.issue; import com.google.common.annotations.Beta; import org.sonar.api.batch.fs.InputFile; @@ -26,46 +26,46 @@ import org.sonar.api.rule.RuleKey; import javax.annotation.Nullable; /** - * Builder for {@link AnalyzerIssue}. + * Builder for {@link Issue}. * * @since 4.4 */ @Beta -public interface AnalyzerIssueBuilder { +public interface IssueBuilder { /** * The {@link RuleKey} of the issue. */ - AnalyzerIssueBuilder ruleKey(RuleKey ruleKey); + IssueBuilder ruleKey(RuleKey ruleKey); /** * The {@link InputFile} the issue belongs to. For global issues call {@link #onProject()}. */ - AnalyzerIssueBuilder onFile(InputFile file); + IssueBuilder onFile(InputFile file); /** * Tell that the issue is global to the project. */ - AnalyzerIssueBuilder onProject(); + IssueBuilder onProject(); /** * Line of the issue. If no line is specified then issue is supposed to be global to the file. */ - AnalyzerIssueBuilder atLine(int line); + IssueBuilder atLine(int line); /** * Effort to fix the issue. */ - AnalyzerIssueBuilder effortToFix(@Nullable Double effortToFix); + IssueBuilder effortToFix(@Nullable Double effortToFix); /** * Message of the issue. */ - AnalyzerIssueBuilder message(String message); + IssueBuilder message(String message); /** * Build the issue. */ - AnalyzerIssue build(); + Issue build(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java index ba75d12fca7..d20d5c7700e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java @@ -17,13 +17,14 @@ * 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.batch.analyzer.issue.internal; +package org.sonar.api.batch.sensor.issue.internal; + +import org.sonar.api.batch.sensor.issue.Issue; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.rule.RuleKey; @@ -32,7 +33,7 @@ import javax.annotation.Nullable; import java.io.Serializable; import java.util.UUID; -public class DefaultAnalyzerIssue implements AnalyzerIssue, Serializable { +public class DefaultIssue implements Issue, Serializable { private final String key; private final InputFile inputFile; @@ -41,7 +42,7 @@ public class DefaultAnalyzerIssue implements AnalyzerIssue, Serializable { private final Integer line; private final Double effortToFix; - DefaultAnalyzerIssue(DefaultAnalyzerIssueBuilder builder) { + DefaultIssue(DefaultIssueBuilder builder) { Preconditions.checkNotNull(builder.ruleKey, "ruleKey is mandatory on issue"); this.inputFile = builder.file; this.ruleKey = builder.ruleKey; @@ -91,7 +92,7 @@ public class DefaultAnalyzerIssue implements AnalyzerIssue, Serializable { if (o == null || getClass() != o.getClass()) { return false; } - DefaultAnalyzerIssue that = (DefaultAnalyzerIssue) o; + DefaultIssue that = (DefaultIssue) o; return !key.equals(that.key); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssueBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueBuilder.java index 42a6b970380..8d8249d3058 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssueBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueBuilder.java @@ -17,17 +17,18 @@ * 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.batch.analyzer.issue.internal; +package org.sonar.api.batch.sensor.issue.internal; + +import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.batch.sensor.issue.IssueBuilder; import com.google.common.base.Preconditions; -import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; -import org.sonar.api.batch.analyzer.issue.AnalyzerIssueBuilder; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.rule.RuleKey; import javax.annotation.Nullable; -public class DefaultAnalyzerIssueBuilder implements AnalyzerIssueBuilder { +public class DefaultIssueBuilder implements IssueBuilder { String key; Boolean onProject = null; @@ -38,13 +39,13 @@ public class DefaultAnalyzerIssueBuilder implements AnalyzerIssueBuilder { Double effortToFix; @Override - public DefaultAnalyzerIssueBuilder ruleKey(RuleKey ruleKey) { + public DefaultIssueBuilder ruleKey(RuleKey ruleKey) { this.ruleKey = ruleKey; return this; } @Override - public DefaultAnalyzerIssueBuilder onFile(InputFile file) { + public DefaultIssueBuilder onFile(InputFile file) { onProject(false); Preconditions.checkNotNull(file, "InputFile should be non null"); this.file = file; @@ -52,7 +53,7 @@ public class DefaultAnalyzerIssueBuilder implements AnalyzerIssueBuilder { } @Override - public DefaultAnalyzerIssueBuilder onProject() { + public DefaultIssueBuilder onProject() { onProject(true); this.file = null; return this; @@ -64,19 +65,19 @@ public class DefaultAnalyzerIssueBuilder implements AnalyzerIssueBuilder { } @Override - public DefaultAnalyzerIssueBuilder atLine(int line) { + public DefaultIssueBuilder atLine(int line) { this.line = line; return this; } @Override - public DefaultAnalyzerIssueBuilder effortToFix(@Nullable Double effortToFix) { + public DefaultIssueBuilder effortToFix(@Nullable Double effortToFix) { this.effortToFix = effortToFix; return this; } @Override - public DefaultAnalyzerIssueBuilder message(String message) { + public DefaultIssueBuilder message(String message) { this.message = message; return this; } @@ -84,14 +85,14 @@ public class DefaultAnalyzerIssueBuilder implements AnalyzerIssueBuilder { /** * For testing only. */ - public DefaultAnalyzerIssueBuilder withKey(String key) { + public DefaultIssueBuilder withKey(String key) { this.key = key; return this; } @Override - public AnalyzerIssue build() { - return new DefaultAnalyzerIssue(this); + public Issue build() { + return new DefaultIssue(this); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/package-info.java new file mode 100644 index 00000000000..85fd63f9fff --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/package-info.java @@ -0,0 +1,21 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.api.batch.sensor.issue.internal; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/package-info.java index 7ccdcaf5e21..6cc03c47d89 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/package-info.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/package-info.java @@ -18,4 +18,4 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.analyzer.issue; +package org.sonar.api.batch.sensor.issue; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/AnalyzerMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/Measure.java index 4c33ff1e391..ea606d45bd8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/AnalyzerMeasure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/Measure.java @@ -17,10 +17,11 @@ * 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.batch.analyzer.measure; +package org.sonar.api.batch.sensor.measure; + +import org.sonar.api.batch.sensor.Sensor; import com.google.common.annotations.Beta; -import org.sonar.api.batch.analyzer.Analyzer; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; @@ -29,11 +30,11 @@ import javax.annotation.Nullable; import java.io.Serializable; /** - * A measure computed by an {@link Analyzer}. + * A measure computed by an {@link Sensor}. * @since 4.4 */ @Beta -public interface AnalyzerMeasure<G extends Serializable> { +public interface Measure<G extends Serializable> { /** * The {@link InputFile} this measure belongs to. Returns null if measure is global to the project. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/AnalyzerMeasureBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/MeasureBuilder.java index b837f85ab85..05b16bee932 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/AnalyzerMeasureBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/MeasureBuilder.java @@ -17,7 +17,7 @@ * 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.batch.analyzer.measure; +package org.sonar.api.batch.sensor.measure; import org.sonar.api.batch.measure.Metric; @@ -27,34 +27,34 @@ import org.sonar.api.batch.fs.InputFile; import java.io.Serializable; /** - * Builder to create new {@link AnalyzerMeasure} + * Builder to create new {@link Measure} * @since 4.4 */ @Beta -public interface AnalyzerMeasureBuilder<G extends Serializable> { +public interface MeasureBuilder<G extends Serializable> { /** * The file the measure belongs to. */ - AnalyzerMeasureBuilder<G> onFile(InputFile file); + MeasureBuilder<G> onFile(InputFile file); /** * Tell that the measure is global to the project. */ - AnalyzerMeasureBuilder<G> onProject(); + MeasureBuilder<G> onProject(); /** * The metric this measure belong to. */ - AnalyzerMeasureBuilder<G> forMetric(Metric<G> metric); + MeasureBuilder<G> forMetric(Metric<G> metric); /** * Value of the measure. */ - AnalyzerMeasureBuilder<G> withValue(G value); + MeasureBuilder<G> withValue(G value); /** * Build the measure. */ - AnalyzerMeasure<G> build(); + Measure<G> build(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java index 1e0f6964168..6664a055b8a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java @@ -17,14 +17,15 @@ * 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.batch.analyzer.measure.internal; +package org.sonar.api.batch.sensor.measure.internal; + +import org.sonar.api.batch.sensor.measure.Measure; import com.google.common.base.Preconditions; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; @@ -32,13 +33,13 @@ import javax.annotation.Nullable; import java.io.Serializable; -public class DefaultAnalyzerMeasure<G extends Serializable> implements AnalyzerMeasure<G>, Serializable { +public class DefaultMeasure<G extends Serializable> implements Measure<G>, Serializable { private final InputFile inputFile; private final Metric<G> metric; private final G value; - DefaultAnalyzerMeasure(DefaultAnalyzerMeasureBuilder<G> builder) { + DefaultMeasure(DefaultMeasureBuilder<G> builder) { Preconditions.checkNotNull(builder.value, "Measure value can't be null"); Preconditions.checkNotNull(builder.metric, "Measure metric can't be null"); Preconditions.checkState(builder.metric.valueType().equals(builder.value.getClass()), "Measure value should be of type " + builder.metric.valueType()); @@ -74,7 +75,7 @@ public class DefaultAnalyzerMeasure<G extends Serializable> implements AnalyzerM if (obj.getClass() != getClass()) { return false; } - DefaultAnalyzerMeasure rhs = (DefaultAnalyzerMeasure) obj; + DefaultMeasure rhs = (DefaultMeasure) obj; return new EqualsBuilder() .append(inputFile, rhs.inputFile) .append(metric, rhs.metric) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasureBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureBuilder.java index 76de69c6ce4..a1ef2e508d9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasureBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureBuilder.java @@ -17,16 +17,17 @@ * 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.batch.analyzer.measure.internal; +package org.sonar.api.batch.sensor.measure.internal; + +import org.sonar.api.batch.sensor.measure.MeasureBuilder; import com.google.common.base.Preconditions; -import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; import java.io.Serializable; -public class DefaultAnalyzerMeasureBuilder<G extends Serializable> implements AnalyzerMeasureBuilder<G> { +public class DefaultMeasureBuilder<G extends Serializable> implements MeasureBuilder<G> { Boolean onProject = null; InputFile file; @@ -34,7 +35,7 @@ public class DefaultAnalyzerMeasureBuilder<G extends Serializable> implements An G value; @Override - public DefaultAnalyzerMeasureBuilder<G> onFile(InputFile inputFile) { + public DefaultMeasureBuilder<G> onFile(InputFile inputFile) { onProject(false); Preconditions.checkNotNull(inputFile, "inputFile should be non null"); this.file = inputFile; @@ -42,7 +43,7 @@ public class DefaultAnalyzerMeasureBuilder<G extends Serializable> implements An } @Override - public DefaultAnalyzerMeasureBuilder<G> onProject() { + public DefaultMeasureBuilder<G> onProject() { onProject(true); this.file = null; return this; @@ -54,7 +55,7 @@ public class DefaultAnalyzerMeasureBuilder<G extends Serializable> implements An } @Override - public DefaultAnalyzerMeasureBuilder<G> forMetric(Metric<G> metric) { + public DefaultMeasureBuilder<G> forMetric(Metric<G> metric) { Preconditions.checkState(metric != null, "Metric already defined"); Preconditions.checkNotNull(metric, "metric should be non null"); this.metric = metric; @@ -62,7 +63,7 @@ public class DefaultAnalyzerMeasureBuilder<G extends Serializable> implements An } @Override - public DefaultAnalyzerMeasureBuilder<G> withValue(G value) { + public DefaultMeasureBuilder<G> withValue(G value) { Preconditions.checkState(this.value == null, "Measure value already defined"); Preconditions.checkNotNull(value, "Measure value can't be null"); this.value = value; @@ -70,7 +71,7 @@ public class DefaultAnalyzerMeasureBuilder<G extends Serializable> implements An } @Override - public DefaultAnalyzerMeasure<G> build() { - return new DefaultAnalyzerMeasure<G>(this); + public DefaultMeasure<G> build() { + return new DefaultMeasure<G>(this); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/package-info.java index 4034ce7fdfa..414484da3ca 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/package-info.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/package-info.java @@ -18,4 +18,4 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.analyzer.issue.internal; +package org.sonar.api.batch.sensor.measure.internal; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/package-info.java index b61bc2267b8..92eba8a28f1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/internal/package-info.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/package-info.java @@ -18,4 +18,4 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.analyzer.internal; +package org.sonar.api.batch.sensor.measure; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/package-info.java index 4ae26db9bf1..0b6b56aa15f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/package-info.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/package-info.java @@ -18,4 +18,4 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.analyzer; +package org.sonar.api.batch.sensor; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/internal/DefaultAnalyzerDescriptorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java index b55bae7bf75..fc91edc8ce1 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/internal/DefaultAnalyzerDescriptorTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java @@ -17,19 +17,20 @@ * 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.batch.analyzer.internal; +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.fest.assertions.Assertions.assertThat; -public class DefaultAnalyzerDescriptorTest { +public class DefaultSensorDescriptorTest { @Test public void describe() { - DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor(); + DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); descriptor .name("Foo") .dependsOn(CoreMetrics.NCLOC) diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java index 1ec42281afc..25454a8f251 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssueTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java @@ -17,25 +17,26 @@ * 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.batch.analyzer.issue.internal; +package org.sonar.api.batch.sensor.issue.internal; + +import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.batch.sensor.issue.internal.DefaultIssueBuilder; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.rule.RuleKey; - import static org.fest.assertions.Assertions.assertThat; -public class DefaultAnalyzerIssueTest { +public class DefaultIssueTest { @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void build_file_issue() { - AnalyzerIssue issue = new DefaultAnalyzerIssueBuilder() + Issue issue = new DefaultIssueBuilder() .onFile(new DefaultInputFile("src/Foo.php")) .ruleKey(RuleKey.of("repo", "rule")) .atLine(1) @@ -52,7 +53,7 @@ public class DefaultAnalyzerIssueTest { @Test public void build_project_issue() { - AnalyzerIssue issue = new DefaultAnalyzerIssueBuilder() + Issue issue = new DefaultIssueBuilder() .onProject() .ruleKey(RuleKey.of("repo", "rule")) .atLine(1) @@ -71,7 +72,7 @@ public class DefaultAnalyzerIssueTest { public void not_allowed_to_call_onFile_and_onProject() { thrown.expect(IllegalStateException.class); thrown.expectMessage("onFile or onProject can be called only once"); - new DefaultAnalyzerIssueBuilder() + new DefaultIssueBuilder() .onProject() .onFile(new DefaultInputFile("src/Foo.php")) .ruleKey(RuleKey.of("repo", "rule")) diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasureTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java index 1e27f766ae3..c75a31679b2 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasureTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java @@ -17,25 +17,26 @@ * 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.batch.analyzer.measure.internal; +package org.sonar.api.batch.sensor.measure.internal; + +import org.sonar.api.batch.sensor.measure.Measure; +import org.sonar.api.batch.sensor.measure.internal.DefaultMeasureBuilder; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.measures.CoreMetrics; - import static org.fest.assertions.Assertions.assertThat; -public class DefaultAnalyzerMeasureTest { +public class DefaultMeasureTest { @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void build_file_measure() { - AnalyzerMeasure<Integer> issue = new DefaultAnalyzerMeasureBuilder<Integer>() + Measure<Integer> issue = new DefaultMeasureBuilder<Integer>() .forMetric(CoreMetrics.LINES) .onFile(new DefaultInputFile("src/Foo.php")) .withValue(3) @@ -48,7 +49,7 @@ public class DefaultAnalyzerMeasureTest { @Test public void build_project_measure() { - AnalyzerMeasure<Integer> issue = new DefaultAnalyzerMeasureBuilder<Integer>() + Measure<Integer> issue = new DefaultMeasureBuilder<Integer>() .forMetric(CoreMetrics.LINES) .onProject() .withValue(3) @@ -63,7 +64,7 @@ public class DefaultAnalyzerMeasureTest { public void not_allowed_to_call_onFile_and_onProject() { thrown.expect(IllegalStateException.class); thrown.expectMessage("onFile or onProject can be called only once"); - new DefaultAnalyzerMeasureBuilder<Integer>() + new DefaultMeasureBuilder<Integer>() .onProject() .onFile(new DefaultInputFile("src/Foo.php")) .withValue(3) |