diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-10 12:02:19 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-09-07 08:33:31 +0200 |
commit | 0d4d37faf7a8c7e1c252c24c286d830802cfbb7b (patch) | |
tree | ef2f98d6e33b1eb3133553307664f696630b54e3 | |
parent | 4f2c55e5f60c9c8108730a50e59c74344c5c195f (diff) | |
download | sonarqube-0d4d37faf7a8c7e1c252c24c286d830802cfbb7b.tar.gz sonarqube-0d4d37faf7a8c7e1c252c24c286d830802cfbb7b.zip |
SONAR-9664 Add IT for custom rules backdating
25 files changed, 357 insertions, 21 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.sonarsource.sonarqube</groupId> + <artifactId>sonarqube</artifactId> + <version>6.6-SNAPSHOT</version> + <relativePath>../..</relativePath> + </parent> + <artifactId>backdating-customplugin</artifactId> + <name>SonarQube :: Plugins :: Backdating (custom)</name> + <packaging>sonar-plugin</packaging> + <description>Sample of custom rule plugin to test issue backdating</description> + + <properties> + <sonar.skip>true</sonar.skip> + </properties> + + <dependencies> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + <dependency> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.sonarsource.sonarqube</groupId> + <artifactId>sonar-plugin-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.sonarsource.sonarqube</groupId> + <artifactId>backdating-plugin-v1</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + + <!-- unit testing --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId> + <artifactId>sonar-packaging-maven-plugin</artifactId> + <configuration> + <pluginKey>custombackdating</pluginKey> + <pluginName>Custom</pluginName> + <basePlugin>backdating</basePlugin> + <pluginClass>org.sonar.backdating.custom.BackdatingPlugin</pluginClass> + </configuration> + </plugin> + </plugins> + </build> +</project> 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-plugin-v2/src/main/java/org/sonar/backdating/package-info.java b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/package-info.java index 7ed72718c44..9bc11a1358c 100644 --- a/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/package-info.java +++ b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/package-info.java @@ -18,6 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.backdating; +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-plugin-v1/src/main/java/org/sonar/backdating/rule/package-info.java b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/package-info.java index 02d0eb7fe6f..a5239fe6992 100644 --- a/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/package-info.java +++ b/tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/package-info.java @@ -18,6 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.backdating.rule; +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 @@ <configuration> <pluginKey>backdating</pluginKey> <pluginName>Foo</pluginName> - <pluginClass>org.sonar.backdating.BackdatingPlugin</pluginClass> + <pluginClass>org.sonar.plugins.backdating.BackdatingPlugin</pluginClass> </configuration> </plugin> </plugins> 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/plugins/backdating/BackdatingPlugin.java index 57152b85726..b28c1c98eba 100644 --- 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/plugins/backdating/BackdatingPlugin.java @@ -17,11 +17,11 @@ * 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; +package org.sonar.plugins.backdating; import org.sonar.api.Plugin; -import org.sonar.backdating.rule.BackRulesDefinition; -import org.sonar.backdating.rule.BackSensorV1; +import org.sonar.plugins.backdating.rule.BackRulesDefinition; +import org.sonar.plugins.backdating.rule.BackSensorV1; /** * Plugin entry-point, as declared in pom.xml. 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/backdating/package-info.java b/tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/package-info.java index 7ed72718c44..293300416ac 100644 --- 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/plugins/backdating/package-info.java @@ -18,6 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.backdating; +package org.sonar.plugins.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/plugins/backdating/rule/BackRulesDefinition.java index d7fe20f2a5d..85715b16e35 100644 --- 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/plugins/backdating/rule/BackRulesDefinition.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.plugins.backdating.rule; import org.sonar.api.server.rule.RulesDefinition; 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/plugins/backdating/rule/BackSensorV1.java index 51cf7a0c671..48eab7da30c 100644 --- 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/plugins/backdating/rule/BackSensorV1.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.plugins.backdating.rule; import java.io.BufferedReader; import java.io.IOException; 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 @@ <configuration> <pluginKey>backdating</pluginKey> <pluginName>Foo</pluginName> - <pluginClass>org.sonar.backdating.BackdatingPlugin</pluginClass> + <pluginClass>org.sonar.plugins.backdating.BackdatingPlugin</pluginClass> </configuration> </plugin> </plugins> 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/plugins/backdating/BackdatingPlugin.java index b79527ccf45..ee65cdbad86 100644 --- 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/plugins/backdating/BackdatingPlugin.java @@ -17,11 +17,11 @@ * 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; +package org.sonar.plugins.backdating; import org.sonar.api.Plugin; -import org.sonar.backdating.rule.BackRulesDefinition; -import org.sonar.backdating.rule.BackSensorV2; +import org.sonar.plugins.backdating.rule.BackRulesDefinition; +import org.sonar.plugins.backdating.rule.BackSensorV2; /** * Plugin entry-point, as declared in pom.xml. 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/backdating/rule/package-info.java b/tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/package-info.java index 02d0eb7fe6f..293300416ac 100644 --- 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/plugins/backdating/package-info.java @@ -18,6 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.backdating.rule; +package org.sonar.plugins.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/plugins/backdating/rule/BackRulesDefinition.java index d7fe20f2a5d..85715b16e35 100644 --- 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/plugins/backdating/rule/BackRulesDefinition.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.plugins.backdating.rule; import org.sonar.api.server.rule.RulesDefinition; 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/plugins/backdating/rule/BackSensorV2.java index 82864f9a28a..3e827b3e23c 100644 --- 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/plugins/backdating/rule/BackSensorV2.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.plugins.backdating.rule; import java.io.BufferedReader; import java.io.IOException; @@ -28,9 +28,20 @@ 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) @@ -53,6 +64,9 @@ public class BackSensorV2 implements Sensor { .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 @@ <module>ws-plugin</module> <module>backdating-plugin-v1</module> <module>backdating-plugin-v2</module> + <module>backdating-customplugin</module> </modules> </project> 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<Issue> getIssues(IssueQuery query) { diff --git a/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/one-rule.xml b/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml index 8857d01b00f..2d5d3461c2f 100644 --- a/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/one-rule.xml +++ b/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml @@ -7,5 +7,10 @@ <key>Rule</key> <priority>MAJOR</priority> </rule> + <rule> + <repositoryKey>back</repositoryKey> + <key>Custom</key> + <priority>MAJOR</priority> + </rule> </rules> </profile> |