]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9664 Add IT for custom rules backdating
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 10 Aug 2017 10:02:19 +0000 (12:02 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 7 Sep 2017 06:33:31 +0000 (08:33 +0200)
36 files changed:
tests/plugins/backdating-customplugin/pom.xml [new file with mode: 0644]
tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/BackdatingPlugin.java [new file with mode: 0644]
tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/package-info.java [new file with mode: 0644]
tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/CustomRulesDefinition.java [new file with mode: 0644]
tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/MyCustomProcessor.java [new file with mode: 0644]
tests/plugins/backdating-customplugin/src/main/java/org/sonar/backdating/custom/rule/package-info.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v1/pom.xml
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/BackdatingPlugin.java [deleted file]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/package-info.java [deleted file]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java [deleted file]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/BackSensorV1.java [deleted file]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/backdating/rule/package-info.java [deleted file]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/package-info.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV1.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v1/src/main/java/org/sonar/plugins/backdating/rule/package-info.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v2/pom.xml
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/BackdatingPlugin.java [deleted file]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/package-info.java [deleted file]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackRulesDefinition.java [deleted file]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/BackSensorV2.java [deleted file]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/backdating/rule/package-info.java [deleted file]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/BackdatingPlugin.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/api/CustomProcessor.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/package-info.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackRulesDefinition.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/BackSensorV2.java [new file with mode: 0644]
tests/plugins/backdating-plugin-v2/src/main/java/org/sonar/plugins/backdating/rule/package-info.java [new file with mode: 0644]
tests/plugins/pom.xml
tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo
tests/projects/issue/creationDatePluginChanged/src/main/xoo/sample/Sample.xoo.scm
tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java
tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/one-rule.xml [deleted file]
tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml [new file with mode: 0644]

diff --git a/tests/plugins/backdating-customplugin/pom.xml b/tests/plugins/backdating-customplugin/pom.xml
new file mode 100644 (file)
index 0000000..8371451
--- /dev/null
@@ -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 (file)
index 0000000..e6b24bc
--- /dev/null
@@ -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 (file)
index 0000000..9bc11a1
--- /dev/null
@@ -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 (file)
index 0000000..3e338fd
--- /dev/null
@@ -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 (file)
index 0000000..981c7f7
--- /dev/null
@@ -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 (file)
index 0000000..a5239fe
--- /dev/null
@@ -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;
index 34cee6c1ca45df5469a86a39984d0c657c4f1924..85a241daf313e09cea40ac0f9af3be8456bd2fbe 100644 (file)
@@ -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/backdating/BackdatingPlugin.java
deleted file mode 100644 (file)
index 57152b8..0000000
+++ /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 (file)
index 7ed7271..0000000
+++ /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 (file)
index d7fe20f..0000000
+++ /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 (file)
index 51cf7a0..0000000
+++ /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 (file)
index 02d0eb7..0000000
+++ /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 (file)
index 0000000..b28c1c9
--- /dev/null
@@ -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 (file)
index 0000000..2ad47d4
--- /dev/null
@@ -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 (file)
index 0000000..2933004
--- /dev/null
@@ -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 (file)
index 0000000..85715b1
--- /dev/null
@@ -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 (file)
index 0000000..48eab7d
--- /dev/null
@@ -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 (file)
index 0000000..4a1857f
--- /dev/null
@@ -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;
index 9736566f83c83acda40cfd8c0bd8fc27b62efd8c..59adfffc20d5e96bbfc541e17f0056b990d42df8 100644 (file)
@@ -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/backdating/BackdatingPlugin.java
deleted file mode 100644 (file)
index b79527c..0000000
+++ /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 (file)
index 7ed7271..0000000
+++ /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 (file)
index d7fe20f..0000000
+++ /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 (file)
index 82864f9..0000000
+++ /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 (file)
index 02d0eb7..0000000
+++ /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 (file)
index 0000000..ee65cdb
--- /dev/null
@@ -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 (file)
index 0000000..2ad47d4
--- /dev/null
@@ -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 (file)
index 0000000..2933004
--- /dev/null
@@ -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 (file)
index 0000000..85715b1
--- /dev/null
@@ -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 (file)
index 0000000..3e827b3
--- /dev/null
@@ -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 (file)
index 0000000..4a1857f
--- /dev/null
@@ -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;
index 7ba2dfebd1b7c74bc473146076890e3f17416599..70015985e6b71f3f31848b3d094047dc6155d096 100644 (file)
@@ -63,5 +63,6 @@
     <module>ws-plugin</module>
     <module>backdating-plugin-v1</module>
     <module>backdating-plugin-v2</module>
+    <module>backdating-customplugin</module>
   </modules>
 </project>
index 879889f64bdd2597fcfa4ab66464255accd682c1..ed059c9883f4d5a9f562160e90986bf3af7835a1 100644 (file)
@@ -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
index 9f3bb6c0dcb5a54cd26daaf3375d552e4af22f97..74478d22334fe38ad5a0a135b6987be8af4ab9d9 100644 (file)
@@ -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
index e5bd0a3d55c24e04332000dfa462ce5302bf3282..98ab45d77d334901369a12a168d32a67bd7956a5 100644 (file)
@@ -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/one-rule.xml
deleted file mode 100644 (file)
index 8857d01..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<profile>
-  <name>creation-date-plugin</name>
-  <language>xoo</language>
-  <rules>
-    <rule>
-      <repositoryKey>back</repositoryKey>
-      <key>Rule</key>
-      <priority>MAJOR</priority>
-    </rule>
-  </rules>
-</profile>
diff --git a/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml b/tests/src/test/resources/issue/IssueCreationDatePluginChangedTest/profile.xml
new file mode 100644 (file)
index 0000000..2d5d346
--- /dev/null
@@ -0,0 +1,16 @@
+<profile>
+  <name>creation-date-plugin</name>
+  <language>xoo</language>
+  <rules>
+    <rule>
+      <repositoryKey>back</repositoryKey>
+      <key>Rule</key>
+      <priority>MAJOR</priority>
+    </rule>
+    <rule>
+      <repositoryKey>back</repositoryKey>
+      <key>Custom</key>
+      <priority>MAJOR</priority>
+    </rule>
+  </rules>
+</profile>