]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5389 Rename Analyzer -> Sensor
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 21 Jul 2014 13:52:34 +0000 (15:52 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 21 Jul 2014 13:53:14 +0000 (15:53 +0200)
72 files changed:
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java
sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java
sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
sonar-batch/src/main/java/org/sonar/batch/scan/SensorContextAdaptor.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java
sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java
sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerIssueCache.java
sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerMeasureCache.java
sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java
sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java
sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java
sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultFileLinesContext.java
sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureAnalyzer.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureSensor.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivityAnalyzer.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivitySensor.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java
sonar-batch/src/test/java/org/sonar/batch/scan/AnalyzerContextAdapterTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/scan/SensorContextAdapterTest.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java
sonar-deprecated/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/Sensor.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/Analyzer.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/AnalyzerContext.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/AnalyzerDescriptor.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/internal/DefaultAnalyzerDescriptor.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/internal/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/AnalyzerIssue.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/AnalyzerIssueBuilder.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssue.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssueBuilder.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/internal/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/issue/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/AnalyzerMeasure.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/AnalyzerMeasureBuilder.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasure.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasureBuilder.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/internal/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueBuilder.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueBuilder.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/Measure.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/MeasureBuilder.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureBuilder.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/internal/DefaultAnalyzerDescriptorTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/issue/internal/DefaultAnalyzerIssueTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/analyzer/measure/internal/DefaultAnalyzerMeasureTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java [new file with mode: 0644]

index 0ec11fc59734fe3ad00cf3102c6a875521a6879b..fdbdc536eaf7735e31387a65b021a280a9a812aa 100644 (file)
@@ -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);
index f20917fe97141d0a987c8a227d65df6adc2ca282..9a96da2b2aaaee46d48cdd6b2916654614086576 100644 (file)
  */
 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;
     }
 
index 169683b42354c5e42f26fa883266b3ef28974407..37fde7a3495bec56b05bbe9f6716d1c9e3d7e6b6 100644 (file)
@@ -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/AnalyzerContextAdaptor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
deleted file mode 100644 (file)
index 8b883db..0000000
+++ /dev/null
@@ -1,231 +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.
- */
-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.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;
-import org.sonar.api.resources.File;
-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.
- *
- */
-public class AnalyzerContextAdaptor implements AnalyzerContext {
-
-  private SensorContext sensorContext;
-  private MetricFinder metricFinder;
-  private Project project;
-  private ResourcePerspectives perspectives;
-  private Settings settings;
-  private FileSystem fs;
-  private ActiveRules activeRules;
-
-  public AnalyzerContextAdaptor(SensorContext sensorContext, MetricFinder metricFinder, Project project, ResourcePerspectives perspectives,
-    Settings settings, FileSystem fs, ActiveRules activeRules) {
-    this.sensorContext = sensorContext;
-    this.metricFinder = metricFinder;
-    this.project = project;
-    this.perspectives = perspectives;
-    this.settings = settings;
-    this.fs = fs;
-    this.activeRules = activeRules;
-  }
-
-  @Override
-  public Settings settings() {
-    return settings;
-  }
-
-  @Override
-  public FileSystem fileSystem() {
-    return fs;
-  }
-
-  @Override
-  public ActiveRules activeRules() {
-    return activeRules;
-  }
-
-  @Override
-  public <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder() {
-    return new DefaultAnalyzerMeasureBuilder<G>();
-  }
-
-  @Override
-  public AnalyzerMeasure getMeasure(String metricKey) {
-    Metric<?> m = findMetricOrFail(metricKey);
-    return getMeasure(m);
-  }
-
-  @Override
-  public <G extends Serializable> AnalyzerMeasure<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);
-    if (measure == null) {
-      return null;
-    }
-    return this.<G>measureBuilder()
-      .onProject()
-      .forMetric(metric)
-      .withValue(measure.value())
-      .build();
-  }
-
-  @Override
-  public AnalyzerMeasure getMeasure(InputFile file, String metricKey) {
-    Metric<?> m = findMetricOrFail(metricKey);
-    return getMeasure(file, m);
-  }
-
-  private Metric<?> findMetricOrFail(String metricKey) {
-    Metric<?> m = metricFinder.findByKey(metricKey);
-    if (m == null) {
-      throw new IllegalStateException("Unknow metric with key: " + metricKey);
-    }
-    return m;
-  }
-
-  @Override
-  public <G extends Serializable> AnalyzerMeasure<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);
-    if (measure == null) {
-      return null;
-    }
-    return this.<G>measureBuilder()
-      .onFile(file)
-      .forMetric(metric)
-      .withValue(measure.value())
-      .build();
-  }
-
-  @Override
-  public void addMeasure(AnalyzerMeasure<?> 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);
-    setValueAccordingToMetricType(measure, m, measureToSave);
-    if (measure.inputFile() != null) {
-      Formula formula = measure.metric() instanceof org.sonar.api.measures.Metric ?
-        ((org.sonar.api.measures.Metric) measure.metric()).getFormula() : null;
-      if (formula instanceof SumChildDistributionFormula
-        && !Scopes.isHigherThanOrEquals(Scopes.FILE, ((SumChildDistributionFormula) formula).getMinimumScopeToPersist())) {
-        measureToSave.setPersistenceMode(PersistenceMode.MEMORY);
-      }
-      sensorContext.saveMeasure(measure.inputFile(), measureToSave);
-    } else {
-      sensorContext.saveMeasure(measureToSave);
-    }
-  }
-
-  private void setValueAccordingToMetricType(AnalyzerMeasure<?> measure, org.sonar.api.measures.Metric<?> m, Measure measureToSave) {
-    switch (m.getType()) {
-      case BOOL:
-        measureToSave.setValue(Boolean.TRUE.equals(measure.value()) ? 1.0 : 0.0);
-        break;
-      case INT:
-      case MILLISEC:
-        measureToSave.setValue(Double.valueOf((Integer) measure.value()));
-        break;
-      case FLOAT:
-      case PERCENT:
-      case RATING:
-        measureToSave.setValue((Double) measure.value());
-        break;
-      case STRING:
-      case LEVEL:
-      case DATA:
-      case DISTRIB:
-        measureToSave.setData((String) measure.value());
-        break;
-      case WORK_DUR:
-        measureToSave.setValue(Double.valueOf((Long) measure.value()));
-        break;
-      default:
-        if (m.isNumericType()) {
-          measureToSave.setValue((Double) measure.value());
-        } else if (m.isDataType()) {
-          measureToSave.setData((String) measure.value());
-        } else {
-          throw new UnsupportedOperationException("Unsupported type :" + m.getType());
-        }
-    }
-  }
-
-  @Override
-  public AnalyzerIssueBuilder issueBuilder() {
-    return new DefaultAnalyzerIssueBuilder();
-  }
-
-  @Override
-  public boolean addIssue(AnalyzerIssue issue) {
-    Resource r;
-    InputFile inputFile = issue.inputFile();
-    if (inputFile != null) {
-      r = File.create(inputFile.relativePath());
-    } else {
-      r = project;
-    }
-    Issuable issuable = perspectives.as(Issuable.class, r);
-    return issuable.addIssue(toDefaultIssue(project.getKey(), r.getKey(), issue));
-  }
-
-  public static DefaultIssue toDefaultIssue(String projectKey, String componentKey, AnalyzerIssue issue) {
-    return new DefaultIssueBuilder()
-      .componentKey(componentKey)
-      .projectKey(projectKey)
-      .ruleKey(RuleKey.of(issue.ruleKey().repository(), issue.ruleKey().rule()))
-      .effortToFix(issue.effortToFix())
-      .line(issue.line())
-      .message(issue.message())
-      .build();
-  }
-
-}
index 455567e5e680326de6c5fa212e7fdf510792acc0..733a8237dd8e5db65861dcec7d007d75a996644d 100644 (file)
@@ -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/SensorContextAdaptor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorContextAdaptor.java
new file mode 100644 (file)
index 0000000..4798b49
--- /dev/null
@@ -0,0 +1,228 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.scan;
+
+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.MetricFinder;
+import org.sonar.api.measures.PersistenceMode;
+import org.sonar.api.measures.SumChildDistributionFormula;
+import org.sonar.api.resources.File;
+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 java.io.Serializable;
+
+/**
+ * Implements {@link SensorContext} but forward everything to {@link org.sonar.api.batch.SensorContext} for backward compatibility.
+ *
+ */
+public class SensorContextAdaptor implements SensorContext {
+
+  private org.sonar.api.batch.SensorContext sensorContext;
+  private MetricFinder metricFinder;
+  private Project project;
+  private ResourcePerspectives perspectives;
+  private Settings settings;
+  private FileSystem fs;
+  private ActiveRules activeRules;
+
+  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;
+    this.project = project;
+    this.perspectives = perspectives;
+    this.settings = settings;
+    this.fs = fs;
+    this.activeRules = activeRules;
+  }
+
+  @Override
+  public Settings settings() {
+    return settings;
+  }
+
+  @Override
+  public FileSystem fileSystem() {
+    return fs;
+  }
+
+  @Override
+  public ActiveRules activeRules() {
+    return activeRules;
+  }
+
+  @Override
+  public <G extends Serializable> MeasureBuilder<G> measureBuilder() {
+    return new DefaultMeasureBuilder<G>();
+  }
+
+  @Override
+  public Measure getMeasure(String metricKey) {
+    Metric<?> m = findMetricOrFail(metricKey);
+    return getMeasure(m);
+  }
+
+  @Override
+  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());
+    org.sonar.api.measures.Measure<G> measure = sensorContext.getMeasure(m);
+    if (measure == null) {
+      return null;
+    }
+    return this.<G>measureBuilder()
+      .onProject()
+      .forMetric(metric)
+      .withValue(measure.value())
+      .build();
+  }
+
+  @Override
+  public Measure getMeasure(InputFile file, String metricKey) {
+    Metric<?> m = findMetricOrFail(metricKey);
+    return getMeasure(file, m);
+  }
+
+  private Metric<?> findMetricOrFail(String metricKey) {
+    Metric<?> m = metricFinder.findByKey(metricKey);
+    if (m == null) {
+      throw new IllegalStateException("Unknow metric with key: " + metricKey);
+    }
+    return m;
+  }
+
+  @Override
+  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());
+    org.sonar.api.measures.Measure<G> measure = sensorContext.getMeasure(fileRes, m);
+    if (measure == null) {
+      return null;
+    }
+    return this.<G>measureBuilder()
+      .onFile(file)
+      .forMetric(metric)
+      .withValue(measure.value())
+      .build();
+  }
+
+  @Override
+  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());
+    }
+
+    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 ?
+        ((org.sonar.api.measures.Metric) measure.metric()).getFormula() : null;
+      if (formula instanceof SumChildDistributionFormula
+        && !Scopes.isHigherThanOrEquals(Scopes.FILE, ((SumChildDistributionFormula) formula).getMinimumScopeToPersist())) {
+        measureToSave.setPersistenceMode(PersistenceMode.MEMORY);
+      }
+      sensorContext.saveMeasure(measure.inputFile(), measureToSave);
+    } else {
+      sensorContext.saveMeasure(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);
+        break;
+      case INT:
+      case MILLISEC:
+        measureToSave.setValue(Double.valueOf((Integer) measure.value()));
+        break;
+      case FLOAT:
+      case PERCENT:
+      case RATING:
+        measureToSave.setValue((Double) measure.value());
+        break;
+      case STRING:
+      case LEVEL:
+      case DATA:
+      case DISTRIB:
+        measureToSave.setData((String) measure.value());
+        break;
+      case WORK_DUR:
+        measureToSave.setValue(Double.valueOf((Long) measure.value()));
+        break;
+      default:
+        if (m.isNumericType()) {
+          measureToSave.setValue((Double) measure.value());
+        } else if (m.isDataType()) {
+          measureToSave.setData((String) measure.value());
+        } else {
+          throw new UnsupportedOperationException("Unsupported type :" + m.getType());
+        }
+    }
+  }
+
+  @Override
+  public IssueBuilder issueBuilder() {
+    return new DefaultIssueBuilder();
+  }
+
+  @Override
+  public boolean addIssue(Issue issue) {
+    Resource r;
+    InputFile inputFile = issue.inputFile();
+    if (inputFile != null) {
+      r = File.create(inputFile.relativePath());
+    } else {
+      r = project;
+    }
+    Issuable issuable = perspectives.as(Issuable.class, r);
+    return issuable.addIssue(toDefaultIssue(project.getKey(), r.getKey(), issue));
+  }
+
+  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()))
+      .effortToFix(issue.effortToFix())
+      .line(issue.line())
+      .message(issue.message())
+      .build();
+  }
+
+}
index 5489b9da52848f1218d9d68a2aacd602c403cc38..617ade05f3fb40dde947a98b8e574289210dcea2 100644 (file)
@@ -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);
   }
 }
index c422da9a3c3ef4c4c03b059eca8e655dd96a85ca..cfd03f82e59bad0c996b39957bcd1b3e4742ebc4 100644 (file)
  */
 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) {
index 4adc383a00dd922b1a5c8f83eb3b3949c169c7ca..9b0fd3f6d60d6d690ccfca65647847d4f1ae10cd 100644 (file)
@@ -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);
   }
 
index 030ff3e6ccc4e8e3460299dd659ebbad8caa9299..75d0e31932cb824ea7a3f14c17b6a83a12e5e59c 100644 (file)
  */
 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();
   }
 
index 0e8753607430ff3215aed76d80186636cb2bb75e..fb461854c69c9a769a81021c834faf1ececdc035 100644 (file)
@@ -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());
 
index 7bb802e301c333ca0131b85880ddb1b29ab1f6be..f8b8aef6c70ad53e55c363082bb454ccfcd01a76 100644 (file)
  */
 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);
   }
 
index 7c495df931c7d8fe401a667e09c8740994d6bf95..ea323742c0b0561622ace181897f63bc965b95d3 100644 (file)
  */
 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;
     }
 
index e8cb04faf3bd40aea3f0fede8a4eb2bba896a37d..f3bd801717f7f51d2e4f03b32d43fb04b0e04a49 100644 (file)
  */
 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();
index 15e78df740c16a0bbbb382e0e9d43c1bf594ee62..0f96f195698e562c1bc798690132ce375b66c219 100644 (file)
@@ -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;
index 796408efea0aa677a3acc0a3650137101f2f08a6..b0c2e3076d649178d99ec5cdbb25d7958a9945eb 100644 (file)
@@ -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;
     }
index 26cc47ff793b9d823277d881fcb5b302aac8ad41..90ff20508fe14afe97e945668d8bc27face9f1c2 100644 (file)
  */
 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"));
index 31064275b700098a6c797a7b23fa57f8c7190299..975999bd3523595a39de5e31789ebe03ea5b18b7 100644 (file)
  */
 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")
index ff113906138c2f0b8da4ef21e6d63c331422478a..00bfc6b5a414400e4ea7aba9a6cfd4a7fdcb3972 100644 (file)
@@ -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/MeasureAnalyzer.java
deleted file mode 100644 (file)
index 92d0040..0000000
+++ /dev/null
@@ -1,119 +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.
- */
-package org.sonar.batch.mediumtest.xoo.plugin.lang;
-
-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;
-import org.sonar.batch.mediumtest.xoo.plugin.base.Xoo;
-import org.sonar.batch.mediumtest.xoo.plugin.base.XooConstants;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.List;
-
-/**
- * Parse files *.xoo.measures
- */
-public class MeasureAnalyzer implements Analyzer {
-
-  private static final String MEASURES_EXTENSION = ".measures";
-
-  private MetricFinder metricFinder;
-
-  public MeasureAnalyzer(MetricFinder metricFinder) {
-    this.metricFinder = metricFinder;
-  }
-
-  private void processFileMeasures(InputFile inputFile, AnalyzerContext context) {
-    File ioFile = inputFile.file();
-    File measureFile = new File(ioFile.getParentFile(), ioFile.getName() + MEASURES_EXTENSION);
-    if (measureFile.exists()) {
-      XooConstants.LOG.debug("Processing " + measureFile.getAbsolutePath());
-      try {
-        List<String> lines = FileUtils.readLines(measureFile, context.fileSystem().encoding().name());
-        int lineNumber = 0;
-        for (String line : lines) {
-          lineNumber++;
-          if (StringUtils.isBlank(line)) {
-            continue;
-          }
-          if (line.startsWith("#")) {
-            continue;
-          }
-          try {
-            String metricKey = StringUtils.substringBefore(line, ":");
-            String value = line.substring(metricKey.length() + 1);
-            context.addMeasure(createMeasure(context, inputFile, metricKey, value));
-          } catch (Exception e) {
-            throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
-          }
-        }
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
-    }
-  }
-
-  private AnalyzerMeasure<?> createMeasure(AnalyzerContext context, InputFile xooFile, String metricKey, String value) {
-    org.sonar.api.batch.measure.Metric<Serializable> metric = metricFinder.findByKey(metricKey);
-    AnalyzerMeasureBuilder<Serializable> builder = context.measureBuilder()
-      .forMetric(metric)
-      .onFile(xooFile);
-    if (Boolean.class.equals(metric.valueType())) {
-      builder.withValue(Boolean.parseBoolean(value));
-    } else if (Integer.class.equals(metric.valueType())) {
-      builder.withValue(Integer.valueOf(value));
-    } else if (Double.class.equals(metric.valueType())) {
-      builder.withValue(Double.valueOf(value));
-    } else if (String.class.equals(metric.valueType())) {
-      builder.withValue(value);
-    } else if (Long.class.equals(metric.valueType())) {
-      builder.withValue(Long.valueOf(value));
-    } else {
-      throw new UnsupportedOperationException("Unsupported type :" + metric.valueType());
-    }
-    return builder.build();
-  }
-
-  @Override
-  public void describe(AnalyzerDescriptor descriptor) {
-    descriptor
-      .name("Xoo Measure Analyzer")
-      .provides(CoreMetrics.LINES)
-      .workOnLanguages(Xoo.KEY)
-      .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST);
-  }
-
-  @Override
-  public void analyse(AnalyzerContext 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/MeasureSensor.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/MeasureSensor.java
new file mode 100644 (file)
index 0000000..2f56da1
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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.fs.InputFile;
+import org.sonar.api.batch.measure.MetricFinder;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.batch.mediumtest.xoo.plugin.base.Xoo;
+import org.sonar.batch.mediumtest.xoo.plugin.base.XooConstants;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Parse files *.xoo.measures
+ */
+public class MeasureSensor implements Sensor {
+
+  private static final String MEASURES_EXTENSION = ".measures";
+
+  private MetricFinder metricFinder;
+
+  public MeasureSensor(MetricFinder metricFinder) {
+    this.metricFinder = metricFinder;
+  }
+
+  private void processFileMeasures(InputFile inputFile, SensorContext context) {
+    File ioFile = inputFile.file();
+    File measureFile = new File(ioFile.getParentFile(), ioFile.getName() + MEASURES_EXTENSION);
+    if (measureFile.exists()) {
+      XooConstants.LOG.debug("Processing " + measureFile.getAbsolutePath());
+      try {
+        List<String> lines = FileUtils.readLines(measureFile, context.fileSystem().encoding().name());
+        int lineNumber = 0;
+        for (String line : lines) {
+          lineNumber++;
+          if (StringUtils.isBlank(line)) {
+            continue;
+          }
+          if (line.startsWith("#")) {
+            continue;
+          }
+          try {
+            String metricKey = StringUtils.substringBefore(line, ":");
+            String value = line.substring(metricKey.length() + 1);
+            context.addMeasure(createMeasure(context, inputFile, metricKey, value));
+          } catch (Exception e) {
+            throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
+          }
+        }
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  private Measure<?> createMeasure(SensorContext context, InputFile xooFile, String metricKey, String value) {
+    org.sonar.api.batch.measure.Metric<Serializable> metric = metricFinder.findByKey(metricKey);
+    MeasureBuilder<Serializable> builder = context.measureBuilder()
+      .forMetric(metric)
+      .onFile(xooFile);
+    if (Boolean.class.equals(metric.valueType())) {
+      builder.withValue(Boolean.parseBoolean(value));
+    } else if (Integer.class.equals(metric.valueType())) {
+      builder.withValue(Integer.valueOf(value));
+    } else if (Double.class.equals(metric.valueType())) {
+      builder.withValue(Double.valueOf(value));
+    } else if (String.class.equals(metric.valueType())) {
+      builder.withValue(value);
+    } else if (Long.class.equals(metric.valueType())) {
+      builder.withValue(Long.valueOf(value));
+    } else {
+      throw new UnsupportedOperationException("Unsupported type :" + metric.valueType());
+    }
+    return builder.build();
+  }
+
+  @Override
+  public void describe(SensorDescriptor descriptor) {
+    descriptor
+      .name("Xoo Measure Analyzer")
+      .provides(CoreMetrics.LINES)
+      .workOnLanguages(Xoo.KEY)
+      .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST);
+  }
+
+  @Override
+  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/ScmActivityAnalyzer.java
deleted file mode 100644 (file)
index 346036a..0000000
+++ /dev/null
@@ -1,112 +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.
- */
-package org.sonar.batch.mediumtest.xoo.plugin.lang;
-
-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;
-import org.sonar.api.measures.FileLinesContext;
-import org.sonar.api.measures.FileLinesContextFactory;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.batch.mediumtest.xoo.plugin.base.Xoo;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.List;
-
-public class ScmActivityAnalyzer implements Analyzer {
-
-  private static final Logger LOG = LoggerFactory.getLogger(ScmActivityAnalyzer.class);
-
-  private static final String SCM_EXTENSION = ".scm";
-
-  private final FileSystem fs;
-  private final FileLinesContextFactory fileLinesContextFactory;
-
-  public ScmActivityAnalyzer(FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem) {
-    this.fs = fileSystem;
-    this.fileLinesContextFactory = fileLinesContextFactory;
-  }
-
-  @Override
-  public void describe(AnalyzerDescriptor descriptor) {
-    descriptor
-      .name(this.getClass().getSimpleName())
-      .provides(CoreMetrics.SCM_AUTHORS_BY_LINE,
-        CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE,
-        CoreMetrics.SCM_REVISIONS_BY_LINE)
-      .workOnLanguages(Xoo.KEY);
-  }
-
-  @Override
-  public void analyse(AnalyzerContext context) {
-    for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(Xoo.KEY))) {
-      processFile(inputFile);
-    }
-
-  }
-
-  @VisibleForTesting
-  protected void processFile(InputFile inputFile) {
-    File ioFile = inputFile.file();
-    File scmDataFile = new java.io.File(ioFile.getParentFile(), ioFile.getName() + SCM_EXTENSION);
-    if (!scmDataFile.exists()) {
-      LOG.debug("Skipping SCM data injection for " + inputFile.relativePath());
-      return;
-    }
-
-    FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile);
-    try {
-      List<String> lines = FileUtils.readLines(scmDataFile, Charsets.UTF_8.name());
-      int lineNumber = 0;
-      for (String line : lines) {
-        lineNumber++;
-        if (StringUtils.isNotBlank(line)) {
-          // revision,author,dateTime
-          String[] fields = StringUtils.split(line, ',');
-          if (fields.length < 3) {
-            throw new IllegalStateException("Not enough fields on line " + lineNumber);
-          }
-          String revision = fields[0];
-          String author = fields[1];
-          // Will throw an exception, when date is not in format "yyyy-MM-dd"
-          Date date = DateUtils.parseDate(fields[2]);
-
-          fileLinesContext.setStringValue(CoreMetrics.SCM_REVISIONS_BY_LINE_KEY, lineNumber, revision);
-          fileLinesContext.setStringValue(CoreMetrics.SCM_AUTHORS_BY_LINE_KEY, lineNumber, author);
-          fileLinesContext.setStringValue(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, lineNumber, DateUtils.formatDateTime(date));
-        }
-      }
-    } catch (IOException e) {
-      throw new IllegalStateException(e);
-    }
-    fileLinesContext.save();
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivitySensor.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivitySensor.java
new file mode 100644 (file)
index 0000000..ecf05f8
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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.fs.FileSystem;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.FileLinesContext;
+import org.sonar.api.measures.FileLinesContextFactory;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.batch.mediumtest.xoo.plugin.base.Xoo;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+public class ScmActivitySensor implements Sensor {
+
+  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 ScmActivitySensor(FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem) {
+    this.fs = fileSystem;
+    this.fileLinesContextFactory = fileLinesContextFactory;
+  }
+
+  @Override
+  public void describe(SensorDescriptor descriptor) {
+    descriptor
+      .name(this.getClass().getSimpleName())
+      .provides(CoreMetrics.SCM_AUTHORS_BY_LINE,
+        CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE,
+        CoreMetrics.SCM_REVISIONS_BY_LINE)
+      .workOnLanguages(Xoo.KEY);
+  }
+
+  @Override
+  public void analyse(SensorContext context) {
+    for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(Xoo.KEY))) {
+      processFile(inputFile);
+    }
+
+  }
+
+  @VisibleForTesting
+  protected void processFile(InputFile inputFile) {
+    File ioFile = inputFile.file();
+    File scmDataFile = new java.io.File(ioFile.getParentFile(), ioFile.getName() + SCM_EXTENSION);
+    if (!scmDataFile.exists()) {
+      LOG.debug("Skipping SCM data injection for " + inputFile.relativePath());
+      return;
+    }
+
+    FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile);
+    try {
+      List<String> lines = FileUtils.readLines(scmDataFile, Charsets.UTF_8.name());
+      int lineNumber = 0;
+      for (String line : lines) {
+        lineNumber++;
+        if (StringUtils.isNotBlank(line)) {
+          // revision,author,dateTime
+          String[] fields = StringUtils.split(line, ',');
+          if (fields.length < 3) {
+            throw new IllegalStateException("Not enough fields on line " + lineNumber);
+          }
+          String revision = fields[0];
+          String author = fields[1];
+          // Will throw an exception, when date is not in format "yyyy-MM-dd"
+          Date date = DateUtils.parseDate(fields[2]);
+
+          fileLinesContext.setStringValue(CoreMetrics.SCM_REVISIONS_BY_LINE_KEY, lineNumber, revision);
+          fileLinesContext.setStringValue(CoreMetrics.SCM_AUTHORS_BY_LINE_KEY, lineNumber, author);
+          fileLinesContext.setStringValue(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, lineNumber, DateUtils.formatDateTime(date));
+        }
+      }
+    } catch (IOException e) {
+      throw new IllegalStateException(e);
+    }
+    fileLinesContext.save();
+  }
+}
index 522ad3b6b5327bb9db61a6d37e012ace86c9c068..f55e7b7bb401dd1ab11d9e1d6124c0e3284dbeac 100644 (file)
  */
 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/AnalyzerContextAdapterTest.java
deleted file mode 100644 (file)
index f20f930..0000000
+++ /dev/null
@@ -1,162 +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.
- */
-package org.sonar.batch.scan;
-
-import org.junit.Before;
-import org.junit.Rule;
-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.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;
-import org.sonar.api.rule.RuleKey;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class AnalyzerContextAdapterTest {
-
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
-  private ActiveRules activeRules;
-  private DefaultFileSystem fs;
-  private AnalyzerContextAdaptor adaptor;
-  private SensorContext sensorContext;
-  private Settings settings;
-  private ResourcePerspectives resourcePerspectives;
-
-  @Before
-  public void prepare() {
-    activeRules = new ActiveRulesBuilder().build();
-    fs = new DefaultFileSystem();
-    MetricFinder metricFinder = mock(MetricFinder.class);
-    when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
-    sensorContext = mock(SensorContext.class);
-    settings = new Settings();
-    resourcePerspectives = mock(ResourcePerspectives.class);
-    adaptor = new AnalyzerContextAdaptor(sensorContext, metricFinder, new Project("myProject"),
-      resourcePerspectives, settings, fs, activeRules);
-  }
-
-  @Test
-  public void shouldProvideComponents() {
-    assertThat(adaptor.activeRules()).isEqualTo(activeRules);
-    assertThat(adaptor.fileSystem()).isEqualTo(fs);
-    assertThat(adaptor.settings()).isEqualTo(settings);
-
-    assertThat(adaptor.issueBuilder()).isNotNull();
-    assertThat(adaptor.measureBuilder()).isNotNull();
-  }
-
-  @Test
-  public void shouldRedirectProjectMeasuresToSensorContext() {
-    AnalyzerMeasure<Integer> measure = adaptor.getMeasure(CoreMetrics.NCLOC_KEY);
-    assertThat(measure).isNull();
-
-    when(sensorContext.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure<Integer>(CoreMetrics.NCLOC, 10.0));
-
-    measure = adaptor.getMeasure(CoreMetrics.NCLOC);
-    assertThat(measure.metric()).isEqualTo(CoreMetrics.NCLOC);
-    assertThat(measure.inputFile()).isNull();
-    assertThat(measure.value()).isEqualTo(10);
-
-    thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("Unknow metric with key: lines");
-    adaptor.getMeasure(CoreMetrics.LINES);
-  }
-
-  @Test
-  public void shouldRedirectFileMeasuresToSensorContext() {
-    InputFile file = new DefaultInputFile("src/Foo.php");
-
-    AnalyzerMeasure<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));
-    measure = adaptor.getMeasure(file, CoreMetrics.NCLOC);
-
-    assertThat(measure.metric()).isEqualTo(CoreMetrics.NCLOC);
-    assertThat(measure.inputFile()).isEqualTo(file);
-    assertThat(measure.value()).isEqualTo(10);
-  }
-
-  @Test
-  public void shouldAddMeasureToSensorContext() {
-    InputFile file = new DefaultInputFile("src/Foo.php");
-
-    ArgumentCaptor<Measure> argumentCaptor = ArgumentCaptor.forClass(Measure.class);
-    when(sensorContext.saveMeasure(eq(file), argumentCaptor.capture())).thenReturn(null);
-
-    adaptor.addMeasure(new DefaultAnalyzerMeasureBuilder()
-      .onFile(file)
-      .forMetric(CoreMetrics.NCLOC)
-      .withValue(10)
-      .build());
-
-    Measure m = argumentCaptor.getValue();
-    assertThat(m.getValue()).isEqualTo(10.0);
-    assertThat(m.getMetric()).isEqualTo(CoreMetrics.NCLOC);
-  }
-
-  @Test
-  public void shouldAddIssue() {
-    InputFile file = new DefaultInputFile("src/Foo.php");
-
-    ArgumentCaptor<Issue> argumentCaptor = ArgumentCaptor.forClass(Issue.class);
-
-    Issuable issuable = mock(Issuable.class);
-    when(resourcePerspectives.as(Issuable.class, File.create("src/Foo.php"))).thenReturn(issuable);
-
-    when(issuable.addIssue(argumentCaptor.capture())).thenReturn(true);
-
-    adaptor.addIssue(new DefaultAnalyzerIssueBuilder()
-      .onFile(file)
-      .ruleKey(RuleKey.of("foo", "bar"))
-      .message("Foo")
-      .atLine(3)
-      .effortToFix(10.0)
-      .build());
-
-    Issue issue = argumentCaptor.getValue();
-    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("foo", "bar"));
-    assertThat(issue.message()).isEqualTo("Foo");
-    assertThat(issue.line()).isEqualTo(3);
-    assertThat(issue.effortToFix()).isEqualTo(10.0);
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/SensorContextAdapterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/SensorContextAdapterTest.java
new file mode 100644 (file)
index 0000000..b4a8fda
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.scan;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.batch.SensorContext;
+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.MetricFinder;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Project;
+import org.sonar.api.rule.RuleKey;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class SensorContextAdapterTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  private ActiveRules activeRules;
+  private DefaultFileSystem fs;
+  private SensorContextAdaptor adaptor;
+  private SensorContext sensorContext;
+  private Settings settings;
+  private ResourcePerspectives resourcePerspectives;
+
+  @Before
+  public void prepare() {
+    activeRules = new ActiveRulesBuilder().build();
+    fs = new DefaultFileSystem();
+    MetricFinder metricFinder = mock(MetricFinder.class);
+    when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
+    sensorContext = mock(SensorContext.class);
+    settings = new Settings();
+    resourcePerspectives = mock(ResourcePerspectives.class);
+    adaptor = new SensorContextAdaptor(sensorContext, metricFinder, new Project("myProject"),
+      resourcePerspectives, settings, fs, activeRules);
+  }
+
+  @Test
+  public void shouldProvideComponents() {
+    assertThat(adaptor.activeRules()).isEqualTo(activeRules);
+    assertThat(adaptor.fileSystem()).isEqualTo(fs);
+    assertThat(adaptor.settings()).isEqualTo(settings);
+
+    assertThat(adaptor.issueBuilder()).isNotNull();
+    assertThat(adaptor.measureBuilder()).isNotNull();
+  }
+
+  @Test
+  public void shouldRedirectProjectMeasuresToSensorContext() {
+    Measure<Integer> measure = adaptor.getMeasure(CoreMetrics.NCLOC_KEY);
+    assertThat(measure).isNull();
+
+    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);
+    assertThat(measure.inputFile()).isNull();
+    assertThat(measure.value()).isEqualTo(10);
+
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("Unknow metric with key: lines");
+    adaptor.getMeasure(CoreMetrics.LINES);
+  }
+
+  @Test
+  public void shouldRedirectFileMeasuresToSensorContext() {
+    InputFile file = new DefaultInputFile("src/Foo.php");
+
+    Measure<Integer> measure = adaptor.getMeasure(file, CoreMetrics.NCLOC_KEY);
+    assertThat(measure).isNull();
+
+    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);
+    assertThat(measure.inputFile()).isEqualTo(file);
+    assertThat(measure.value()).isEqualTo(10);
+  }
+
+  @Test
+  public void shouldAddMeasureToSensorContext() {
+    InputFile file = new DefaultInputFile("src/Foo.php");
+
+    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 DefaultMeasureBuilder()
+      .onFile(file)
+      .forMetric(CoreMetrics.NCLOC)
+      .withValue(10)
+      .build());
+
+    org.sonar.api.measures.Measure m = argumentCaptor.getValue();
+    assertThat(m.getValue()).isEqualTo(10.0);
+    assertThat(m.getMetric()).isEqualTo(CoreMetrics.NCLOC);
+  }
+
+  @Test
+  public void shouldAddIssue() {
+    InputFile file = new DefaultInputFile("src/Foo.php");
+
+    ArgumentCaptor<Issue> argumentCaptor = ArgumentCaptor.forClass(Issue.class);
+
+    Issuable issuable = mock(Issuable.class);
+    when(resourcePerspectives.as(Issuable.class, File.create("src/Foo.php"))).thenReturn(issuable);
+
+    when(issuable.addIssue(argumentCaptor.capture())).thenReturn(true);
+
+    adaptor.addIssue(new DefaultIssueBuilder()
+      .onFile(file)
+      .ruleKey(RuleKey.of("foo", "bar"))
+      .message("Foo")
+      .atLine(3)
+      .effortToFix(10.0)
+      .build());
+
+    Issue issue = argumentCaptor.getValue();
+    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("foo", "bar"));
+    assertThat(issue.message()).isEqualTo("Foo");
+    assertThat(issue.line()).isEqualTo(3);
+    assertThat(issue.effortToFix()).isEqualTo(10.0);
+  }
+}
index 8940c3dd2fc34474efd389c7a0a8e0efc683db7c..6c21f0c11848783ed4d02bb152c82927bcae58e8 100644 (file)
  */
 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();
 
index 556ea373b9cccc54fc2233c9d532417112a46925..ffd90b34de247c3c545188c651d2b4ce43d3e2fa 100644 (file)
  */
 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;
index fc055e6da5caa7472d702e8872ede466652812ca..7a82bc2401556a010c1d33a09ea7a8670b9e9493 100644 (file)
@@ -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 {
 
   /**
index ccdec2dbf2f69cfc30377749dd565cc53c22f9ba..2c8332ee0c599c5816dcd4deb216493cf6a58bc5 100644 (file)
@@ -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/Analyzer.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/Analyzer.java
deleted file mode 100644 (file)
index c551226..0000000
+++ /dev/null
@@ -1,50 +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.
- */
-package org.sonar.api.batch.analyzer;
-
-import com.google.common.annotations.Beta;
-import org.sonar.api.BatchExtension;
-
-/**
- * <p>
- * An Analyzer is invoked once during the analysis of a project. The analyzer can parse a flat file, connect to a web server... Analyzers are
- * used to add measure and issues at file level.
- * </p>
- *
- * <p>
- * For example the Cobertura Analyzer parses Cobertura report and saves the first-level of measures on files.
- * </p>
- *
- * @since 4.4
- */
-@Beta
-public interface Analyzer extends BatchExtension {
-
-  /**
-   * Populate {@link AnalyzerDescriptor} of this analyzer.
-   */
-  void describe(AnalyzerDescriptor descriptor);
-
-  /**
-   * The actual analyzer code.
-   */
-  void analyse(AnalyzerContext 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/analyzer/AnalyzerContext.java
deleted file mode 100644 (file)
index 244d0f9..0000000
+++ /dev/null
@@ -1,107 +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.
- */
-package org.sonar.api.batch.analyzer;
-
-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;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.config.Settings;
-
-import javax.annotation.CheckForNull;
-
-import java.io.Serializable;
-
-/**
- * @since 4.4
- */
-@Beta
-public interface AnalyzerContext {
-
-  /**
-   * Get settings of the current project.
-   */
-  Settings settings();
-
-  /**
-   * Get filesystem of the current project.
-   */
-  FileSystem fileSystem();
-
-  /**
-   * Get list of active rules.
-   */
-  ActiveRules activeRules();
-
-  // ----------- MEASURES --------------
-
-  /**
-   * Builder to create a new {@link AnalyzerMeasure}.
-   */
-  <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder();
-
-  /**
-   * Find a project measure.
-   */
-  @CheckForNull
-  AnalyzerMeasure getMeasure(String metricKey);
-
-  /**
-   * Find a project measure.
-   */
-  @CheckForNull
-  <G extends Serializable> AnalyzerMeasure<G> getMeasure(Metric<G> metric);
-
-  /**
-   * Find a file measure.
-   */
-  @CheckForNull
-  AnalyzerMeasure getMeasure(InputFile file, String metricKey);
-
-  /**
-   * Find a file measure.
-   */
-  @CheckForNull
-  <G extends Serializable> AnalyzerMeasure<G> getMeasure(InputFile file, Metric<G> metric);
-
-  /**
-   * Add a measure. Use {@link #measureBuilder()} to create the new measure.
-   */
-  void addMeasure(AnalyzerMeasure<?> measure);
-
-  // ----------- ISSUES --------------
-
-  /**
-   * Builder to create a new {@link AnalyzerIssue}.
-   */
-  AnalyzerIssueBuilder 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);
-
-}
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/analyzer/AnalyzerDescriptor.java
deleted file mode 100644 (file)
index 3e38e5d..0000000
+++ /dev/null
@@ -1,70 +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.
- */
-package org.sonar.api.batch.analyzer;
-
-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
- * to log interesting information or perform some optimization.
- * @since 4.4
- */
-@Beta
-public interface AnalyzerDescriptor {
-
-  /**
-   * Name of the {@link Analyzer}. Will be displayed in logs.
-   */
-  AnalyzerDescriptor name(String name);
-
-  /**
-   * List {@link Metric} this {@link Analyzer} depends on. Will be used to execute Analyzers in correct order.
-   */
-  AnalyzerDescriptor dependsOn(Metric<?>... metrics);
-
-  /**
-   * List {@link Metric} this {@link Analyzer} provides. Will be used to execute Analyzers in correct order.
-   */
-  AnalyzerDescriptor provides(Metric<?>... metrics);
-
-  /**
-   * List languages this {@link Analyzer} work on. May be used by the platform to skip execution of the {@link Analyzer} 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);
-
-  /**
-   * List {@link InputFile.Type} this {@link Analyzer} work on. May be used by the platform to skip execution of the {@link Analyzer} 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);
-
-  /**
-   * List {@link InputFile.Type} this {@link Analyzer} work on. May be used by the platform to skip execution of the {@link Analyzer} 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);
-
-}
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/analyzer/internal/DefaultAnalyzerDescriptor.java
deleted file mode 100644 (file)
index 3f793c9..0000000
+++ /dev/null
@@ -1,98 +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.
- */
-package org.sonar.api.batch.analyzer.internal;
-
-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 {
-
-  private String name;
-  private Metric<?>[] dependsOn = new Metric<?>[0];
-  private Metric<?>[] provides = new Metric<?>[0];
-  private String[] languages = new String[0];
-  private InputFile.Type[] types = new InputFile.Type[0];
-  private String[] ruleRepositories = new String[0];
-
-  public String name() {
-    return name;
-  }
-
-  public Metric[] dependsOn() {
-    return dependsOn;
-  }
-
-  public Metric[] provides() {
-    return provides;
-  }
-
-  public Collection<String> languages() {
-    return Arrays.asList(languages);
-  }
-
-  public Collection<InputFile.Type> types() {
-    return Arrays.asList(types);
-  }
-
-  public Collection<String> ruleRepositories() {
-    return Arrays.asList(ruleRepositories);
-  }
-
-  @Override
-  public DefaultAnalyzerDescriptor name(String name) {
-    this.name = name;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerDescriptor dependsOn(Metric<?>... metrics) {
-    this.dependsOn = metrics;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerDescriptor provides(Metric<?>... metrics) {
-    this.provides = metrics;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerDescriptor workOnLanguages(String... languageKeys) {
-    this.languages = languageKeys;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerDescriptor workOnFileTypes(InputFile.Type... types) {
-    this.types = types;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerDescriptor createIssuesForRuleRepositories(String... repositoryKeys) {
-    this.ruleRepositories = repositoryKeys;
-    return this;
-  }
-
-}
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/analyzer/internal/package-info.java
deleted file mode 100644 (file)
index b61bc22..0000000
+++ /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.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/analyzer/issue/AnalyzerIssue.java
deleted file mode 100644 (file)
index 9a9ce1b..0000000
+++ /dev/null
@@ -1,64 +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.
- */
-package org.sonar.api.batch.analyzer.issue;
-
-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}
- *
- * @since 4.4
- */
-@Beta
-public interface AnalyzerIssue {
-
-  /**
-   * The {@link InputFile} this issue belongs to. Returns null if issue is global to the project.
-   */
-  @Nullable
-  InputFile inputFile();
-
-  /**
-   * The {@link RuleKey} of this issue.
-   */
-  RuleKey ruleKey();
-
-  /**
-   * Message of the issue.
-   */
-  String message();
-
-  /**
-   * Line of the issue.
-   */
-  Integer line();
-
-  /**
-   * Effort to fix the issue. Used by technical debt model.
-   */
-  @Nullable
-  Double effortToFix();
-
-}
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/analyzer/issue/AnalyzerIssueBuilder.java
deleted file mode 100644 (file)
index 12969a5..0000000
+++ /dev/null
@@ -1,71 +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.
- */
-package org.sonar.api.batch.analyzer.issue;
-
-import com.google.common.annotations.Beta;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.rule.RuleKey;
-
-import javax.annotation.Nullable;
-
-/**
- * Builder for {@link AnalyzerIssue}.
- *
- * @since 4.4
- */
-@Beta
-public interface AnalyzerIssueBuilder {
-
-  /**
-   * The {@link RuleKey} of the issue.
-   */
-  AnalyzerIssueBuilder ruleKey(RuleKey ruleKey);
-
-  /**
-   * The {@link InputFile} the issue belongs to. For global issues call {@link #onProject()}.
-   */
-  AnalyzerIssueBuilder onFile(InputFile file);
-
-  /**
-   * Tell that the issue is global to the project.
-   */
-  AnalyzerIssueBuilder onProject();
-
-  /**
-   * Line of the issue. If no line is specified then issue is supposed to be global to the file.
-   */
-  AnalyzerIssueBuilder atLine(int line);
-
-  /**
-   * Effort to fix the issue.
-   */
-  AnalyzerIssueBuilder effortToFix(@Nullable Double effortToFix);
-
-  /**
-   * Message of the issue.
-   */
-  AnalyzerIssueBuilder message(String message);
-
-  /**
-   * Build the issue.
-   */
-  AnalyzerIssue 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/analyzer/issue/internal/DefaultAnalyzerIssue.java
deleted file mode 100644 (file)
index ba75d12..0000000
+++ /dev/null
@@ -1,108 +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.
- */
-package org.sonar.api.batch.analyzer.issue.internal;
-
-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;
-
-import javax.annotation.Nullable;
-
-import java.io.Serializable;
-import java.util.UUID;
-
-public class DefaultAnalyzerIssue implements AnalyzerIssue, Serializable {
-
-  private final String key;
-  private final InputFile inputFile;
-  private final RuleKey ruleKey;
-  private final String message;
-  private final Integer line;
-  private final Double effortToFix;
-
-  DefaultAnalyzerIssue(DefaultAnalyzerIssueBuilder builder) {
-    Preconditions.checkNotNull(builder.ruleKey, "ruleKey is mandatory on issue");
-    this.inputFile = builder.file;
-    this.ruleKey = builder.ruleKey;
-    this.message = builder.message;
-    this.line = builder.line;
-    this.effortToFix = builder.effortToFix;
-    this.key = builder.key == null ? UUID.randomUUID().toString() : builder.key;
-    Preconditions.checkState(!Strings.isNullOrEmpty(key), "Fail to generate issue key");
-  }
-
-  public String key() {
-    return key;
-  }
-
-  @Override
-  @Nullable
-  public InputFile inputFile() {
-    return inputFile;
-  }
-
-  @Override
-  public RuleKey ruleKey() {
-    return ruleKey;
-  }
-
-  @Override
-  public String message() {
-    return message;
-  }
-
-  @Override
-  public Integer line() {
-    return line;
-  }
-
-  @Override
-  @Nullable
-  public Double effortToFix() {
-    return effortToFix;
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || getClass() != o.getClass()) {
-      return false;
-    }
-    DefaultAnalyzerIssue that = (DefaultAnalyzerIssue) o;
-    return !key.equals(that.key);
-  }
-
-  @Override
-  public int hashCode() {
-    return key.hashCode();
-  }
-
-  @Override
-  public String toString() {
-    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
-  }
-
-}
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/analyzer/issue/internal/DefaultAnalyzerIssueBuilder.java
deleted file mode 100644 (file)
index 42a6b97..0000000
+++ /dev/null
@@ -1,97 +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.
- */
-package org.sonar.api.batch.analyzer.issue.internal;
-
-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 {
-
-  String key;
-  Boolean onProject = null;
-  InputFile file;
-  RuleKey ruleKey;
-  String message;
-  Integer line;
-  Double effortToFix;
-
-  @Override
-  public DefaultAnalyzerIssueBuilder ruleKey(RuleKey ruleKey) {
-    this.ruleKey = ruleKey;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerIssueBuilder onFile(InputFile file) {
-    onProject(false);
-    Preconditions.checkNotNull(file, "InputFile should be non null");
-    this.file = file;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerIssueBuilder onProject() {
-    onProject(true);
-    this.file = null;
-    return this;
-  }
-
-  private void onProject(boolean isOnProject) {
-    Preconditions.checkState(this.onProject == null, "onFile or onProject can be called only once");
-    this.onProject = isOnProject;
-  }
-
-  @Override
-  public DefaultAnalyzerIssueBuilder atLine(int line) {
-    this.line = line;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerIssueBuilder effortToFix(@Nullable Double effortToFix) {
-    this.effortToFix = effortToFix;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerIssueBuilder message(String message) {
-    this.message = message;
-    return this;
-  }
-
-  /**
-   * For testing only.
-   */
-  public DefaultAnalyzerIssueBuilder withKey(String key) {
-    this.key = key;
-    return this;
-  }
-
-  @Override
-  public AnalyzerIssue build() {
-    return new DefaultAnalyzerIssue(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/analyzer/issue/internal/package-info.java
deleted file mode 100644 (file)
index 4034ce7..0000000
+++ /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.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/analyzer/issue/package-info.java
deleted file mode 100644 (file)
index 7ccdcaf..0000000
+++ /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.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/analyzer/measure/AnalyzerMeasure.java
deleted file mode 100644 (file)
index 4c33ff1..0000000
+++ /dev/null
@@ -1,48 +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.
- */
-package org.sonar.api.batch.analyzer.measure;
-
-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;
-
-import javax.annotation.Nullable;
-
-import java.io.Serializable;
-
-/**
- * A measure computed by an {@link Analyzer}.
- * @since 4.4
- */
-@Beta
-public interface AnalyzerMeasure<G extends Serializable> {
-
-  /**
-   * The {@link InputFile} this measure belongs to. Returns null if measure is global to the project.
-   */
-  @Nullable
-  InputFile inputFile();
-
-  Metric<G> metric();
-
-  G value();
-
-}
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/analyzer/measure/AnalyzerMeasureBuilder.java
deleted file mode 100644 (file)
index b837f85..0000000
+++ /dev/null
@@ -1,60 +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.
- */
-package org.sonar.api.batch.analyzer.measure;
-
-import org.sonar.api.batch.measure.Metric;
-
-import com.google.common.annotations.Beta;
-import org.sonar.api.batch.fs.InputFile;
-
-import java.io.Serializable;
-
-/**
- * Builder to create new {@link AnalyzerMeasure}
- * @since 4.4
- */
-@Beta
-public interface AnalyzerMeasureBuilder<G extends Serializable> {
-
-  /**
-   * The file the measure belongs to.
-   */
-  AnalyzerMeasureBuilder<G> onFile(InputFile file);
-
-  /**
-   * Tell that the measure is global to the project.
-   */
-  AnalyzerMeasureBuilder<G> onProject();
-
-  /**
-   * The metric this measure belong to.
-   */
-  AnalyzerMeasureBuilder<G> forMetric(Metric<G> metric);
-
-  /**
-   * Value of the measure.
-   */
-  AnalyzerMeasureBuilder<G> withValue(G value);
-
-  /**
-   * Build the measure.
-   */
-  AnalyzerMeasure<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/analyzer/measure/internal/DefaultAnalyzerMeasure.java
deleted file mode 100644 (file)
index 1e0f696..0000000
+++ /dev/null
@@ -1,99 +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.
- */
-package org.sonar.api.batch.analyzer.measure.internal;
-
-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;
-
-import javax.annotation.Nullable;
-
-import java.io.Serializable;
-
-public class DefaultAnalyzerMeasure<G extends Serializable> implements AnalyzerMeasure<G>, Serializable {
-
-  private final InputFile inputFile;
-  private final Metric<G> metric;
-  private final G value;
-
-  DefaultAnalyzerMeasure(DefaultAnalyzerMeasureBuilder<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());
-    this.inputFile = builder.file;
-    this.metric = builder.metric;
-    this.value = builder.value;
-  }
-
-  @Nullable
-  @Override
-  public InputFile inputFile() {
-    return inputFile;
-  }
-
-  @Override
-  public Metric<G> metric() {
-    return metric;
-  }
-
-  @Override
-  public G value() {
-    return value;
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (obj == null) {
-      return false;
-    }
-    if (obj == this) {
-      return true;
-    }
-    if (obj.getClass() != getClass()) {
-      return false;
-    }
-    DefaultAnalyzerMeasure rhs = (DefaultAnalyzerMeasure) obj;
-    return new EqualsBuilder()
-      .append(inputFile, rhs.inputFile)
-      .append(metric, rhs.metric)
-      .append(value, rhs.value)
-      .isEquals();
-  }
-
-  @Override
-  public int hashCode() {
-    return new HashCodeBuilder(27, 45).
-      append(inputFile).
-      append(metric).
-      append(value).
-      toHashCode();
-  }
-
-  @Override
-  public String toString() {
-    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
-  }
-
-}
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/analyzer/measure/internal/DefaultAnalyzerMeasureBuilder.java
deleted file mode 100644 (file)
index 76de69c..0000000
+++ /dev/null
@@ -1,76 +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.
- */
-package org.sonar.api.batch.analyzer.measure.internal;
-
-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> {
-
-  Boolean onProject = null;
-  InputFile file;
-  Metric<G> metric;
-  G value;
-
-  @Override
-  public DefaultAnalyzerMeasureBuilder<G> onFile(InputFile inputFile) {
-    onProject(false);
-    Preconditions.checkNotNull(inputFile, "inputFile should be non null");
-    this.file = inputFile;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerMeasureBuilder<G> onProject() {
-    onProject(true);
-    this.file = null;
-    return this;
-  }
-
-  private void onProject(boolean isOnProject) {
-    Preconditions.checkState(this.onProject == null, "onFile or onProject can be called only once");
-    this.onProject = isOnProject;
-  }
-
-  @Override
-  public DefaultAnalyzerMeasureBuilder<G> forMetric(Metric<G> metric) {
-    Preconditions.checkState(metric != null, "Metric already defined");
-    Preconditions.checkNotNull(metric, "metric should be non null");
-    this.metric = metric;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerMeasureBuilder<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;
-    return this;
-  }
-
-  @Override
-  public DefaultAnalyzerMeasure<G> build() {
-    return new DefaultAnalyzerMeasure<G>(this);
-  }
-}
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 (file)
index a508e1e..0000000
+++ /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/measure/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/analyzer/measure/package-info.java
deleted file mode 100644 (file)
index a72c5a1..0000000
+++ /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;
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/analyzer/package-info.java
deleted file mode 100644 (file)
index 4ae26db..0000000
+++ /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;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java
new file mode 100644 (file)
index 0000000..17a963e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.sensor;
+
+import com.google.common.annotations.Beta;
+import org.sonar.api.BatchExtension;
+
+/**
+ * <p>
+ * An Analyzer is invoked once during the analysis of a project. The analyzer can parse a flat file, connect to a web server... Analyzers are
+ * used to add measure and issues at file level.
+ * </p>
+ *
+ * <p>
+ * For example the Cobertura Analyzer parses Cobertura report and saves the first-level of measures on files.
+ * </p>
+ *
+ * @since 4.4
+ */
+@Beta
+public interface Sensor extends BatchExtension {
+
+  /**
+   * Populate {@link SensorDescriptor} of this analyzer.
+   */
+  void describe(SensorDescriptor descriptor);
+
+  /**
+   * The actual analyzer code.
+   */
+  void analyse(SensorContext context);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
new file mode 100644 (file)
index 0000000..873fed6
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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.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.config.Settings;
+
+import javax.annotation.CheckForNull;
+
+import java.io.Serializable;
+
+/**
+ * @since 4.4
+ */
+@Beta
+public interface SensorContext {
+
+  /**
+   * Get settings of the current project.
+   */
+  Settings settings();
+
+  /**
+   * Get filesystem of the current project.
+   */
+  FileSystem fileSystem();
+
+  /**
+   * Get list of active rules.
+   */
+  ActiveRules activeRules();
+
+  // ----------- MEASURES --------------
+
+  /**
+   * Builder to create a new {@link Measure}.
+   */
+  <G extends Serializable> MeasureBuilder<G> measureBuilder();
+
+  /**
+   * Find a project measure.
+   */
+  @CheckForNull
+  Measure getMeasure(String metricKey);
+
+  /**
+   * Find a project measure.
+   */
+  @CheckForNull
+  <G extends Serializable> Measure<G> getMeasure(Metric<G> metric);
+
+  /**
+   * Find a file measure.
+   */
+  @CheckForNull
+  Measure getMeasure(InputFile file, String metricKey);
+
+  /**
+   * Find a file measure.
+   */
+  @CheckForNull
+  <G extends Serializable> Measure<G> getMeasure(InputFile file, Metric<G> metric);
+
+  /**
+   * Add a measure. Use {@link #measureBuilder()} to create the new measure.
+   */
+  void addMeasure(Measure<?> measure);
+
+  // ----------- ISSUES --------------
+
+  /**
+   * Builder to create a new {@link Issue}.
+   */
+  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(Issue issue);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java
new file mode 100644 (file)
index 0000000..b25f00e
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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 Sensor} is doing. Information may be used by the platform
+ * to log interesting information or perform some optimization.
+ * @since 4.4
+ */
+@Beta
+public interface SensorDescriptor {
+
+  /**
+   * Name of the {@link Sensor}. Will be displayed in logs.
+   */
+  SensorDescriptor name(String name);
+
+  /**
+   * List {@link Metric} this {@link Sensor} depends on. Will be used to execute Analyzers in correct order.
+   */
+  SensorDescriptor dependsOn(Metric<?>... metrics);
+
+  /**
+   * List {@link Metric} this {@link Sensor} provides. Will be used to execute Analyzers in correct order.
+   */
+  SensorDescriptor provides(Metric<?>... metrics);
+
+  /**
+   * 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.
+   */
+  SensorDescriptor workOnLanguages(String... languageKeys);
+
+  /**
+   * 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.
+   */
+  SensorDescriptor workOnFileTypes(InputFile.Type... types);
+
+  /**
+   * 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.
+   */
+  SensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptor.java
new file mode 100644 (file)
index 0000000..a371fc5
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.sensor.internal;
+
+import org.sonar.api.batch.sensor.SensorDescriptor;
+
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.measure.Metric;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+public class DefaultSensorDescriptor implements SensorDescriptor {
+
+  private String name;
+  private Metric<?>[] dependsOn = new Metric<?>[0];
+  private Metric<?>[] provides = new Metric<?>[0];
+  private String[] languages = new String[0];
+  private InputFile.Type[] types = new InputFile.Type[0];
+  private String[] ruleRepositories = new String[0];
+
+  public String name() {
+    return name;
+  }
+
+  public Metric[] dependsOn() {
+    return dependsOn;
+  }
+
+  public Metric[] provides() {
+    return provides;
+  }
+
+  public Collection<String> languages() {
+    return Arrays.asList(languages);
+  }
+
+  public Collection<InputFile.Type> types() {
+    return Arrays.asList(types);
+  }
+
+  public Collection<String> ruleRepositories() {
+    return Arrays.asList(ruleRepositories);
+  }
+
+  @Override
+  public DefaultSensorDescriptor name(String name) {
+    this.name = name;
+    return this;
+  }
+
+  @Override
+  public DefaultSensorDescriptor dependsOn(Metric<?>... metrics) {
+    this.dependsOn = metrics;
+    return this;
+  }
+
+  @Override
+  public DefaultSensorDescriptor provides(Metric<?>... metrics) {
+    this.provides = metrics;
+    return this;
+  }
+
+  @Override
+  public DefaultSensorDescriptor workOnLanguages(String... languageKeys) {
+    this.languages = languageKeys;
+    return this;
+  }
+
+  @Override
+  public DefaultSensorDescriptor workOnFileTypes(InputFile.Type... types) {
+    this.types = types;
+    return this;
+  }
+
+  @Override
+  public DefaultSensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys) {
+    this.ruleRepositories = repositoryKeys;
+    return this;
+  }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/package-info.java
new file mode 100644 (file)
index 0000000..9b5158a
--- /dev/null
@@ -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.internal;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java
new file mode 100644 (file)
index 0000000..713b86d
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.sensor.issue;
+
+import org.sonar.api.batch.sensor.Sensor;
+
+import com.google.common.annotations.Beta;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.rule.RuleKey;
+
+import javax.annotation.Nullable;
+
+/**
+ * Issue reported by an {@link Sensor}
+ *
+ * @since 4.4
+ */
+@Beta
+public interface Issue {
+
+  /**
+   * The {@link InputFile} this issue belongs to. Returns null if issue is global to the project.
+   */
+  @Nullable
+  InputFile inputFile();
+
+  /**
+   * The {@link RuleKey} of this issue.
+   */
+  RuleKey ruleKey();
+
+  /**
+   * Message of the issue.
+   */
+  String message();
+
+  /**
+   * Line of the issue.
+   */
+  Integer line();
+
+  /**
+   * Effort to fix the issue. Used by technical debt model.
+   */
+  @Nullable
+  Double effortToFix();
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueBuilder.java
new file mode 100644 (file)
index 0000000..6b962d6
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.sensor.issue;
+
+import com.google.common.annotations.Beta;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.rule.RuleKey;
+
+import javax.annotation.Nullable;
+
+/**
+ * Builder for {@link Issue}.
+ *
+ * @since 4.4
+ */
+@Beta
+public interface IssueBuilder {
+
+  /**
+   * The {@link RuleKey} of the issue.
+   */
+  IssueBuilder ruleKey(RuleKey ruleKey);
+
+  /**
+   * The {@link InputFile} the issue belongs to. For global issues call {@link #onProject()}.
+   */
+  IssueBuilder onFile(InputFile file);
+
+  /**
+   * Tell that the issue is global to the project.
+   */
+  IssueBuilder onProject();
+
+  /**
+   * Line of the issue. If no line is specified then issue is supposed to be global to the file.
+   */
+  IssueBuilder atLine(int line);
+
+  /**
+   * Effort to fix the issue.
+   */
+  IssueBuilder effortToFix(@Nullable Double effortToFix);
+
+  /**
+   * Message of the issue.
+   */
+  IssueBuilder message(String message);
+
+  /**
+   * Build the issue.
+   */
+  Issue build();
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
new file mode 100644 (file)
index 0000000..d20d5c7
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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.fs.InputFile;
+import org.sonar.api.rule.RuleKey;
+
+import javax.annotation.Nullable;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+public class DefaultIssue implements Issue, Serializable {
+
+  private final String key;
+  private final InputFile inputFile;
+  private final RuleKey ruleKey;
+  private final String message;
+  private final Integer line;
+  private final Double effortToFix;
+
+  DefaultIssue(DefaultIssueBuilder builder) {
+    Preconditions.checkNotNull(builder.ruleKey, "ruleKey is mandatory on issue");
+    this.inputFile = builder.file;
+    this.ruleKey = builder.ruleKey;
+    this.message = builder.message;
+    this.line = builder.line;
+    this.effortToFix = builder.effortToFix;
+    this.key = builder.key == null ? UUID.randomUUID().toString() : builder.key;
+    Preconditions.checkState(!Strings.isNullOrEmpty(key), "Fail to generate issue key");
+  }
+
+  public String key() {
+    return key;
+  }
+
+  @Override
+  @Nullable
+  public InputFile inputFile() {
+    return inputFile;
+  }
+
+  @Override
+  public RuleKey ruleKey() {
+    return ruleKey;
+  }
+
+  @Override
+  public String message() {
+    return message;
+  }
+
+  @Override
+  public Integer line() {
+    return line;
+  }
+
+  @Override
+  @Nullable
+  public Double effortToFix() {
+    return effortToFix;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+    DefaultIssue that = (DefaultIssue) o;
+    return !key.equals(that.key);
+  }
+
+  @Override
+  public int hashCode() {
+    return key.hashCode();
+  }
+
+  @Override
+  public String toString() {
+    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+  }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueBuilder.java
new file mode 100644 (file)
index 0000000..8d8249d
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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.fs.InputFile;
+import org.sonar.api.rule.RuleKey;
+
+import javax.annotation.Nullable;
+
+public class DefaultIssueBuilder implements IssueBuilder {
+
+  String key;
+  Boolean onProject = null;
+  InputFile file;
+  RuleKey ruleKey;
+  String message;
+  Integer line;
+  Double effortToFix;
+
+  @Override
+  public DefaultIssueBuilder ruleKey(RuleKey ruleKey) {
+    this.ruleKey = ruleKey;
+    return this;
+  }
+
+  @Override
+  public DefaultIssueBuilder onFile(InputFile file) {
+    onProject(false);
+    Preconditions.checkNotNull(file, "InputFile should be non null");
+    this.file = file;
+    return this;
+  }
+
+  @Override
+  public DefaultIssueBuilder onProject() {
+    onProject(true);
+    this.file = null;
+    return this;
+  }
+
+  private void onProject(boolean isOnProject) {
+    Preconditions.checkState(this.onProject == null, "onFile or onProject can be called only once");
+    this.onProject = isOnProject;
+  }
+
+  @Override
+  public DefaultIssueBuilder atLine(int line) {
+    this.line = line;
+    return this;
+  }
+
+  @Override
+  public DefaultIssueBuilder effortToFix(@Nullable Double effortToFix) {
+    this.effortToFix = effortToFix;
+    return this;
+  }
+
+  @Override
+  public DefaultIssueBuilder message(String message) {
+    this.message = message;
+    return this;
+  }
+
+  /**
+   * For testing only.
+   */
+  public DefaultIssueBuilder withKey(String key) {
+    this.key = key;
+    return this;
+  }
+
+  @Override
+  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 (file)
index 0000000..85fd63f
--- /dev/null
@@ -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/sensor/issue/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/package-info.java
new file mode 100644 (file)
index 0000000..6cc03c4
--- /dev/null
@@ -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;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/Measure.java
new file mode 100644 (file)
index 0000000..ea606d4
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.sensor.measure;
+
+import org.sonar.api.batch.sensor.Sensor;
+
+import com.google.common.annotations.Beta;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.measure.Metric;
+
+import javax.annotation.Nullable;
+
+import java.io.Serializable;
+
+/**
+ * A measure computed by an {@link Sensor}.
+ * @since 4.4
+ */
+@Beta
+public interface Measure<G extends Serializable> {
+
+  /**
+   * The {@link InputFile} this measure belongs to. Returns null if measure is global to the project.
+   */
+  @Nullable
+  InputFile inputFile();
+
+  Metric<G> metric();
+
+  G value();
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/MeasureBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/MeasureBuilder.java
new file mode 100644 (file)
index 0000000..05b16be
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.sensor.measure;
+
+import org.sonar.api.batch.measure.Metric;
+
+import com.google.common.annotations.Beta;
+import org.sonar.api.batch.fs.InputFile;
+
+import java.io.Serializable;
+
+/**
+ * Builder to create new {@link Measure}
+ * @since 4.4
+ */
+@Beta
+public interface MeasureBuilder<G extends Serializable> {
+
+  /**
+   * The file the measure belongs to.
+   */
+  MeasureBuilder<G> onFile(InputFile file);
+
+  /**
+   * Tell that the measure is global to the project.
+   */
+  MeasureBuilder<G> onProject();
+
+  /**
+   * The metric this measure belong to.
+   */
+  MeasureBuilder<G> forMetric(Metric<G> metric);
+
+  /**
+   * Value of the measure.
+   */
+  MeasureBuilder<G> withValue(G value);
+
+  /**
+   * Build the measure.
+   */
+  Measure<G> build();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java
new file mode 100644 (file)
index 0000000..6664a05
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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.fs.InputFile;
+import org.sonar.api.batch.measure.Metric;
+
+import javax.annotation.Nullable;
+
+import java.io.Serializable;
+
+public class DefaultMeasure<G extends Serializable> implements Measure<G>, Serializable {
+
+  private final InputFile inputFile;
+  private final Metric<G> metric;
+  private final G value;
+
+  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());
+    this.inputFile = builder.file;
+    this.metric = builder.metric;
+    this.value = builder.value;
+  }
+
+  @Nullable
+  @Override
+  public InputFile inputFile() {
+    return inputFile;
+  }
+
+  @Override
+  public Metric<G> metric() {
+    return metric;
+  }
+
+  @Override
+  public G value() {
+    return value;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (obj == this) {
+      return true;
+    }
+    if (obj.getClass() != getClass()) {
+      return false;
+    }
+    DefaultMeasure rhs = (DefaultMeasure) obj;
+    return new EqualsBuilder()
+      .append(inputFile, rhs.inputFile)
+      .append(metric, rhs.metric)
+      .append(value, rhs.value)
+      .isEquals();
+  }
+
+  @Override
+  public int hashCode() {
+    return new HashCodeBuilder(27, 45).
+      append(inputFile).
+      append(metric).
+      append(value).
+      toHashCode();
+  }
+
+  @Override
+  public String toString() {
+    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+  }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureBuilder.java
new file mode 100644 (file)
index 0000000..a1ef2e5
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.sensor.measure.internal;
+
+import org.sonar.api.batch.sensor.measure.MeasureBuilder;
+
+import com.google.common.base.Preconditions;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.measure.Metric;
+
+import java.io.Serializable;
+
+public class DefaultMeasureBuilder<G extends Serializable> implements MeasureBuilder<G> {
+
+  Boolean onProject = null;
+  InputFile file;
+  Metric<G> metric;
+  G value;
+
+  @Override
+  public DefaultMeasureBuilder<G> onFile(InputFile inputFile) {
+    onProject(false);
+    Preconditions.checkNotNull(inputFile, "inputFile should be non null");
+    this.file = inputFile;
+    return this;
+  }
+
+  @Override
+  public DefaultMeasureBuilder<G> onProject() {
+    onProject(true);
+    this.file = null;
+    return this;
+  }
+
+  private void onProject(boolean isOnProject) {
+    Preconditions.checkState(this.onProject == null, "onFile or onProject can be called only once");
+    this.onProject = isOnProject;
+  }
+
+  @Override
+  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;
+    return this;
+  }
+
+  @Override
+  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;
+    return this;
+  }
+
+  @Override
+  public DefaultMeasure<G> build() {
+    return new DefaultMeasure<G>(this);
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/package-info.java
new file mode 100644 (file)
index 0000000..414484d
--- /dev/null
@@ -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.measure.internal;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/package-info.java
new file mode 100644 (file)
index 0000000..92eba8a
--- /dev/null
@@ -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.measure;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/package-info.java
new file mode 100644 (file)
index 0000000..0b6b56a
--- /dev/null
@@ -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;
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/analyzer/internal/DefaultAnalyzerDescriptorTest.java
deleted file mode 100644 (file)
index b55bae7..0000000
+++ /dev/null
@@ -1,47 +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.
- */
-package org.sonar.api.batch.analyzer.internal;
-
-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 {
-
-  @Test
-  public void describe() {
-    DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor();
-    descriptor
-      .name("Foo")
-      .dependsOn(CoreMetrics.NCLOC)
-      .provides(CoreMetrics.BLOCKER_VIOLATIONS)
-      .workOnLanguages("java", "php")
-      .workOnFileTypes(InputFile.Type.MAIN);
-
-    assertThat(descriptor.name()).isEqualTo("Foo");
-    assertThat(descriptor.dependsOn()).containsOnly(CoreMetrics.NCLOC);
-    assertThat(descriptor.provides()).containsOnly(CoreMetrics.BLOCKER_VIOLATIONS);
-    assertThat(descriptor.languages()).containsOnly("java", "php");
-    assertThat(descriptor.types()).containsOnly(InputFile.Type.MAIN);
-  }
-
-}
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/analyzer/issue/internal/DefaultAnalyzerIssueTest.java
deleted file mode 100644 (file)
index 1ec4228..0000000
+++ /dev/null
@@ -1,85 +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.
- */
-package org.sonar.api.batch.analyzer.issue.internal;
-
-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 {
-
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
-  @Test
-  public void build_file_issue() {
-    AnalyzerIssue issue = new DefaultAnalyzerIssueBuilder()
-      .onFile(new DefaultInputFile("src/Foo.php"))
-      .ruleKey(RuleKey.of("repo", "rule"))
-      .atLine(1)
-      .effortToFix(10.0)
-      .message("Wrong way!")
-      .build();
-
-    assertThat(issue.inputFile()).isEqualTo(new DefaultInputFile("src/Foo.php"));
-    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
-    assertThat(issue.line()).isEqualTo(1);
-    assertThat(issue.effortToFix()).isEqualTo(10.0);
-    assertThat(issue.message()).isEqualTo("Wrong way!");
-  }
-
-  @Test
-  public void build_project_issue() {
-    AnalyzerIssue issue = new DefaultAnalyzerIssueBuilder()
-      .onProject()
-      .ruleKey(RuleKey.of("repo", "rule"))
-      .atLine(1)
-      .effortToFix(10.0)
-      .message("Wrong way!")
-      .build();
-
-    assertThat(issue.inputFile()).isNull();
-    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
-    assertThat(issue.line()).isEqualTo(1);
-    assertThat(issue.effortToFix()).isEqualTo(10.0);
-    assertThat(issue.message()).isEqualTo("Wrong way!");
-  }
-
-  @Test
-  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()
-      .onProject()
-      .onFile(new DefaultInputFile("src/Foo.php"))
-      .ruleKey(RuleKey.of("repo", "rule"))
-      .atLine(1)
-      .effortToFix(10.0)
-      .message("Wrong way!")
-      .build();
-
-  }
-
-}
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/analyzer/measure/internal/DefaultAnalyzerMeasureTest.java
deleted file mode 100644 (file)
index 1e27f76..0000000
+++ /dev/null
@@ -1,73 +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.
- */
-package org.sonar.api.batch.analyzer.measure.internal;
-
-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 {
-
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
-  @Test
-  public void build_file_measure() {
-    AnalyzerMeasure<Integer> issue = new DefaultAnalyzerMeasureBuilder<Integer>()
-      .forMetric(CoreMetrics.LINES)
-      .onFile(new DefaultInputFile("src/Foo.php"))
-      .withValue(3)
-      .build();
-
-    assertThat(issue.inputFile()).isEqualTo(new DefaultInputFile("src/Foo.php"));
-    assertThat(issue.metric()).isEqualTo(CoreMetrics.LINES);
-    assertThat(issue.value()).isEqualTo(3);
-  }
-
-  @Test
-  public void build_project_measure() {
-    AnalyzerMeasure<Integer> issue = new DefaultAnalyzerMeasureBuilder<Integer>()
-      .forMetric(CoreMetrics.LINES)
-      .onProject()
-      .withValue(3)
-      .build();
-
-    assertThat(issue.inputFile()).isNull();
-    assertThat(issue.metric()).isEqualTo(CoreMetrics.LINES);
-    assertThat(issue.value()).isEqualTo(3);
-  }
-
-  @Test
-  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>()
-      .onProject()
-      .onFile(new DefaultInputFile("src/Foo.php"))
-      .withValue(3)
-      .build();
-  }
-
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/DefaultSensorDescriptorTest.java
new file mode 100644 (file)
index 0000000..fc91edc
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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 DefaultSensorDescriptorTest {
+
+  @Test
+  public void describe() {
+    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
+    descriptor
+      .name("Foo")
+      .dependsOn(CoreMetrics.NCLOC)
+      .provides(CoreMetrics.BLOCKER_VIOLATIONS)
+      .workOnLanguages("java", "php")
+      .workOnFileTypes(InputFile.Type.MAIN);
+
+    assertThat(descriptor.name()).isEqualTo("Foo");
+    assertThat(descriptor.dependsOn()).containsOnly(CoreMetrics.NCLOC);
+    assertThat(descriptor.provides()).containsOnly(CoreMetrics.BLOCKER_VIOLATIONS);
+    assertThat(descriptor.languages()).containsOnly("java", "php");
+    assertThat(descriptor.types()).containsOnly(InputFile.Type.MAIN);
+  }
+
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java
new file mode 100644 (file)
index 0000000..25454a8
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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.fs.internal.DefaultInputFile;
+import org.sonar.api.rule.RuleKey;
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultIssueTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void build_file_issue() {
+    Issue issue = new DefaultIssueBuilder()
+      .onFile(new DefaultInputFile("src/Foo.php"))
+      .ruleKey(RuleKey.of("repo", "rule"))
+      .atLine(1)
+      .effortToFix(10.0)
+      .message("Wrong way!")
+      .build();
+
+    assertThat(issue.inputFile()).isEqualTo(new DefaultInputFile("src/Foo.php"));
+    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
+    assertThat(issue.line()).isEqualTo(1);
+    assertThat(issue.effortToFix()).isEqualTo(10.0);
+    assertThat(issue.message()).isEqualTo("Wrong way!");
+  }
+
+  @Test
+  public void build_project_issue() {
+    Issue issue = new DefaultIssueBuilder()
+      .onProject()
+      .ruleKey(RuleKey.of("repo", "rule"))
+      .atLine(1)
+      .effortToFix(10.0)
+      .message("Wrong way!")
+      .build();
+
+    assertThat(issue.inputFile()).isNull();
+    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
+    assertThat(issue.line()).isEqualTo(1);
+    assertThat(issue.effortToFix()).isEqualTo(10.0);
+    assertThat(issue.message()).isEqualTo("Wrong way!");
+  }
+
+  @Test
+  public void not_allowed_to_call_onFile_and_onProject() {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("onFile or onProject can be called only once");
+    new DefaultIssueBuilder()
+      .onProject()
+      .onFile(new DefaultInputFile("src/Foo.php"))
+      .ruleKey(RuleKey.of("repo", "rule"))
+      .atLine(1)
+      .effortToFix(10.0)
+      .message("Wrong way!")
+      .build();
+
+  }
+
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java
new file mode 100644 (file)
index 0000000..c75a316
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.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.fs.internal.DefaultInputFile;
+import org.sonar.api.measures.CoreMetrics;
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultMeasureTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void build_file_measure() {
+    Measure<Integer> issue = new DefaultMeasureBuilder<Integer>()
+      .forMetric(CoreMetrics.LINES)
+      .onFile(new DefaultInputFile("src/Foo.php"))
+      .withValue(3)
+      .build();
+
+    assertThat(issue.inputFile()).isEqualTo(new DefaultInputFile("src/Foo.php"));
+    assertThat(issue.metric()).isEqualTo(CoreMetrics.LINES);
+    assertThat(issue.value()).isEqualTo(3);
+  }
+
+  @Test
+  public void build_project_measure() {
+    Measure<Integer> issue = new DefaultMeasureBuilder<Integer>()
+      .forMetric(CoreMetrics.LINES)
+      .onProject()
+      .withValue(3)
+      .build();
+
+    assertThat(issue.inputFile()).isNull();
+    assertThat(issue.metric()).isEqualTo(CoreMetrics.LINES);
+    assertThat(issue.value()).isEqualTo(3);
+  }
+
+  @Test
+  public void not_allowed_to_call_onFile_and_onProject() {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("onFile or onProject can be called only once");
+    new DefaultMeasureBuilder<Integer>()
+      .onProject()
+      .onFile(new DefaultInputFile("src/Foo.php"))
+      .withValue(3)
+      .build();
+  }
+
+}