From 0d4d37faf7a8c7e1c252c24c286d830802cfbb7b Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 10 Aug 2017 12:02:19 +0200 Subject: SONAR-9664 Add IT for custom rules backdating --- tests/plugins/backdating-customplugin/pom.xml | 82 ++++++++++++++++++++++ .../sonar/backdating/custom/BackdatingPlugin.java | 38 ++++++++++ .../org/sonar/backdating/custom/package-info.java | 23 ++++++ .../custom/rule/CustomRulesDefinition.java | 44 ++++++++++++ .../backdating/custom/rule/MyCustomProcessor.java | 40 +++++++++++ .../sonar/backdating/custom/rule/package-info.java | 23 ++++++ tests/plugins/backdating-plugin-v1/pom.xml | 2 +- .../org/sonar/backdating/BackdatingPlugin.java | 38 ---------- .../java/org/sonar/backdating/package-info.java | 23 ------ .../sonar/backdating/rule/BackRulesDefinition.java | 44 ------------ .../org/sonar/backdating/rule/BackSensorV1.java | 63 ----------------- .../org/sonar/backdating/rule/package-info.java | 23 ------ .../sonar/plugins/backdating/BackdatingPlugin.java | 38 ++++++++++ .../plugins/backdating/api/CustomProcessor.java | 31 ++++++++ .../org/sonar/plugins/backdating/package-info.java | 23 ++++++ .../backdating/rule/BackRulesDefinition.java | 44 ++++++++++++ .../plugins/backdating/rule/BackSensorV1.java | 63 +++++++++++++++++ .../plugins/backdating/rule/package-info.java | 23 ++++++ tests/plugins/backdating-plugin-v2/pom.xml | 2 +- .../org/sonar/backdating/BackdatingPlugin.java | 38 ---------- .../java/org/sonar/backdating/package-info.java | 23 ------ .../sonar/backdating/rule/BackRulesDefinition.java | 44 ------------ .../org/sonar/backdating/rule/BackSensorV2.java | 63 ----------------- .../org/sonar/backdating/rule/package-info.java | 23 ------ .../sonar/plugins/backdating/BackdatingPlugin.java | 38 ++++++++++ .../plugins/backdating/api/CustomProcessor.java | 31 ++++++++ .../org/sonar/plugins/backdating/package-info.java | 23 ++++++ .../backdating/rule/BackRulesDefinition.java | 44 ++++++++++++ .../plugins/backdating/rule/BackSensorV2.java | 77 ++++++++++++++++++++ .../plugins/backdating/rule/package-info.java | 23 ++++++ tests/plugins/pom.xml | 1 + .../src/main/xoo/sample/Sample.xoo | 5 +- .../src/main/xoo/sample/Sample.xoo.scm | 1 + .../issue/IssueCreationDatePluginChangedTest.java | 8 ++- .../one-rule.xml | 11 --- .../IssueCreationDatePluginChangedTest/profile.xml | 16 +++++ 36 files changed, 736 insertions(+), 400 deletions(-) create mode 100644 tests/plugins/backdating-customplugin/pom.xml create mode 100644 tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/BackdatingPlugin.java create mode 100644 tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/package-info.java create mode 100644 tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/CustomRulesDefinition.java create mode 100644 tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/MyCustomProcessor.java create mode 100644 tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/package-info.java delete mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/BackdatingPlugin.java delete mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/package-info.java delete mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java delete mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackSensorV1.java delete mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/package-info.java create mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java create mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java create mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/package-info.java create mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java create mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV1.java create mode 100644 tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/package-info.java delete mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/BackdatingPlugin.java delete mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/package-info.java delete mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java delete mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackSensorV2.java delete mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/package-info.java create mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java create mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java create mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/package-info.java create mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java create mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV2.java create mode 100644 tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/package-info.java delete mode 100644 tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/one-rule.xml create mode 100644 tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml diff --git a/tests/plugins/backdating-customplugin/pom.xml b/tests/plugins/backdating-customplugin/pom.xml new file mode 100644 index 00000000000..8371451ba88 --- /dev/null +++ b/tests/plugins/backdating-customplugin/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + org.sonarsource.sonarqube + sonarqube + 6.6-SNAPSHOT + ../.. + + backdating-customplugin + SonarQube :: Plugins :: Backdating (custom) + sonar-plugin + Sample of custom rule plugin to test issue backdating + + + true + + + + + com.google.guava + guava + + + commons-io + commons-io + + + commons-lang + commons-lang + + + com.google.code.findbugs + jsr305 + provided + + + org.sonarsource.sonarqube + sonar-plugin-api + provided + + + org.sonarsource.sonarqube + backdating-plugin-v1 + ${project.version} + provided + + + + + junit + junit + test + + + org.assertj + assertj-core + test + + + org.mockito + mockito-core + test + + + + + + + org.sonarsource.sonar-packaging-maven-plugin + sonar-packaging-maven-plugin + + custombackdating + Custom + backdating + org.sonar.backdating.custom.BackdatingPlugin + + + + + diff --git a/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/BackdatingPlugin.java b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/BackdatingPlugin.java new file mode 100644 index 00000000000..e6b24bc1bab --- /dev/null +++ b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/BackdatingPlugin.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.backdating.custom; + +import org.sonar.api.Plugin; +import org.sonar.backdating.custom.rule.CustomRulesDefinition; +import org.sonar.backdating.custom.rule.MyCustomProcessor; + +/** + * Plugin entry-point, as declared in pom.xml. + */ +public class BackdatingPlugin implements Plugin { + + @Override + public void define(Context context) { + context.addExtensions( + CustomRulesDefinition.class, + MyCustomProcessor.class); + } + +} diff --git a/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/package-info.java b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/package-info.java new file mode 100644 index 00000000000..9bc11a1358c --- /dev/null +++ b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.backdating.custom; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/CustomRulesDefinition.java b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/CustomRulesDefinition.java new file mode 100644 index 00000000000..3e338fd6734 --- /dev/null +++ b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/CustomRulesDefinition.java @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.backdating.custom.rule; + +import org.sonar.api.server.rule.RulesDefinition; + +public class CustomRulesDefinition implements RulesDefinition { + + public static final String RULE_KEY = "Custom"; + public static final String BACK_REPOSITORY = "back"; + + @Override + public void define(Context context) { + defineRulesXoo(context); + } + + private static void defineRulesXoo(Context context) { + NewRepository repo = context.createRepository(BACK_REPOSITORY, "xoo"); + createRule(repo, RULE_KEY); + repo.done(); + } + + private static NewRule createRule(NewRepository repo, String key) { + return repo.createRule(key).setName(key).setHtmlDescription(key); + } + +} diff --git a/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/MyCustomProcessor.java b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/MyCustomProcessor.java new file mode 100644 index 00000000000..981c7f7777c --- /dev/null +++ b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/MyCustomProcessor.java @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.backdating.custom.rule; + +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.sensor.SensorContext; +import org.sonar.api.batch.sensor.issue.NewIssue; +import org.sonar.api.rule.RuleKey; +import org.sonar.plugins.backdating.api.CustomProcessor; + +public class MyCustomProcessor implements CustomProcessor { + + @Override + public void process(String lineContent, SensorContext context, InputFile inputFile, int line) { + if (lineContent.contains("BACKCUSTOM")) { + NewIssue newIssue = context.newIssue(); + newIssue.at(newIssue.newLocation().on(inputFile).at(inputFile.selectLine(line))) + .forRule(RuleKey.of(CustomRulesDefinition.BACK_REPOSITORY, CustomRulesDefinition.RULE_KEY)) + .save(); + } + } + +} diff --git a/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/package-info.java b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/package-info.java new file mode 100644 index 00000000000..a5239fe6992 --- /dev/null +++ b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.backdating.custom.rule; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-plugin-v1/pom.xml b/tests/plugins/backdating-plugin-v1/pom.xml index 34cee6c1ca4..85a241daf31 100644 --- a/tests/plugins/backdating-plugin-v1/pom.xml +++ b/tests/plugins/backdating-plugin-v1/pom.xml @@ -67,7 +67,7 @@ backdating Foo - org.sonar.backdating.BackdatingPlugin + org.sonar.plugins.backdating.BackdatingPlugin diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/BackdatingPlugin.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/BackdatingPlugin.java deleted file mode 100644 index 57152b85726..00000000000 --- a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/BackdatingPlugin.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.backdating; - -import org.sonar.api.Plugin; -import org.sonar.backdating.rule.BackRulesDefinition; -import org.sonar.backdating.rule.BackSensorV1; - -/** - * Plugin entry-point, as declared in pom.xml. - */ -public class BackdatingPlugin implements Plugin { - - @Override - public void define(Context context) { - context.addExtensions( - BackRulesDefinition.class, - BackSensorV1.class); - } - -} diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/package-info.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/package-info.java deleted file mode 100644 index 7ed72718c44..00000000000 --- a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.backdating; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java deleted file mode 100644 index d7fe20f2a5d..00000000000 --- a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.backdating.rule; - -import org.sonar.api.server.rule.RulesDefinition; - -public class BackRulesDefinition implements RulesDefinition { - - public static final String RULE_KEY = "Rule"; - public static final String BACK_REPOSITORY = "back"; - - @Override - public void define(Context context) { - defineRulesXoo(context); - } - - private static void defineRulesXoo(Context context) { - NewRepository repo = context.createRepository(BACK_REPOSITORY, "xoo").setName("Back"); - createRule(repo, RULE_KEY); - repo.done(); - } - - private static NewRule createRule(NewRepository repo, String key) { - return repo.createRule(key).setName(key).setHtmlDescription(key); - } - -} diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackSensorV1.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackSensorV1.java deleted file mode 100644 index 51cf7a0c671..00000000000 --- a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackSensorV1.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.backdating.rule; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.StringReader; -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; - -public class BackSensorV1 implements Sensor { - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor.createIssuesForRuleRepositories(BackRulesDefinition.BACK_REPOSITORY) - .onlyOnLanguage("xoo") - .name("Back V1"); - } - - @Override - public void execute(SensorContext context) { - for (InputFile inputFile : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguage("xoo"))) { - int lineNb = 0; - try { - BufferedReader reader = new BufferedReader(new StringReader(inputFile.contents())); - String line; - while ((line = reader.readLine()) != null) { - lineNb++; - if (line.contains("BACKV1")) { - NewIssue newIssue = context.newIssue(); - newIssue.at(newIssue.newLocation().on(inputFile).at(inputFile.selectLine(lineNb))) - .forRule(RuleKey.of(BackRulesDefinition.BACK_REPOSITORY, BackRulesDefinition.RULE_KEY)) - .save(); - } - } - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - } - -} diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/package-info.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/package-info.java deleted file mode 100644 index 02d0eb7fe6f..00000000000 --- a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.backdating.rule; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java new file mode 100644 index 00000000000..b28c1c98eba --- /dev/null +++ b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.plugins.backdating; + +import org.sonar.api.Plugin; +import org.sonar.plugins.backdating.rule.BackRulesDefinition; +import org.sonar.plugins.backdating.rule.BackSensorV1; + +/** + * Plugin entry-point, as declared in pom.xml. + */ +public class BackdatingPlugin implements Plugin { + + @Override + public void define(Context context) { + context.addExtensions( + BackRulesDefinition.class, + BackSensorV1.class); + } + +} diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java new file mode 100644 index 00000000000..2ad47d4af24 --- /dev/null +++ b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.plugins.backdating.api; + +import org.sonar.api.batch.ScannerSide; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.sensor.SensorContext; + +@ScannerSide +public interface CustomProcessor { + + void process(String lineContent, SensorContext context, InputFile inputFile, int line); + +} diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/package-info.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/package-info.java new file mode 100644 index 00000000000..293300416ac --- /dev/null +++ b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.plugins.backdating; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java new file mode 100644 index 00000000000..85715b16e35 --- /dev/null +++ b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.plugins.backdating.rule; + +import org.sonar.api.server.rule.RulesDefinition; + +public class BackRulesDefinition implements RulesDefinition { + + public static final String RULE_KEY = "Rule"; + public static final String BACK_REPOSITORY = "back"; + + @Override + public void define(Context context) { + defineRulesXoo(context); + } + + private static void defineRulesXoo(Context context) { + NewRepository repo = context.createRepository(BACK_REPOSITORY, "xoo").setName("Back"); + createRule(repo, RULE_KEY); + repo.done(); + } + + private static NewRule createRule(NewRepository repo, String key) { + return repo.createRule(key).setName(key).setHtmlDescription(key); + } + +} diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV1.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV1.java new file mode 100644 index 00000000000..48eab7da30c --- /dev/null +++ b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV1.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.plugins.backdating.rule; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +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; + +public class BackSensorV1 implements Sensor { + + @Override + public void describe(SensorDescriptor descriptor) { + descriptor.createIssuesForRuleRepositories(BackRulesDefinition.BACK_REPOSITORY) + .onlyOnLanguage("xoo") + .name("Back V1"); + } + + @Override + public void execute(SensorContext context) { + for (InputFile inputFile : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguage("xoo"))) { + int lineNb = 0; + try { + BufferedReader reader = new BufferedReader(new StringReader(inputFile.contents())); + String line; + while ((line = reader.readLine()) != null) { + lineNb++; + if (line.contains("BACKV1")) { + NewIssue newIssue = context.newIssue(); + newIssue.at(newIssue.newLocation().on(inputFile).at(inputFile.selectLine(lineNb))) + .forRule(RuleKey.of(BackRulesDefinition.BACK_REPOSITORY, BackRulesDefinition.RULE_KEY)) + .save(); + } + } + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + } + +} diff --git a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/package-info.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/package-info.java new file mode 100644 index 00000000000..4a1857f5ce2 --- /dev/null +++ b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.plugins.backdating.rule; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-plugin-v2/pom.xml b/tests/plugins/backdating-plugin-v2/pom.xml index 9736566f83c..59adfffc20d 100644 --- a/tests/plugins/backdating-plugin-v2/pom.xml +++ b/tests/plugins/backdating-plugin-v2/pom.xml @@ -67,7 +67,7 @@ backdating Foo - org.sonar.backdating.BackdatingPlugin + org.sonar.plugins.backdating.BackdatingPlugin diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/BackdatingPlugin.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/BackdatingPlugin.java deleted file mode 100644 index b79527ccf45..00000000000 --- a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/BackdatingPlugin.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.backdating; - -import org.sonar.api.Plugin; -import org.sonar.backdating.rule.BackRulesDefinition; -import org.sonar.backdating.rule.BackSensorV2; - -/** - * Plugin entry-point, as declared in pom.xml. - */ -public class BackdatingPlugin implements Plugin { - - @Override - public void define(Context context) { - context.addExtensions( - BackRulesDefinition.class, - BackSensorV2.class); - } - -} diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/package-info.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/package-info.java deleted file mode 100644 index 7ed72718c44..00000000000 --- a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.backdating; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java deleted file mode 100644 index d7fe20f2a5d..00000000000 --- a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.backdating.rule; - -import org.sonar.api.server.rule.RulesDefinition; - -public class BackRulesDefinition implements RulesDefinition { - - public static final String RULE_KEY = "Rule"; - public static final String BACK_REPOSITORY = "back"; - - @Override - public void define(Context context) { - defineRulesXoo(context); - } - - private static void defineRulesXoo(Context context) { - NewRepository repo = context.createRepository(BACK_REPOSITORY, "xoo").setName("Back"); - createRule(repo, RULE_KEY); - repo.done(); - } - - private static NewRule createRule(NewRepository repo, String key) { - return repo.createRule(key).setName(key).setHtmlDescription(key); - } - -} diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackSensorV2.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackSensorV2.java deleted file mode 100644 index 82864f9a28a..00000000000 --- a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackSensorV2.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.backdating.rule; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.StringReader; -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; - -public class BackSensorV2 implements Sensor { - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor.createIssuesForRuleRepositories(BackRulesDefinition.BACK_REPOSITORY) - .onlyOnLanguage("xoo") - .name("Back V2"); - } - - @Override - public void execute(SensorContext context) { - for (InputFile inputFile : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguage("xoo"))) { - int lineNb = 0; - try { - BufferedReader reader = new BufferedReader(new StringReader(inputFile.contents())); - String line; - while ((line = reader.readLine()) != null) { - lineNb++; - if (line.contains("BACKV1") || line.contains("BACKV2")) { - NewIssue newIssue = context.newIssue(); - newIssue.at(newIssue.newLocation().on(inputFile).at(inputFile.selectLine(lineNb))) - .forRule(RuleKey.of(BackRulesDefinition.BACK_REPOSITORY, BackRulesDefinition.RULE_KEY)) - .save(); - } - } - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - } - -} diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/package-info.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/package-info.java deleted file mode 100644 index 02d0eb7fe6f..00000000000 --- a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.backdating.rule; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java new file mode 100644 index 00000000000..ee65cdbad86 --- /dev/null +++ b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.plugins.backdating; + +import org.sonar.api.Plugin; +import org.sonar.plugins.backdating.rule.BackRulesDefinition; +import org.sonar.plugins.backdating.rule.BackSensorV2; + +/** + * Plugin entry-point, as declared in pom.xml. + */ +public class BackdatingPlugin implements Plugin { + + @Override + public void define(Context context) { + context.addExtensions( + BackRulesDefinition.class, + BackSensorV2.class); + } + +} diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java new file mode 100644 index 00000000000..2ad47d4af24 --- /dev/null +++ b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.plugins.backdating.api; + +import org.sonar.api.batch.ScannerSide; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.sensor.SensorContext; + +@ScannerSide +public interface CustomProcessor { + + void process(String lineContent, SensorContext context, InputFile inputFile, int line); + +} diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/package-info.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/package-info.java new file mode 100644 index 00000000000..293300416ac --- /dev/null +++ b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.plugins.backdating; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java new file mode 100644 index 00000000000..85715b16e35 --- /dev/null +++ b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.plugins.backdating.rule; + +import org.sonar.api.server.rule.RulesDefinition; + +public class BackRulesDefinition implements RulesDefinition { + + public static final String RULE_KEY = "Rule"; + public static final String BACK_REPOSITORY = "back"; + + @Override + public void define(Context context) { + defineRulesXoo(context); + } + + private static void defineRulesXoo(Context context) { + NewRepository repo = context.createRepository(BACK_REPOSITORY, "xoo").setName("Back"); + createRule(repo, RULE_KEY); + repo.done(); + } + + private static NewRule createRule(NewRepository repo, String key) { + return repo.createRule(key).setName(key).setHtmlDescription(key); + } + +} diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV2.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV2.java new file mode 100644 index 00000000000..3e827b3e23c --- /dev/null +++ b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV2.java @@ -0,0 +1,77 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.plugins.backdating.rule; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +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.plugins.backdating.api.CustomProcessor; + +public class BackSensorV2 implements Sensor { + + private final CustomProcessor[] processors; + + public BackSensorV2() { + this(new CustomProcessor[0]); + } + + public BackSensorV2(CustomProcessor... processors) { + this.processors = processors; + } + + @Override + public void describe(SensorDescriptor descriptor) { + descriptor.createIssuesForRuleRepositories(BackRulesDefinition.BACK_REPOSITORY) + .onlyOnLanguage("xoo") + .name("Back V2"); + } + + @Override + public void execute(SensorContext context) { + for (InputFile inputFile : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguage("xoo"))) { + int lineNb = 0; + try { + BufferedReader reader = new BufferedReader(new StringReader(inputFile.contents())); + String line; + while ((line = reader.readLine()) != null) { + lineNb++; + if (line.contains("BACKV1") || line.contains("BACKV2")) { + NewIssue newIssue = context.newIssue(); + newIssue.at(newIssue.newLocation().on(inputFile).at(inputFile.selectLine(lineNb))) + .forRule(RuleKey.of(BackRulesDefinition.BACK_REPOSITORY, BackRulesDefinition.RULE_KEY)) + .save(); + } + for (CustomProcessor processor : processors) { + processor.process(line, context, inputFile, lineNb); + } + } + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + } + +} diff --git a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/package-info.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/package-info.java new file mode 100644 index 00000000000..4a1857f5ce2 --- /dev/null +++ b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.plugins.backdating.rule; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/tests/plugins/pom.xml b/tests/plugins/pom.xml index 7ba2dfebd1b..70015985e6b 100644 --- a/tests/plugins/pom.xml +++ b/tests/plugins/pom.xml @@ -63,5 +63,6 @@ ws-plugin backdating-plugin-v1 backdating-plugin-v2 + backdating-customplugin diff --git a/tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo b/tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo index 879889f64bd..ed059c9883f 100644 --- a/tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo +++ b/tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo @@ -1,2 +1,3 @@ -BACKV1 -BACKV2 \ No newline at end of file +BACKV1 // Raise issue when back plugin V1 is installed +BACKV2 // Raise issue when back plugin V2 is installed +BACKCUSTOM // Raise issue when custom plugin is installed, but only when back plugin is updated to V2 \ No newline at end of file diff --git a/tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo.scm b/tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo.scm index 9f3bb6c0dcb..74478d22334 100644 --- a/tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo.scm +++ b/tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo.scm @@ -1,2 +1,3 @@ 1,jhenry,2005-01-01T00:00:00+0000 1,jhenry,2005-01-01T00:00:00+0000 +1,jhenry,2005-01-01T00:00:00+0000 diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java index e5bd0a3d55c..98ab45d77d3 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java @@ -59,6 +59,7 @@ public class IssueCreationDatePluginChangedTest { public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() .addPlugin(xooPlugin()) .addPlugin(ItUtils.pluginArtifact("backdating-plugin-v1")) + .addPlugin(ItUtils.pluginArtifact("backdating-customplugin")) .build(); @Before @@ -68,7 +69,7 @@ public class IssueCreationDatePluginChangedTest { @Test public void should_use_scm_date_for_new_issues_if_plugin_updated() { - ItUtils.restoreProfile(ORCHESTRATOR, getClass().getResource("/issue/IssueCreationDatePluginChangedTest/one-rule.xml")); + ItUtils.restoreProfile(ORCHESTRATOR, getClass().getResource("/issue/IssueCreationDatePluginChangedTest/profile.xml")); ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_NAME); ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, LANGUAGE_XOO, SAMPLE_QUALITY_PROFILE_NAME); @@ -95,13 +96,14 @@ public class IssueCreationDatePluginChangedTest { ORCHESTRATOR.restartServer(); - // New analysis that should raise a new issue + // New analysis that should raise 2 new issues that will be backdated ORCHESTRATOR.executeBuild(scanner); issues = getIssues(issueQuery().components("creation-date-sample:src/main/xoo/sample/Sample.xoo")); assertThat(issues) .extracting(Issue::line, Issue::creationDate) .containsExactly(tuple(1, dateTimeParse("2005-01-01T00:00:00+0000")), - tuple(2, dateTimeParse("2005-01-01T00:00:00+0000"))); + tuple(2, dateTimeParse("2005-01-01T00:00:00+0000")), + tuple(3, dateTimeParse("2005-01-01T00:00:00+0000"))); } private static List getIssues(IssueQuery query) { diff --git a/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/one-rule.xml b/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/one-rule.xml deleted file mode 100644 index 8857d01b00f..00000000000 --- a/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/one-rule.xml +++ /dev/null @@ -1,11 +0,0 @@ - - creation-date-plugin - xoo - - - back - Rule - MAJOR - - - diff --git a/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml b/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml new file mode 100644 index 00000000000..2d5d3461c2f --- /dev/null +++ b/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml @@ -0,0 +1,16 @@ + + creation-date-plugin + xoo + + + back + Rule + MAJOR + + + back + Custom + MAJOR + + + -- cgit v1.2.3