aboutsummaryrefslogtreecommitdiffstats
path: root/it/it-plugins/batch-plugin
diff options
context:
space:
mode:
Diffstat (limited to 'it/it-plugins/batch-plugin')
-rw-r--r--it/it-plugins/batch-plugin/pom.xml38
-rw-r--r--it/it-plugins/batch-plugin/src/main/java/com/sonarsource/BatchPlugin.java17
-rw-r--r--it/it-plugins/batch-plugin/src/main/java/com/sonarsource/DumpSettingsInitializer.java43
-rw-r--r--it/it-plugins/batch-plugin/src/main/java/com/sonarsource/RaiseMessageException.java26
-rw-r--r--it/it-plugins/batch-plugin/src/main/java/com/sonarsource/TempFolderExtension.java41
5 files changed, 165 insertions, 0 deletions
diff --git a/it/it-plugins/batch-plugin/pom.xml b/it/it-plugins/batch-plugin/pom.xml
new file mode 100644
index 00000000000..ceb46b9862e
--- /dev/null
+++ b/it/it-plugins/batch-plugin/pom.xml
@@ -0,0 +1,38 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.sonarsource.it</groupId>
+ <artifactId>it-plugins</artifactId>
+ <version>5.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>batch-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>sonar-plugin</packaging>
+ <name>SonarQube Integration Tests :: Plugins :: Batch</name>
+ <description>Main plugin for batch tests</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ <version>${apiVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-packaging-maven-plugin</artifactId>
+ <version>1.12.1</version>
+ <extensions>true</extensions>
+ <configuration>
+ <pluginClass>com.sonarsource.BatchPlugin</pluginClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/BatchPlugin.java b/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/BatchPlugin.java
new file mode 100644
index 00000000000..422e9186a1d
--- /dev/null
+++ b/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/BatchPlugin.java
@@ -0,0 +1,17 @@
+package com.sonarsource;
+
+import java.util.Arrays;
+import java.util.List;
+import org.sonar.api.SonarPlugin;
+
+public class BatchPlugin extends SonarPlugin {
+
+ public List getExtensions() {
+ return Arrays.asList(
+ DumpSettingsInitializer.class,
+ RaiseMessageException.class,
+ TempFolderExtension.class
+ );
+ }
+
+}
diff --git a/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/DumpSettingsInitializer.java b/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/DumpSettingsInitializer.java
new file mode 100644
index 00000000000..14aff204d20
--- /dev/null
+++ b/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/DumpSettingsInitializer.java
@@ -0,0 +1,43 @@
+package com.sonarsource;
+
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.PropertyType;
+import org.sonar.api.batch.Initializer;
+import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Project;
+
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+@Properties({
+ @Property(
+ key = DumpSettingsInitializer.SONAR_SHOW_SETTINGS,
+ type = PropertyType.BOOLEAN,
+ name = "Property to decide if it should output settings",
+ defaultValue = "false")
+})
+public class DumpSettingsInitializer extends Initializer {
+
+ public static final String SONAR_SHOW_SETTINGS = "sonar.showSettings";
+ private Settings settings;
+
+ public DumpSettingsInitializer(Settings settings) {
+ this.settings = settings;
+ }
+
+ @Override
+ public boolean shouldExecuteOnProject(Project project) {
+ return true;
+ }
+
+ @Override
+ public void execute(Project project) {
+ if (settings.getBoolean(SONAR_SHOW_SETTINGS)) {
+ TreeMap<String, String> treemap = new TreeMap<String, String>(settings.getProperties());
+ for (Entry<String, String> prop : treemap.entrySet()) {
+ System.out.println(" o " + project.getKey() + ":" + prop.getKey() + " = " + prop.getValue());
+ }
+ }
+ }
+}
diff --git a/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/RaiseMessageException.java b/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/RaiseMessageException.java
new file mode 100644
index 00000000000..9abc2982b3d
--- /dev/null
+++ b/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/RaiseMessageException.java
@@ -0,0 +1,26 @@
+package com.sonarsource;
+
+import org.sonar.api.batch.Sensor;
+import org.sonar.api.batch.SensorContext;
+import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Project;
+import org.sonar.api.utils.MessageException;
+
+public class RaiseMessageException implements Sensor {
+
+ private final Settings settings;
+
+ public RaiseMessageException(Settings settings) {
+ this.settings = settings;
+ }
+
+ @Override
+ public boolean shouldExecuteOnProject(Project project) {
+ return settings.getBoolean("raiseMessageException");
+ }
+
+ @Override
+ public void analyse(Project project, SensorContext sensorContext) {
+ throw MessageException.of("Error message from plugin");
+ }
+} \ No newline at end of file
diff --git a/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/TempFolderExtension.java b/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/TempFolderExtension.java
new file mode 100644
index 00000000000..72773dd4124
--- /dev/null
+++ b/it/it-plugins/batch-plugin/src/main/java/com/sonarsource/TempFolderExtension.java
@@ -0,0 +1,41 @@
+package com.sonarsource;
+
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.PropertyType;
+import org.sonar.api.batch.Initializer;
+import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Project;
+import org.sonar.api.utils.TempFolder;
+
+@Properties({
+ @Property(
+ key = TempFolderExtension.CREATE_TEMP_FILES,
+ type = PropertyType.BOOLEAN,
+ name = "Property to decide if it should create temp files",
+ defaultValue = "false")
+})
+public class TempFolderExtension extends Initializer {
+
+ public static final String CREATE_TEMP_FILES = "sonar.createTempFiles";
+ private Settings settings;
+ private TempFolder tempFolder;
+
+ public TempFolderExtension(Settings settings, TempFolder tempFolder) {
+ this.settings = settings;
+ this.tempFolder = tempFolder;
+ }
+
+ @Override
+ public boolean shouldExecuteOnProject(Project project) {
+ return true;
+ }
+
+ @Override
+ public void execute(Project project) {
+ if (settings.getBoolean(CREATE_TEMP_FILES)) {
+ System.out.println("Creating temp directory: " + tempFolder.newDir("sonar-it").getAbsolutePath());
+ System.out.println("Creating temp file: " + tempFolder.newFile("sonar-it", ".txt").getAbsolutePath());
+ }
+ }
+}