import org.sonar.api.SonarProduct; | import org.sonar.api.SonarProduct; | ||||
import org.sonar.api.config.PropertyDefinition; | import org.sonar.api.config.PropertyDefinition; | ||||
import org.sonar.api.resources.Qualifiers; | import org.sonar.api.resources.Qualifiers; | ||||
import org.sonar.api.utils.Version; | |||||
import org.sonar.xoo.coverage.ItCoverageSensor; | import org.sonar.xoo.coverage.ItCoverageSensor; | ||||
import org.sonar.xoo.coverage.OverallCoverageSensor; | import org.sonar.xoo.coverage.OverallCoverageSensor; | ||||
import org.sonar.xoo.coverage.UtCoverageSensor; | import org.sonar.xoo.coverage.UtCoverageSensor; | ||||
import org.sonar.xoo.rule.NoSonarSensor; | import org.sonar.xoo.rule.NoSonarSensor; | ||||
import org.sonar.xoo.rule.OneBlockerIssuePerFileSensor; | import org.sonar.xoo.rule.OneBlockerIssuePerFileSensor; | ||||
import org.sonar.xoo.rule.OneBugIssuePerLineSensor; | 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.OneDayDebtPerFileSensor; | ||||
import org.sonar.xoo.rule.OneExternalIssuePerLineSensor; | import org.sonar.xoo.rule.OneExternalIssuePerLineSensor; | ||||
import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor; | import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor; | ||||
Xoo.class, | Xoo.class, | ||||
Xoo2.class, | Xoo2.class, | ||||
XooRulesDefinition.class, | XooRulesDefinition.class, | ||||
XooBuiltInQualityProfilesDefinition.class, | |||||
XooSonarWayProfile.class, | XooSonarWayProfile.class, | ||||
XooBasicProfile.class, | XooBasicProfile.class, | ||||
Xoo2SonarWayProfile.class, | Xoo2SonarWayProfile.class, | ||||
OneDayDebtPerFileSensor.class, | OneDayDebtPerFileSensor.class, | ||||
OneIssuePerFileSensor.class, | OneIssuePerFileSensor.class, | ||||
OneIssuePerTestFileSensor.class, | OneIssuePerTestFileSensor.class, | ||||
OneBugIssuePerTestLineSensor.class, | |||||
OneCodeSmellIssuePerTestLineSensor.class, | |||||
OneIssuePerDirectorySensor.class, | OneIssuePerDirectorySensor.class, | ||||
OneIssuePerModuleSensor.class, | OneIssuePerModuleSensor.class, | ||||
OneIssueOnDirPerFileSensor.class, | OneIssueOnDirPerFileSensor.class, | ||||
OneIssuePerUnknownFileSensor.class, | OneIssuePerUnknownFileSensor.class, | ||||
OneExternalIssuePerLineSensor.class, | |||||
OnePredefinedRuleExternalIssuePerLineSensor.class, | |||||
OnePredefinedAndAdHocRuleExternalIssuePerLineSensor.class, | |||||
CreateIssueByInternalKeySensor.class, | CreateIssueByInternalKeySensor.class, | ||||
MultilineIssuesSensor.class, | MultilineIssuesSensor.class, | ||||
CustomMessageSensor.class, | CustomMessageSensor.class, | ||||
OneBugIssuePerLineSensor.class, | OneBugIssuePerLineSensor.class, | ||||
OneCodeSmellIssuePerLineSensor.class, | |||||
OneVulnerabilityIssuePerModuleSensor.class, | OneVulnerabilityIssuePerModuleSensor.class, | ||||
DeprecatedGlobalSensor.class, | |||||
GlobalProjectSensor.class, | |||||
HotspotSensor.class, | |||||
// Coverage | // Coverage | ||||
UtCoverageSensor.class, | UtCoverageSensor.class, | ||||
ItCoverageSensor.class, | ItCoverageSensor.class, | ||||
// Other | // Other | ||||
XooProjectBuilder.class, | XooProjectBuilder.class, | ||||
XooPostJob.class, | XooPostJob.class, | ||||
XooIssueFilter.class); | |||||
XooIssueFilter.class, | |||||
XooIgnoreCommand.class, | |||||
SignificantCodeSensor.class); | |||||
if (context.getRuntime().getProduct() != SonarProduct.SONARLINT) { | if (context.getRuntime().getProduct() != SonarProduct.SONARLINT) { | ||||
context.addExtension(MeasureSensor.class); | 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); | |||||
} | |||||
} | } | ||||
} | } |
/* | |||||
* 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(); | |||||
} | |||||
} | |||||
} |
/* | |||||
* 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(); | |||||
} | |||||
} | |||||
} |
/* | |||||
* 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(); | |||||
} | |||||
} | |||||
} |
*/ | */ | ||||
package org.sonar.xoo.rule; | 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.FileSystem; | ||||
import org.sonar.api.batch.fs.InputFile; | import org.sonar.api.batch.fs.InputFile; | ||||
import org.sonar.api.batch.fs.InputFile.Type; | import org.sonar.api.batch.fs.InputFile.Type; | ||||
import org.sonar.api.batch.rule.ActiveRules; | 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.SensorContext; | ||||
import org.sonar.api.batch.sensor.SensorDescriptor; | import org.sonar.api.batch.sensor.SensorDescriptor; | ||||
import org.sonar.api.batch.sensor.issue.NewIssue; | import org.sonar.api.batch.sensor.issue.NewIssue; | ||||
import org.sonar.api.rule.RuleKey; | import org.sonar.api.rule.RuleKey; | ||||
import org.sonar.xoo.Xoo; | import org.sonar.xoo.Xoo; | ||||
public class OneIssuePerTestFileSensor extends AbstractXooRuleSensor { | |||||
public class OneIssuePerTestFileSensor implements Sensor { | |||||
public static final String RULE_KEY = "OneIssuePerTestFile"; | public static final String RULE_KEY = "OneIssuePerTestFile"; | ||||
private final FileSystem fs; | |||||
private final ActiveRules activeRules; | |||||
public OneIssuePerTestFileSensor(FileSystem fs, ActiveRules activeRules) { | public OneIssuePerTestFileSensor(FileSystem fs, ActiveRules activeRules) { | ||||
super(fs, activeRules); | |||||
this.fs = fs; | |||||
this.activeRules = activeRules; | |||||
} | } | ||||
@Override | @Override | ||||
protected String getRuleKey() { | |||||
return RULE_KEY; | |||||
public void describe(SensorDescriptor descriptor) { | |||||
descriptor | |||||
.onlyOnLanguage(Xoo.KEY) | |||||
.onlyOnFileType(Type.TEST) | |||||
.createIssuesForRuleRepository(XooRulesDefinition.XOO_REPOSITORY); | |||||
} | } | ||||
@Override | @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 newIssue = context.newIssue(); | ||||
newIssue | newIssue | ||||
.forRule(ruleKey) | .forRule(ruleKey) | ||||
.save(); | .save(); | ||||
} | } | ||||
@Override | |||||
public void describe(SensorDescriptor descriptor) { | |||||
descriptor | |||||
.onlyOnLanguage(Xoo.KEY) | |||||
.onlyOnFileType(Type.TEST) | |||||
.createIssuesForRuleRepository(XooRulesDefinition.XOO_REPOSITORY); | |||||
} | |||||
} | } |
NewRule oneIssuePerTestFile = repo.createRule(OneIssuePerTestFileSensor.RULE_KEY).setName("One Issue Per Test File") | NewRule oneIssuePerTestFile = repo.createRule(OneIssuePerTestFileSensor.RULE_KEY).setName("One Issue Per Test File") | ||||
.setScope(RuleScope.TEST) | .setScope(RuleScope.TEST) | ||||
.setHtmlDescription("Generate an issue on each test file"); | .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") | NewRule oneIssuePerDirectory = repo.createRule(OneIssuePerDirectorySensor.RULE_KEY).setName("One Issue Per Directory") | ||||
.setHtmlDescription("Generate an issue on each non-empty directory"); | .setHtmlDescription("Generate an issue on each non-empty directory"); | ||||
oneBugIssuePerLine | oneBugIssuePerLine | ||||
.setDebtRemediationFunction(oneBugIssuePerLine.debtRemediationFunctions().linear("5min")); | .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") | NewRule oneVulnerabilityIssuePerModule = repo.createRule(OneVulnerabilityIssuePerModuleSensor.RULE_KEY).setName("One Vulnerability Issue Per Module") | ||||
.setHtmlDescription("Generate an issue on each module") | .setHtmlDescription("Generate an issue on each module") | ||||
.setType(RuleType.VULNERABILITY); | .setType(RuleType.VULNERABILITY); |
package org.sonar.xoo; | package org.sonar.xoo; | ||||
import java.util.List; | import java.util.List; | ||||
import org.sonar.api.SonarEdition; | |||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonar.api.Plugin; | import org.sonar.api.Plugin; | ||||
import org.sonar.api.SonarEdition; | |||||
import org.sonar.api.SonarQubeSide; | import org.sonar.api.SonarQubeSide; | ||||
import org.sonar.api.SonarRuntime; | import org.sonar.api.SonarRuntime; | ||||
import org.sonar.api.internal.PluginContextImpl; | import org.sonar.api.internal.PluginContextImpl; | ||||
import org.sonar.api.internal.SonarRuntimeImpl; | import org.sonar.api.internal.SonarRuntimeImpl; | ||||
import org.sonar.api.utils.Version; | import org.sonar.api.utils.Version; | ||||
import org.sonar.xoo.global.GlobalProjectSensor; | 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 org.sonar.xoo.scm.XooIgnoreCommand; | ||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
public class XooPluginTest { | public class XooPluginTest { | ||||
@Test | @Test | ||||
public void provide_extensions_for_5_6() { | |||||
public void provide_extensions_for_sonar_lint() { | |||||
SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4")); | SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4")); | ||||
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); | Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); | ||||
new XooPlugin().define(context); | 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)) | assertThat(getExtensions(context)) | ||||
.hasSize(55) | |||||
.contains(OneExternalIssuePerLineSensor.class); | |||||
.isNotEmpty() | |||||
.doesNotContain(MeasureSensor.class); | |||||
} | } | ||||
@Test | @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(); | Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); | ||||
new XooPlugin().define(context); | 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)) | assertThat(getExtensions(context)) | ||||
.hasSize(58) | |||||
.isNotEmpty() | |||||
.contains(MeasureSensor.class) | |||||
.contains(GlobalProjectSensor.class) | .contains(GlobalProjectSensor.class) | ||||
.contains(XooIgnoreCommand.class); | .contains(XooIgnoreCommand.class); | ||||
} | } |
*/ | */ | ||||
package org.sonar.xoo.rule; | package org.sonar.xoo.rule; | ||||
import org.sonar.api.SonarEdition; | |||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonar.api.SonarEdition; | |||||
import org.sonar.api.SonarQubeSide; | import org.sonar.api.SonarQubeSide; | ||||
import org.sonar.api.impl.server.RulesDefinitionContext; | |||||
import org.sonar.api.internal.SonarRuntimeImpl; | import org.sonar.api.internal.SonarRuntimeImpl; | ||||
import org.sonar.api.server.debt.DebtRemediationFunction; | import org.sonar.api.server.debt.DebtRemediationFunction; | ||||
import org.sonar.api.server.rule.RulesDefinition; | import org.sonar.api.server.rule.RulesDefinition; | ||||
import org.sonar.api.utils.Version; | import org.sonar.api.utils.Version; | ||||
import org.sonar.api.impl.server.RulesDefinitionContext; | |||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
public class XooRulesDefinitionTest { | 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 | @Before | ||||
public void setUp() { | public void setUp() { | ||||
XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY)); | |||||
context = new RulesDefinitionContext(); | |||||
def.define(context); | def.define(context); | ||||
} | } | ||||
assertThat(repo).isNotNull(); | assertThat(repo).isNotNull(); | ||||
assertThat(repo.name()).isEqualTo("Xoo"); | assertThat(repo.name()).isEqualTo("Xoo"); | ||||
assertThat(repo.language()).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); | RulesDefinition.Rule rule = repo.rule(OneIssuePerLineSensor.RULE_KEY); | ||||
assertThat(rule.name()).isNotEmpty(); | assertThat(rule.name()).isNotEmpty(); | ||||
assertThat(repo).isNotNull(); | assertThat(repo).isNotNull(); | ||||
assertThat(repo.name()).isEqualTo("Xoo"); | assertThat(repo.name()).isEqualTo("Xoo"); | ||||
assertThat(repo.language()).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); | RulesDefinition.Rule rule = repo.rule(HotspotSensor.RULE_KEY); | ||||
assertThat(rule.name()).isNotEmpty(); | assertThat(rule.name()).isNotEmpty(); |