From e068aa10a28ee89ad92af424be468fa057ccef6e Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 31 Aug 2020 12:25:35 +0200 Subject: [PATCH] Update Xoo plugin --- .../main/java/org/sonar/xoo/XooPlugin.java | 44 +++++----- .../rule/OneBugIssuePerTestLineSensor.java | 80 +++++++++++++++++++ .../rule/OneCodeSmellIssuePerLineSensor.java | 79 ++++++++++++++++++ .../OneCodeSmellIssuePerTestLineSensor.java | 80 +++++++++++++++++++ .../xoo/rule/OneIssuePerTestFileSensor.java | 39 ++++++--- .../sonar/xoo/rule/XooRulesDefinition.java | 22 ++++- .../java/org/sonar/xoo/XooPluginTest.java | 46 +++-------- .../xoo/rule/XooRulesDefinitionTest.java | 15 ++-- 8 files changed, 323 insertions(+), 82 deletions(-) create mode 100644 plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBugIssuePerTestLineSensor.java create mode 100644 plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneCodeSmellIssuePerLineSensor.java create mode 100644 plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneCodeSmellIssuePerTestLineSensor.java diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java index cb3bc1d7a36..b329ef992e9 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java @@ -24,7 +24,6 @@ import org.sonar.api.PropertyType; import org.sonar.api.SonarProduct; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.resources.Qualifiers; -import org.sonar.api.utils.Version; import org.sonar.xoo.coverage.ItCoverageSensor; import org.sonar.xoo.coverage.OverallCoverageSensor; import org.sonar.xoo.coverage.UtCoverageSensor; @@ -49,6 +48,9 @@ import org.sonar.xoo.rule.MultilineIssuesSensor; import org.sonar.xoo.rule.NoSonarSensor; import org.sonar.xoo.rule.OneBlockerIssuePerFileSensor; import org.sonar.xoo.rule.OneBugIssuePerLineSensor; +import org.sonar.xoo.rule.OneBugIssuePerTestLineSensor; +import org.sonar.xoo.rule.OneCodeSmellIssuePerLineSensor; +import org.sonar.xoo.rule.OneCodeSmellIssuePerTestLineSensor; import org.sonar.xoo.rule.OneDayDebtPerFileSensor; import org.sonar.xoo.rule.OneExternalIssuePerLineSensor; import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor; @@ -107,6 +109,7 @@ public class XooPlugin implements Plugin { Xoo.class, Xoo2.class, XooRulesDefinition.class, + XooBuiltInQualityProfilesDefinition.class, XooSonarWayProfile.class, XooBasicProfile.class, Xoo2SonarWayProfile.class, @@ -137,17 +140,30 @@ public class XooPlugin implements Plugin { OneDayDebtPerFileSensor.class, OneIssuePerFileSensor.class, OneIssuePerTestFileSensor.class, + OneBugIssuePerTestLineSensor.class, + OneCodeSmellIssuePerTestLineSensor.class, OneIssuePerDirectorySensor.class, OneIssuePerModuleSensor.class, OneIssueOnDirPerFileSensor.class, OneIssuePerUnknownFileSensor.class, + + OneExternalIssuePerLineSensor.class, + OnePredefinedRuleExternalIssuePerLineSensor.class, + OnePredefinedAndAdHocRuleExternalIssuePerLineSensor.class, + CreateIssueByInternalKeySensor.class, MultilineIssuesSensor.class, CustomMessageSensor.class, OneBugIssuePerLineSensor.class, + OneCodeSmellIssuePerLineSensor.class, OneVulnerabilityIssuePerModuleSensor.class, + DeprecatedGlobalSensor.class, + GlobalProjectSensor.class, + + HotspotSensor.class, + // Coverage UtCoverageSensor.class, ItCoverageSensor.class, @@ -163,33 +179,13 @@ public class XooPlugin implements Plugin { // Other XooProjectBuilder.class, XooPostJob.class, - XooIssueFilter.class); + XooIssueFilter.class, + XooIgnoreCommand.class, + SignificantCodeSensor.class); if (context.getRuntime().getProduct() != SonarProduct.SONARLINT) { context.addExtension(MeasureSensor.class); } - - if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 6))) { - context.addExtension(XooBuiltInQualityProfilesDefinition.class); - } - if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 4))) { - context.addExtension(DeprecatedGlobalSensor.class); - } - if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 6))) { - context.addExtensions( - GlobalProjectSensor.class, - XooIgnoreCommand.class); - } - if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 2))) { - context.addExtensions( - OneExternalIssuePerLineSensor.class, - OnePredefinedRuleExternalIssuePerLineSensor.class, - OnePredefinedAndAdHocRuleExternalIssuePerLineSensor.class, - SignificantCodeSensor.class); - } - if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 3))) { - context.addExtension(HotspotSensor.class); - } } } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBugIssuePerTestLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBugIssuePerTestLineSensor.java new file mode 100644 index 00000000000..50bcbf3c82e --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneBugIssuePerTestLineSensor.java @@ -0,0 +1,80 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.xoo.rule; + +import org.sonar.api.batch.fs.FilePredicates; +import org.sonar.api.batch.fs.FileSystem; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.TextRange; +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.issue.NewIssue; +import org.sonar.api.rule.RuleKey; +import org.sonar.xoo.Xoo; +import org.sonar.xoo.Xoo2; + +public class OneBugIssuePerTestLineSensor implements Sensor { + + public static final String RULE_KEY = "OneBugIssuePerTestLine"; + + @Override + public void describe(SensorDescriptor descriptor) { + descriptor + .name("One Bug Issue Per Line of Test File") + .onlyOnFileType(Type.TEST) + .onlyOnLanguages(Xoo.KEY, Xoo2.KEY) + .createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY, XooRulesDefinition.XOO2_REPOSITORY); + } + + @Override + public void execute(SensorContext context) { + analyse(context, Xoo.KEY, XooRulesDefinition.XOO_REPOSITORY); + } + + private void analyse(SensorContext context, String language, String repo) { + FileSystem fs = context.fileSystem(); + FilePredicates p = fs.predicates(); + for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(language), p.hasType(Type.TEST)))) { + createIssues(file, context, repo); + } + } + + private static void createIssues(InputFile file, SensorContext context, String repo) { + RuleKey ruleKey = RuleKey.of(repo, RULE_KEY); + for (int line = 1; line <= file.lines(); line++) { + TextRange text = file.selectLine(line); + // do not count empty lines, which can be a pain with end-of-file return + if (text.end().lineOffset() == 0) { + continue; + } + NewIssue newIssue = context.newIssue(); + newIssue + .forRule(ruleKey) + .at(newIssue.newLocation() + .on(file) + .at(text) + .message("This bug issue is generated on each line of a test file")) + .save(); + } + } + +} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneCodeSmellIssuePerLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneCodeSmellIssuePerLineSensor.java new file mode 100644 index 00000000000..3011a0182d6 --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneCodeSmellIssuePerLineSensor.java @@ -0,0 +1,79 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.xoo.rule; + +import org.sonar.api.batch.fs.FilePredicates; +import org.sonar.api.batch.fs.FileSystem; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.TextRange; +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.issue.NewIssue; +import org.sonar.api.rule.RuleKey; +import org.sonar.xoo.Xoo; +import org.sonar.xoo.Xoo2; + +public class OneCodeSmellIssuePerLineSensor implements Sensor { + + public static final String RULE_KEY = "OneCodeSmellIssuePerLine"; + + @Override + public void describe(SensorDescriptor descriptor) { + descriptor + .name("One Code Smell Issue Per Line") + .onlyOnLanguages(Xoo.KEY, Xoo2.KEY) + .createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY, XooRulesDefinition.XOO2_REPOSITORY); + } + + @Override + public void execute(SensorContext context) { + analyse(context, Xoo.KEY, XooRulesDefinition.XOO_REPOSITORY); + } + + private void analyse(SensorContext context, String language, String repo) { + FileSystem fs = context.fileSystem(); + FilePredicates p = fs.predicates(); + for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(language), p.hasType(Type.MAIN)))) { + createIssues(file, context, repo); + } + } + + private static void createIssues(InputFile file, SensorContext context, String repo) { + RuleKey ruleKey = RuleKey.of(repo, RULE_KEY); + for (int line = 1; line <= file.lines(); line++) { + TextRange text = file.selectLine(line); + // do not count empty lines, which can be a pain with end-of-file return + if (text.end().lineOffset() == 0) { + continue; + } + NewIssue newIssue = context.newIssue(); + newIssue + .forRule(ruleKey) + .at(newIssue.newLocation() + .on(file) + .at(text) + .message("This code smell issue is generated on each line")) + .save(); + } + } + +} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneCodeSmellIssuePerTestLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneCodeSmellIssuePerTestLineSensor.java new file mode 100644 index 00000000000..e434ca5b02d --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneCodeSmellIssuePerTestLineSensor.java @@ -0,0 +1,80 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.xoo.rule; + +import org.sonar.api.batch.fs.FilePredicates; +import org.sonar.api.batch.fs.FileSystem; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.TextRange; +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.issue.NewIssue; +import org.sonar.api.rule.RuleKey; +import org.sonar.xoo.Xoo; +import org.sonar.xoo.Xoo2; + +public class OneCodeSmellIssuePerTestLineSensor implements Sensor { + + public static final String RULE_KEY = "OneCodeSmellIssuePerTestLine"; + + @Override + public void describe(SensorDescriptor descriptor) { + descriptor + .name("One Code Smell Issue Per Line of Test File") + .onlyOnFileType(Type.TEST) + .onlyOnLanguages(Xoo.KEY, Xoo2.KEY) + .createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY, XooRulesDefinition.XOO2_REPOSITORY); + } + + @Override + public void execute(SensorContext context) { + analyse(context, Xoo.KEY, XooRulesDefinition.XOO_REPOSITORY); + } + + private void analyse(SensorContext context, String language, String repo) { + FileSystem fs = context.fileSystem(); + FilePredicates p = fs.predicates(); + for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(language), p.hasType(Type.TEST)))) { + createIssues(file, context, repo); + } + } + + private static void createIssues(InputFile file, SensorContext context, String repo) { + RuleKey ruleKey = RuleKey.of(repo, RULE_KEY); + for (int line = 1; line <= file.lines(); line++) { + TextRange text = file.selectLine(line); + // do not count empty lines, which can be a pain with end-of-file return + if (text.end().lineOffset() == 0) { + continue; + } + NewIssue newIssue = context.newIssue(); + newIssue + .forRule(ruleKey) + .at(newIssue.newLocation() + .on(file) + .at(text) + .message("This code smell issue is generated on each line of a test file")) + .save(); + } + } + +} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerTestFileSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerTestFileSensor.java index b1b589e6c79..5089923b60e 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerTestFileSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerTestFileSensor.java @@ -19,30 +19,51 @@ */ package org.sonar.xoo.rule; +import org.sonar.api.batch.fs.FilePredicates; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.rule.ActiveRules; +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.issue.NewIssue; import org.sonar.api.rule.RuleKey; import org.sonar.xoo.Xoo; -public class OneIssuePerTestFileSensor extends AbstractXooRuleSensor { +public class OneIssuePerTestFileSensor implements Sensor { + public static final String RULE_KEY = "OneIssuePerTestFile"; + private final FileSystem fs; + private final ActiveRules activeRules; + public OneIssuePerTestFileSensor(FileSystem fs, ActiveRules activeRules) { - super(fs, activeRules); + this.fs = fs; + this.activeRules = activeRules; } @Override - protected String getRuleKey() { - return RULE_KEY; + public void describe(SensorDescriptor descriptor) { + descriptor + .onlyOnLanguage(Xoo.KEY) + .onlyOnFileType(Type.TEST) + .createIssuesForRuleRepository(XooRulesDefinition.XOO_REPOSITORY); } @Override - protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) { + public void execute(SensorContext context) { + RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY); + if (activeRules.find(ruleKey) == null) { + return; + } + FilePredicates p = fs.predicates(); + for (InputFile inputFile : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.TEST)))) { + processFile(inputFile, context, ruleKey); + } + } + + private void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey) { NewIssue newIssue = context.newIssue(); newIssue .forRule(ruleKey) @@ -51,12 +72,4 @@ public class OneIssuePerTestFileSensor extends AbstractXooRuleSensor { .save(); } - @Override - public void describe(SensorDescriptor descriptor) { - descriptor - .onlyOnLanguage(Xoo.KEY) - .onlyOnFileType(Type.TEST) - .createIssuesForRuleRepository(XooRulesDefinition.XOO_REPOSITORY); - } - } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java index 6d91f1d758c..15453d26205 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java @@ -113,7 +113,21 @@ public class XooRulesDefinition implements RulesDefinition { NewRule oneIssuePerTestFile = repo.createRule(OneIssuePerTestFileSensor.RULE_KEY).setName("One Issue Per Test File") .setScope(RuleScope.TEST) .setHtmlDescription("Generate an issue on each test file"); - oneIssuePerTestFile.setDebtRemediationFunction(oneIssuePerTestFile.debtRemediationFunctions().linear(TEN_MIN)); + oneIssuePerTestFile.setDebtRemediationFunction(oneIssuePerTestFile.debtRemediationFunctions().linear("8min")); + + NewRule oneBugIssuePerTestLine = repo.createRule(OneBugIssuePerTestLineSensor.RULE_KEY).setName("One Bug Issue Per Test Line") + .setScope(RuleScope.TEST) + .setHtmlDescription("Generate a bug issue on each line of a test file. It requires the metric \"lines\".") + .setType(RuleType.BUG); + oneBugIssuePerTestLine + .setDebtRemediationFunction(oneBugIssuePerTestLine.debtRemediationFunctions().linear("4min")); + + NewRule oneCodeSmellIssuePerTestLine = repo.createRule(OneCodeSmellIssuePerTestLineSensor.RULE_KEY).setName("One Code Smell Issue Per Test Line") + .setScope(RuleScope.TEST) + .setHtmlDescription("Generate a code smell issue on each line of a test file. It requires the metric \"lines\".") + .setType(RuleType.CODE_SMELL); + oneCodeSmellIssuePerTestLine + .setDebtRemediationFunction(oneCodeSmellIssuePerTestLine.debtRemediationFunctions().linear("3min")); NewRule oneIssuePerDirectory = repo.createRule(OneIssuePerDirectorySensor.RULE_KEY).setName("One Issue Per Directory") .setHtmlDescription("Generate an issue on each non-empty directory"); @@ -151,6 +165,12 @@ public class XooRulesDefinition implements RulesDefinition { oneBugIssuePerLine .setDebtRemediationFunction(oneBugIssuePerLine.debtRemediationFunctions().linear("5min")); + NewRule oneCodeSmellIssuePerLine = repo.createRule(OneCodeSmellIssuePerLineSensor.RULE_KEY).setName("One Code Smell Issue Per Line") + .setHtmlDescription("Generate a code smell issue on each line of a file. It requires the metric \"lines\".") + .setType(RuleType.CODE_SMELL); + oneCodeSmellIssuePerLine + .setDebtRemediationFunction(oneBugIssuePerLine.debtRemediationFunctions().linear("9min")); + NewRule oneVulnerabilityIssuePerModule = repo.createRule(OneVulnerabilityIssuePerModuleSensor.RULE_KEY).setName("One Vulnerability Issue Per Module") .setHtmlDescription("Generate an issue on each module") .setType(RuleType.VULNERABILITY); diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java index 41e61e39832..f70cb8368a2 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java @@ -20,17 +20,16 @@ package org.sonar.xoo; import java.util.List; -import org.sonar.api.SonarEdition; import org.junit.Test; import org.sonar.api.Plugin; +import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; import org.sonar.api.SonarRuntime; import org.sonar.api.internal.PluginContextImpl; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; import org.sonar.xoo.global.GlobalProjectSensor; -import org.sonar.xoo.rule.OneExternalIssuePerLineSensor; -import org.sonar.xoo.rule.XooBuiltInQualityProfilesDefinition; +import org.sonar.xoo.lang.MeasureSensor; import org.sonar.xoo.scm.XooIgnoreCommand; import static org.assertj.core.api.Assertions.assertThat; @@ -38,52 +37,25 @@ import static org.assertj.core.api.Assertions.assertThat; public class XooPluginTest { @Test - public void provide_extensions_for_5_6() { + public void provide_extensions_for_sonar_lint() { SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4")); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); - assertThat(getExtensions(context)) - .hasSize(48) - .doesNotContain(XooBuiltInQualityProfilesDefinition.class); - } - - @Test - public void provide_extensions_for_6_6() { - SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.6"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY); - Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); - new XooPlugin().define(context); - assertThat(getExtensions(context)) - .hasSize(51) - .contains(XooBuiltInQualityProfilesDefinition.class); - } - @Test - public void provide_extensions_for_7_2() { - SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.2"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY); - Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); - new XooPlugin().define(context); assertThat(getExtensions(context)) - .hasSize(55) - .contains(OneExternalIssuePerLineSensor.class); + .isNotEmpty() + .doesNotContain(MeasureSensor.class); } @Test - public void provide_extensions_for_7_3() { - SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.3"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY); + public void provide_extensions_for_sonar_qube() { + SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("8.4"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); - assertThat(getExtensions(context)) - .hasSize(56) - .contains(OneExternalIssuePerLineSensor.class); - } - @Test - public void provide_extensions_for_7_6() { - SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.6"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY); - Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); - new XooPlugin().define(context); assertThat(getExtensions(context)) - .hasSize(58) + .isNotEmpty() + .contains(MeasureSensor.class) .contains(GlobalProjectSensor.class) .contains(XooIgnoreCommand.class); } diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java index 69c72e60f6d..447c57c0dcf 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java @@ -19,25 +19,26 @@ */ package org.sonar.xoo.rule; -import org.sonar.api.SonarEdition; import org.junit.Before; import org.junit.Test; +import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; +import org.sonar.api.impl.server.RulesDefinitionContext; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.rule.RulesDefinition; import org.sonar.api.utils.Version; -import org.sonar.api.impl.server.RulesDefinitionContext; import static org.assertj.core.api.Assertions.assertThat; public class XooRulesDefinitionTest { - RulesDefinition.Context context; + + private XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY)); + + private RulesDefinition.Context context = new RulesDefinitionContext(); @Before public void setUp() { - XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY)); - context = new RulesDefinitionContext(); def.define(context); } @@ -47,7 +48,7 @@ public class XooRulesDefinitionTest { assertThat(repo).isNotNull(); assertThat(repo.name()).isEqualTo("Xoo"); assertThat(repo.language()).isEqualTo("xoo"); - assertThat(repo.rules()).hasSize(19); + assertThat(repo.rules()).hasSize(22); RulesDefinition.Rule rule = repo.rule(OneIssuePerLineSensor.RULE_KEY); assertThat(rule.name()).isNotEmpty(); @@ -63,7 +64,7 @@ public class XooRulesDefinitionTest { assertThat(repo).isNotNull(); assertThat(repo.name()).isEqualTo("Xoo"); assertThat(repo.language()).isEqualTo("xoo"); - assertThat(repo.rules()).hasSize(19); + assertThat(repo.rules()).hasSize(22); RulesDefinition.Rule rule = repo.rule(HotspotSensor.RULE_KEY); assertThat(rule.name()).isNotEmpty(); -- 2.39.5