From b43267d5415759f54a1fba7bfd502fd5587ef0d9 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 21 Jul 2014 17:36:30 +0200 Subject: SONAR-5389 Rename Analyzer -> Sensor --- .../batch/mediumtest/AnalyzerMediumTester.java | 312 -------------------- .../sonar/batch/mediumtest/BatchMediumTester.java | 321 +++++++++++++++++++++ .../java/org/sonar/batch/scan/SensorWrapper.java | 2 +- .../org/sonar/batch/scan2/AnalyzersExecutor.java | 2 +- .../batch/mediumtest/fs/FileSystemMediumTest.java | 6 +- .../batch/mediumtest/issues/IssuesMediumTest.java | 6 +- .../mediumtest/measures/MeasuresMediumTest.java | 9 +- .../batch/mediumtest/xoo/plugin/XooPlugin.java | 4 +- .../mediumtest/xoo/plugin/lang/MeasureSensor.java | 11 +- .../xoo/plugin/lang/ScmActivitySensor.java | 2 +- .../xoo/plugin/rule/OneIssuePerLineAnalyzer.java | 72 ----- .../xoo/plugin/rule/OneIssuePerLineSensor.java | 72 +++++ 12 files changed, 413 insertions(+), 406 deletions(-) delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java create mode 100644 sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java create mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineSensor.java (limited to 'sonar-batch') diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java deleted file mode 100644 index 9a96da2b2aa..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java +++ /dev/null @@ -1,312 +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; - -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.bootstrap.ProjectReactor; -import org.sonar.api.batch.debt.internal.DefaultDebtModel; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.config.Settings; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Metric; -import org.sonar.api.platform.PluginMetadata; -import org.sonar.api.resources.Languages; -import org.sonar.batch.bootstrap.PluginsReferential; -import org.sonar.batch.bootstrapper.Batch; -import org.sonar.batch.bootstrapper.EnvironmentInformation; -import org.sonar.batch.protocol.input.ActiveRule; -import org.sonar.batch.protocol.input.ProjectReferentials; -import org.sonar.batch.referential.ProjectReferentialsLoader; -import org.sonar.batch.scan.filesystem.InputFileCache; -import org.sonar.batch.scan2.AnalyzerIssueCache; -import org.sonar.batch.scan2.AnalyzerMeasureCache; -import org.sonar.batch.scan2.ProjectScanContainer; -import org.sonar.batch.scan2.ScanTaskObserver; -import org.sonar.batch.settings.SettingsReferential; -import org.sonar.core.plugins.DefaultPluginMetadata; -import org.sonar.core.plugins.RemotePlugin; - -import java.io.File; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -public class AnalyzerMediumTester { - - private Batch batch; - - public static AnalyzerMediumTesterBuilder builder() { - return new AnalyzerMediumTesterBuilder().registerCoreMetrics(); - } - - public static class AnalyzerMediumTesterBuilder { - private final FakeProjectReferentialsLoader refProvider = new FakeProjectReferentialsLoader(); - private final FakeSettingsReferential settingsReferential = new FakeSettingsReferential(); - private final FackPluginsReferential pluginsReferential = new FackPluginsReferential(); - private final Map bootstrapProperties = new HashMap(); - - public AnalyzerMediumTester build() { - return new AnalyzerMediumTester(this); - } - - public AnalyzerMediumTesterBuilder registerPlugin(String pluginKey, File location) { - pluginsReferential.addPlugin(pluginKey, location); - return this; - } - - public AnalyzerMediumTesterBuilder registerPlugin(String pluginKey, SonarPlugin instance) { - pluginsReferential.addPlugin(pluginKey, instance); - return this; - } - - public AnalyzerMediumTesterBuilder registerCoreMetrics() { - for (Metric m : CoreMetrics.getMetrics()) { - registerMetric(m); - } - return this; - } - - public AnalyzerMediumTesterBuilder registerMetric(Metric metric) { - refProvider.add(metric); - return this; - } - - public AnalyzerMediumTesterBuilder addQProfile(String language, String name) { - refProvider.addQProfile(language, name); - return this; - } - - public AnalyzerMediumTesterBuilder addDefaultQProfile(String language, String name) { - addQProfile(language, name); - settingsReferential.globalSettings().put("sonar.profile." + language, name); - return this; - } - - public AnalyzerMediumTesterBuilder bootstrapProperties(Map props) { - bootstrapProperties.putAll(props); - return this; - } - - public AnalyzerMediumTesterBuilder activateRule(ActiveRule activeRule) { - refProvider.addActiveRule(activeRule); - return this; - } - - } - - public void start() { - batch.start(); - } - - public void stop() { - batch.stop(); - } - - private AnalyzerMediumTester(AnalyzerMediumTesterBuilder builder) { - batch = Batch.builder() - .setEnableLoggingConfiguration(true) - .addComponents( - new EnvironmentInformation("mediumTest", "1.0"), - builder.settingsReferential, - builder.pluginsReferential, - builder.refProvider, - new DefaultDebtModel()) - .setBootstrapProperties(builder.bootstrapProperties) - .build(); - } - - public TaskBuilder newTask() { - return new TaskBuilder(this); - } - - public TaskBuilder newScanTask(File sonarProps) { - Properties prop = new Properties(); - FileReader reader = null; - try { - reader = new FileReader(sonarProps); - prop.load(reader); - } catch (Exception e) { - throw new IllegalStateException("Unable to read configuration file", e); - } finally { - if (reader != null) { - IOUtils.closeQuietly(reader); - } - } - TaskBuilder builder = new TaskBuilder(this); - builder.property("sonar.task", "scan"); - builder.property("sonar.projectBaseDir", sonarProps.getParentFile().getAbsolutePath()); - for (Map.Entry entry : prop.entrySet()) { - builder.property(entry.getKey().toString(), entry.getValue().toString()); - } - return builder; - } - - public static class TaskBuilder { - private final Map taskProperties = new HashMap(); - private AnalyzerMediumTester tester; - - public TaskBuilder(AnalyzerMediumTester tester) { - this.tester = tester; - } - - public TaskResult start() { - TaskResult result = new TaskResult(); - tester.batch.executeTask(taskProperties, - result - ); - return result; - } - - public TaskBuilder properties(Map props) { - taskProperties.putAll(props); - return this; - } - - public TaskBuilder property(String key, String value) { - taskProperties.put(key, value); - return this; - } - } - - public static class TaskResult implements ScanTaskObserver { - private List issues = new ArrayList(); - private List measures = new ArrayList(); - private List inputFiles = new ArrayList(); - - @Override - public void scanTaskCompleted(ProjectScanContainer container) { - for (Issue issue : container.getComponentByType(AnalyzerIssueCache.class).all()) { - issues.add(issue); - } - - for (Measure measure : container.getComponentByType(AnalyzerMeasureCache.class).all()) { - measures.add(measure); - } - - InputFileCache inputFileCache = container.getComponentByType(InputFileCache.class); - for (InputFile inputFile : inputFileCache.all()) { - inputFiles.add(inputFile); - } - } - - public List issues() { - return issues; - } - - public List measures() { - return measures; - } - - public List inputFiles() { - return inputFiles; - } - - } - - private static class FakeProjectReferentialsLoader implements ProjectReferentialsLoader { - - private int metricId = 1; - - private ProjectReferentials ref = new ProjectReferentials(); - - @Override - public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) { - return ref; - } - - public FakeProjectReferentialsLoader addQProfile(String language, String name) { - ref.addQProfile(new org.sonar.batch.protocol.input.QProfile(name, name, language, new Date())); - return this; - } - - public FakeProjectReferentialsLoader add(Metric metric) { - ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId, metric.key(), metric.getType().name(), metric.getBestValue(), metric.isOptimizedBestValue())); - metricId++; - return this; - } - - public FakeProjectReferentialsLoader addActiveRule(ActiveRule activeRule) { - ref.addActiveRule(activeRule); - return this; - } - } - - private static class FakeSettingsReferential implements SettingsReferential { - - private Map globalSettings = new HashMap(); - private Map> projectSettings = new HashMap>(); - - @Override - public Map globalSettings() { - return globalSettings; - } - - @Override - public Map projectSettings(String projectKey) { - return projectSettings.containsKey(projectKey) ? projectSettings.get(projectKey) : Collections.emptyMap(); - } - - } - - private static class FackPluginsReferential implements PluginsReferential { - - private List pluginList = new ArrayList(); - private Map pluginFiles = new HashMap(); - Map localPlugins = new HashMap(); - - @Override - public List pluginList() { - return pluginList; - } - - @Override - public File pluginFile(RemotePlugin remote) { - return pluginFiles.get(remote); - } - - public FackPluginsReferential addPlugin(String pluginKey, File location) { - RemotePlugin plugin = new RemotePlugin(pluginKey, false); - pluginList.add(plugin); - pluginFiles.put(plugin, location); - return this; - } - - public FackPluginsReferential addPlugin(String pluginKey, SonarPlugin pluginInstance) { - localPlugins.put(DefaultPluginMetadata.create(null).setKey(pluginKey), pluginInstance); - return this; - } - - @Override - public Map localPlugins() { - return localPlugins; - } - - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java new file mode 100644 index 00000000000..70a509bb22f --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java @@ -0,0 +1,321 @@ +/* + * 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; + +import org.apache.commons.io.IOUtils; +import org.sonar.api.SonarPlugin; +import org.sonar.api.batch.bootstrap.ProjectReactor; +import org.sonar.api.batch.debt.internal.DefaultDebtModel; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.batch.sensor.measure.Measure; +import org.sonar.api.config.Settings; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Metric; +import org.sonar.api.platform.PluginMetadata; +import org.sonar.api.resources.Languages; +import org.sonar.batch.bootstrap.PluginsReferential; +import org.sonar.batch.bootstrapper.Batch; +import org.sonar.batch.bootstrapper.EnvironmentInformation; +import org.sonar.batch.protocol.input.ActiveRule; +import org.sonar.batch.protocol.input.ProjectReferentials; +import org.sonar.batch.referential.ProjectReferentialsLoader; +import org.sonar.batch.scan.filesystem.InputFileCache; +import org.sonar.batch.scan2.AnalyzerIssueCache; +import org.sonar.batch.scan2.AnalyzerMeasureCache; +import org.sonar.batch.scan2.ProjectScanContainer; +import org.sonar.batch.scan2.ScanTaskObserver; +import org.sonar.batch.settings.SettingsReferential; +import org.sonar.core.plugins.DefaultPluginMetadata; +import org.sonar.core.plugins.RemotePlugin; + +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +public class BatchMediumTester { + + private Batch batch; + + public static BatchMediumTesterBuilder builder() { + return new BatchMediumTesterBuilder().registerCoreMetrics(); + } + + public static class BatchMediumTesterBuilder { + private final FakeProjectReferentialsLoader refProvider = new FakeProjectReferentialsLoader(); + private final FakeSettingsReferential settingsReferential = new FakeSettingsReferential(); + private final FackPluginsReferential pluginsReferential = new FackPluginsReferential(); + private final Map bootstrapProperties = new HashMap(); + + public BatchMediumTester build() { + return new BatchMediumTester(this); + } + + public BatchMediumTesterBuilder registerPlugin(String pluginKey, File location) { + pluginsReferential.addPlugin(pluginKey, location); + return this; + } + + public BatchMediumTesterBuilder registerPlugin(String pluginKey, SonarPlugin instance) { + pluginsReferential.addPlugin(pluginKey, instance); + return this; + } + + public BatchMediumTesterBuilder registerCoreMetrics() { + for (Metric m : CoreMetrics.getMetrics()) { + registerMetric(m); + } + return this; + } + + public BatchMediumTesterBuilder registerMetric(Metric metric) { + refProvider.add(metric); + return this; + } + + public BatchMediumTesterBuilder addQProfile(String language, String name) { + refProvider.addQProfile(language, name); + return this; + } + + public BatchMediumTesterBuilder addDefaultQProfile(String language, String name) { + addQProfile(language, name); + settingsReferential.globalSettings().put("sonar.profile." + language, name); + return this; + } + + public BatchMediumTesterBuilder bootstrapProperties(Map props) { + bootstrapProperties.putAll(props); + return this; + } + + public BatchMediumTesterBuilder activateRule(ActiveRule activeRule) { + refProvider.addActiveRule(activeRule); + return this; + } + + } + + public void start() { + batch.start(); + } + + public void stop() { + batch.stop(); + } + + private BatchMediumTester(BatchMediumTesterBuilder builder) { + batch = Batch.builder() + .setEnableLoggingConfiguration(true) + .addComponents( + new EnvironmentInformation("mediumTest", "1.0"), + builder.settingsReferential, + builder.pluginsReferential, + builder.refProvider, + new DefaultDebtModel()) + .setBootstrapProperties(builder.bootstrapProperties) + .build(); + } + + public TaskBuilder newTask() { + return new TaskBuilder(this); + } + + public TaskBuilder newScanTask(File sonarProps) { + Properties prop = new Properties(); + FileReader reader = null; + try { + reader = new FileReader(sonarProps); + prop.load(reader); + } catch (Exception e) { + throw new IllegalStateException("Unable to read configuration file", e); + } finally { + if (reader != null) { + IOUtils.closeQuietly(reader); + } + } + TaskBuilder builder = new TaskBuilder(this); + builder.property("sonar.task", "scan"); + builder.property("sonar.projectBaseDir", sonarProps.getParentFile().getAbsolutePath()); + for (Map.Entry entry : prop.entrySet()) { + builder.property(entry.getKey().toString(), entry.getValue().toString()); + } + return builder; + } + + public static class TaskBuilder { + private final Map taskProperties = new HashMap(); + private BatchMediumTester tester; + + public TaskBuilder(BatchMediumTester tester) { + this.tester = tester; + } + + public TaskResult start() { + TaskResult result = new TaskResult(); + tester.batch.executeTask(taskProperties, + result + ); + return result; + } + + public TaskBuilder properties(Map props) { + taskProperties.putAll(props); + return this; + } + + public TaskBuilder property(String key, String value) { + taskProperties.put(key, value); + return this; + } + } + + public static class TaskResult implements ScanTaskObserver { + private List issues = new ArrayList(); + private List measures = new ArrayList(); + private List inputFiles = new ArrayList(); + + @Override + public void scanTaskCompleted(ProjectScanContainer container) { + for (Issue issue : container.getComponentByType(AnalyzerIssueCache.class).all()) { + issues.add(issue); + } + + for (Measure measure : container.getComponentByType(AnalyzerMeasureCache.class).all()) { + measures.add(measure); + } + + InputFileCache inputFileCache = container.getComponentByType(InputFileCache.class); + for (InputFile inputFile : inputFileCache.all()) { + inputFiles.add(inputFile); + } + } + + public List issues() { + return issues; + } + + public List measures() { + return measures; + } + + public List inputFiles() { + return inputFiles; + } + + } + + private static class FakeProjectReferentialsLoader implements ProjectReferentialsLoader { + + private int metricId = 1; + + private ProjectReferentials ref = new ProjectReferentials(); + + @Override + public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) { + return ref; + } + + public FakeProjectReferentialsLoader addQProfile(String language, String name) { + ref.addQProfile(new org.sonar.batch.protocol.input.QProfile(name, name, language, new Date())); + return this; + } + + public FakeProjectReferentialsLoader add(Metric metric) { + ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId, + metric.key(), + metric.getType().name(), + metric.getDescription(), + metric.getDirection(), + metric.getName(), + metric.getQualitative(), + metric.getUserManaged(), + metric.getWorstValue(), + metric.getBestValue(), + metric.isOptimizedBestValue())); + metricId++; + return this; + } + + public FakeProjectReferentialsLoader addActiveRule(ActiveRule activeRule) { + ref.addActiveRule(activeRule); + return this; + } + } + + private static class FakeSettingsReferential implements SettingsReferential { + + private Map globalSettings = new HashMap(); + private Map> projectSettings = new HashMap>(); + + @Override + public Map globalSettings() { + return globalSettings; + } + + @Override + public Map projectSettings(String projectKey) { + return projectSettings.containsKey(projectKey) ? projectSettings.get(projectKey) : Collections.emptyMap(); + } + + } + + private static class FackPluginsReferential implements PluginsReferential { + + private List pluginList = new ArrayList(); + private Map pluginFiles = new HashMap(); + Map localPlugins = new HashMap(); + + @Override + public List pluginList() { + return pluginList; + } + + @Override + public File pluginFile(RemotePlugin remote) { + return pluginFiles.get(remote); + } + + public FackPluginsReferential addPlugin(String pluginKey, File location) { + RemotePlugin plugin = new RemotePlugin(pluginKey, false); + pluginList.add(plugin); + pluginFiles.put(plugin, location); + return this; + } + + public FackPluginsReferential addPlugin(String pluginKey, SonarPlugin pluginInstance) { + localPlugins.put(DefaultPluginMetadata.create(null).setKey(pluginKey), pluginInstance); + return this; + } + + @Override + public Map localPlugins() { + return localPlugins; + } + + } + +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java index 617ade05f3f..4deeaa0cf97 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java @@ -63,6 +63,6 @@ public class SensorWrapper implements org.sonar.api.batch.Sensor { @Override public void analyse(Project module, org.sonar.api.batch.SensorContext context) { - analyzer.analyse(adaptor); + analyzer.execute(adaptor); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java index f8b8aef6c70..54e6b1397ac 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java @@ -63,7 +63,7 @@ public class AnalyzersExecutor implements BatchComponent { } private void executeSensor(SensorContext context, Sensor analyzer) { - analyzer.analyse(context); + analyzer.execute(context); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java index d572ef1b383..e2cbc4909de 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java @@ -29,8 +29,8 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.utils.MessageException; -import org.sonar.batch.mediumtest.AnalyzerMediumTester; -import org.sonar.batch.mediumtest.AnalyzerMediumTester.TaskResult; +import org.sonar.batch.mediumtest.BatchMediumTester; +import org.sonar.batch.mediumtest.BatchMediumTester.TaskResult; import org.sonar.batch.mediumtest.xoo.plugin.XooPlugin; import org.sonar.batch.protocol.input.ActiveRule; @@ -47,7 +47,7 @@ public class FileSystemMediumTest { @Rule public ExpectedException thrown = ExpectedException.none(); - public AnalyzerMediumTester tester = AnalyzerMediumTester.builder() + public BatchMediumTester tester = BatchMediumTester.builder() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") .activateRule(new ActiveRule("xoo", "OneIssuePerLine", "MAJOR", "xoo", "xoo")) diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java index 90ff20508fe..21705209b92 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java @@ -28,8 +28,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.batch.mediumtest.AnalyzerMediumTester; -import org.sonar.batch.mediumtest.AnalyzerMediumTester.TaskResult; +import org.sonar.batch.mediumtest.BatchMediumTester; +import org.sonar.batch.mediumtest.BatchMediumTester.TaskResult; import org.sonar.batch.mediumtest.xoo.plugin.XooPlugin; import org.sonar.batch.protocol.input.ActiveRule; @@ -43,7 +43,7 @@ public class IssuesMediumTest { @org.junit.Rule public TemporaryFolder temp = new TemporaryFolder(); - public AnalyzerMediumTester tester = AnalyzerMediumTester.builder() + public BatchMediumTester tester = BatchMediumTester.builder() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") .activateRule(new ActiveRule("xoo", "OneIssuePerLine", "MAJOR", "xoo", "xoo")) diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java index 975999bd352..bb93ae4b7ba 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java @@ -19,8 +19,6 @@ */ 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; @@ -28,9 +26,10 @@ import org.junit.Before; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.sensor.measure.internal.DefaultMeasureBuilder; import org.sonar.api.measures.CoreMetrics; -import org.sonar.batch.mediumtest.AnalyzerMediumTester; -import org.sonar.batch.mediumtest.AnalyzerMediumTester.TaskResult; +import org.sonar.batch.mediumtest.BatchMediumTester; +import org.sonar.batch.mediumtest.BatchMediumTester.TaskResult; import org.sonar.batch.mediumtest.xoo.plugin.XooPlugin; import java.io.File; @@ -43,7 +42,7 @@ public class MeasuresMediumTest { @org.junit.Rule public TemporaryFolder temp = new TemporaryFolder(); - public AnalyzerMediumTester tester = AnalyzerMediumTester.builder() + public BatchMediumTester tester = BatchMediumTester.builder() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") .bootstrapProperties(ImmutableMap.of("sonar.analysis.mode", "sensor")) diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java index 00bfc6b5a41..70e31407d60 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/XooPlugin.java @@ -23,7 +23,7 @@ import org.sonar.api.SonarPlugin; import org.sonar.batch.mediumtest.xoo.plugin.base.Xoo; 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 org.sonar.batch.mediumtest.xoo.plugin.rule.OneIssuePerLineSensor; import java.util.Arrays; import java.util.List; @@ -39,7 +39,7 @@ public final class XooPlugin extends SonarPlugin { Xoo.class, // rules - OneIssuePerLineAnalyzer.class + OneIssuePerLineSensor.class ); } } 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 index 2f56da1b7a8..9a4b46afd1a 100644 --- 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 @@ -19,16 +19,15 @@ */ 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.fs.InputFile; +import org.sonar.api.batch.measure.MetricFinder; 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; @@ -112,7 +111,7 @@ public class MeasureSensor implements Sensor { } @Override - public void analyse(SensorContext context) { + public void execute(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/ScmActivitySensor.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/lang/ScmActivitySensor.java index ecf05f862a2..b3352dba62a 100644 --- 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 @@ -67,7 +67,7 @@ public class ScmActivitySensor implements Sensor { } @Override - public void analyse(SensorContext context) { + public void execute(SensorContext context) { for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(Xoo.KEY))) { processFile(inputFile); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java deleted file mode 100644 index f55e7b7bb40..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineAnalyzer.java +++ /dev/null @@ -1,72 +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.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.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 Sensor { - - public static final String RULE_KEY = "OneIssuePerLine"; - private static final String EFFORT_TO_FIX_PROPERTY = "sonar.oneIssuePerLine.effortToFix"; - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor - .name("One Issue Per Line") - .dependsOn(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))) { - createIssues(file, context); - } - } - - private void createIssues(InputFile file, SensorContext context) { - RuleKey ruleKey = RuleKey.of(XooConstants.REPOSITORY_KEY, RULE_KEY); - Measure linesMeasure = context.getMeasure(file, CoreMetrics.LINES); - if (linesMeasure == null) { - LoggerFactory.getLogger(getClass()).warn("Missing measure " + CoreMetrics.LINES_KEY + " on " + file); - } else { - for (int line = 1; line <= (Integer) linesMeasure.value(); line++) { - context.addIssue(context.issueBuilder() - .ruleKey(ruleKey) - .onFile(file) - .atLine(line) - .effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)) - .message("This issue is generated on each line") - .build()); - } - } - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineSensor.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineSensor.java new file mode 100644 index 00000000000..65557983534 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/plugin/rule/OneIssuePerLineSensor.java @@ -0,0 +1,72 @@ +/* + * 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.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.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 OneIssuePerLineSensor implements Sensor { + + public static final String RULE_KEY = "OneIssuePerLine"; + private static final String EFFORT_TO_FIX_PROPERTY = "sonar.oneIssuePerLine.effortToFix"; + + @Override + public void describe(SensorDescriptor descriptor) { + descriptor + .name("One Issue Per Line") + .dependsOn(CoreMetrics.LINES) + .workOnLanguages(Xoo.KEY) + .workOnFileTypes(InputFile.Type.MAIN, InputFile.Type.TEST); + } + + @Override + public void execute(SensorContext context) { + for (InputFile file : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguages(Xoo.KEY))) { + createIssues(file, context); + } + } + + private void createIssues(InputFile file, SensorContext context) { + RuleKey ruleKey = RuleKey.of(XooConstants.REPOSITORY_KEY, RULE_KEY); + Measure linesMeasure = context.getMeasure(file, CoreMetrics.LINES); + if (linesMeasure == null) { + LoggerFactory.getLogger(getClass()).warn("Missing measure " + CoreMetrics.LINES_KEY + " on " + file); + } else { + for (int line = 1; line <= (Integer) linesMeasure.value(); line++) { + context.addIssue(context.issueBuilder() + .ruleKey(ruleKey) + .onFile(file) + .atLine(line) + .effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)) + .message("This issue is generated on each line") + .build()); + } + } + } +} -- cgit v1.2.3