diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-02-05 16:59:48 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-02-08 13:41:00 +0100 |
commit | fc7ff3ff910868bd3e1032b21d79ba67edcf1abe (patch) | |
tree | 272b7e35b8aa156f831491fdee715222e5a565f0 /tests/plugins/foo-plugin-v1 | |
parent | e6dbc80a0d82fb12c9bd19cfdb68767484521d87 (diff) | |
download | sonarqube-fc7ff3ff910868bd3e1032b21d79ba67edcf1abe.tar.gz sonarqube-fc7ff3ff910868bd3e1032b21d79ba67edcf1abe.zip |
SONAR-10311 add IT on rule rekeying applying to issues
Diffstat (limited to 'tests/plugins/foo-plugin-v1')
-rw-r--r-- | tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/FooPlugin.java | 4 | ||||
-rw-r--r-- | tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/RekeyingRulesSensor.java | 54 |
2 files changed, 57 insertions, 1 deletions
diff --git a/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/FooPlugin.java b/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/FooPlugin.java index 673c8a002cd..c8c15a8ed3d 100644 --- a/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/FooPlugin.java +++ b/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/FooPlugin.java @@ -22,6 +22,7 @@ package org.sonar.foo; import org.sonar.api.Plugin; import org.sonar.foo.rule.FooBasicProfile; import org.sonar.foo.rule.FooRulesDefinition; +import org.sonar.foo.rule.RekeyingRulesSensor; /** * Plugin entry-point, as declared in pom.xml. @@ -33,7 +34,8 @@ public class FooPlugin implements Plugin { context.addExtensions( Foo.class, FooRulesDefinition.class, - FooBasicProfile.class); + FooBasicProfile.class, + RekeyingRulesSensor.class); } } diff --git a/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/RekeyingRulesSensor.java b/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/RekeyingRulesSensor.java new file mode 100644 index 00000000000..0e69550382b --- /dev/null +++ b/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/RekeyingRulesSensor.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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.foo.rule; + +import org.sonar.api.batch.fs.InputFile; +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.foo.Foo; + +import static org.sonar.foo.rule.FooRulesDefinition.FOO_REPOSITORY; + +public class RekeyingRulesSensor implements Sensor { + @Override + public void describe(SensorDescriptor descriptor) { + descriptor.createIssuesForRuleRepositories(FOO_REPOSITORY) + .onlyOnLanguage(Foo.KEY) + .name("Sensor generating one issue per Foo file for re-keyed rules"); + + } + + @Override + public void execute(SensorContext context) { + for (InputFile inputFile : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguage(Foo.KEY))) { + NewIssue newIssue = context.newIssue(); + newIssue.at(newIssue.newLocation().on(inputFile)) + .forRule(RuleKey.of(FOO_REPOSITORY, "ToBeRenamed")) + .save(); + newIssue = context.newIssue(); + newIssue.at(newIssue.newLocation().on(inputFile)) + .forRule(RuleKey.of(FOO_REPOSITORY, "ToBeRenamedAndMoved")) + .save(); + } + } +} |