diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-01-29 09:55:50 +0100 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-02-07 11:32:38 +0100 |
commit | e019c97d3173c44402c4f38e9acca8d579f4816d (patch) | |
tree | 58695fd7800cbd87584562177cb6418d6e7e745b /plugins | |
parent | 4e1b01c0139c80bba0c8b1075010394fe4eeb3d4 (diff) | |
download | sonarqube-e019c97d3173c44402c4f38e9acca8d579f4816d.tar.gz sonarqube-e019c97d3173c44402c4f38e9acca8d579f4816d.zip |
SONAR-10321 Add scope field to rule search ws
Diffstat (limited to 'plugins')
3 files changed, 55 insertions, 2 deletions
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 099b08b0713..97e59ef3156 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 @@ -53,6 +53,7 @@ import org.sonar.xoo.rule.OneIssuePerDirectorySensor; import org.sonar.xoo.rule.OneIssuePerFileSensor; import org.sonar.xoo.rule.OneIssuePerLineSensor; import org.sonar.xoo.rule.OneIssuePerModuleSensor; +import org.sonar.xoo.rule.OneIssuePerTestFileSensor; import org.sonar.xoo.rule.OneIssuePerUnknownFileSensor; import org.sonar.xoo.rule.OneVulnerabilityIssuePerModuleSensor; import org.sonar.xoo.rule.RandomAccessSensor; @@ -127,6 +128,7 @@ public class XooPlugin implements Plugin { OneIssuePerLineSensor.class, OneDayDebtPerFileSensor.class, OneIssuePerFileSensor.class, + OneIssuePerTestFileSensor.class, OneIssuePerDirectorySensor.class, OneIssuePerModuleSensor.class, OneIssueOnDirPerFileSensor.class, 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 new file mode 100644 index 00000000000..09d09bb850b --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerTestFileSensor.java @@ -0,0 +1,43 @@ +package org.sonar.xoo.rule; + +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.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 static final String RULE_KEY = "OneIssuePerTestFile"; + + public OneIssuePerTestFileSensor(FileSystem fs, ActiveRules activeRules) { + super(fs, activeRules); + } + + @Override + protected String getRuleKey() { + return RULE_KEY; + } + + @Override + protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) { + NewIssue newIssue = context.newIssue(); + newIssue + .forRule(ruleKey) + .at(newIssue.newLocation().message("This issue is generated on each test file") + .on(inputFile)) + .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 afab06245d7..13c238cae7a 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 @@ -19,6 +19,7 @@ */ package org.sonar.xoo.rule; +import org.sonar.api.rule.RuleScope; import org.sonar.api.rules.RuleType; import org.sonar.api.server.rule.RuleParamType; import org.sonar.api.server.rule.RulesDefinition; @@ -35,6 +36,8 @@ public class XooRulesDefinition implements RulesDefinition { public static final String XOO_REPOSITORY = "xoo"; public static final String XOO2_REPOSITORY = "xoo2"; + private static final String TEN_MIN = "10min"; + @Override public void define(Context context) { defineRulesXoo(context); @@ -89,11 +92,16 @@ public class XooRulesDefinition implements RulesDefinition { NewRule oneIssuePerFile = repo.createRule(OneIssuePerFileSensor.RULE_KEY).setName("One Issue Per File") .setHtmlDescription("Generate an issue on each file"); - oneIssuePerFile.setDebtRemediationFunction(oneIssuePerFile.debtRemediationFunctions().linear("10min")); + oneIssuePerFile.setDebtRemediationFunction(oneIssuePerFile.debtRemediationFunctions().linear(TEN_MIN)); + + 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)); NewRule oneIssuePerDirectory = repo.createRule(OneIssuePerDirectorySensor.RULE_KEY).setName("One Issue Per Directory") .setHtmlDescription("Generate an issue on each non-empty directory"); - oneIssuePerFile.setDebtRemediationFunction(oneIssuePerDirectory.debtRemediationFunctions().linear("10min")); + oneIssuePerDirectory.setDebtRemediationFunction(oneIssuePerDirectory.debtRemediationFunctions().linear(TEN_MIN)); NewRule oneDayDebtPerFile = repo.createRule(OneDayDebtPerFileSensor.RULE_KEY).setName("One Day Debt Per File") .setHtmlDescription("Generate an issue on each file with a debt of one day"); |