aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-03-16 15:35:26 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-06-03 12:09:14 +0200
commit5dd7b6e298dde08601a09a5acc11e215961a6c63 (patch)
tree5ed9dcead7a21020a1ad7988e40f29106debc8a5 /plugins
parent4490f3161107ad197c736125c2ca551a1525c7d8 (diff)
downloadsonarqube-5dd7b6e298dde08601a09a5acc11e215961a6c63.tar.gz
sonarqube-5dd7b6e298dde08601a09a5acc11e215961a6c63.zip
SONAR-3821 Drop any Maven dependency
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-batch-maven-plugin/pom.xml53
-rw-r--r--plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenBatchPlugin.java34
-rw-r--r--plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenProjectBuilder.java64
3 files changed, 151 insertions, 0 deletions
diff --git a/plugins/sonar-batch-maven-plugin/pom.xml b/plugins/sonar-batch-maven-plugin/pom.xml
new file mode 100644
index 00000000000..1905981221a
--- /dev/null
+++ b/plugins/sonar-batch-maven-plugin/pom.xml
@@ -0,0 +1,53 @@
+<?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.codehaus.sonar</groupId>
+ <artifactId>sonar</artifactId>
+ <version>5.2-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+
+ <groupId>org.codehaus.sonar.plugins</groupId>
+ <artifactId>sonar-batch-maven-plugin</artifactId>
+ <name>SonarQube :: Batch Maven Plugin</name>
+ <packaging>sonar-plugin</packaging>
+ <description>Inject MavenProject in each module.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-packaging-maven-plugin</artifactId>
+ <configuration>
+ <pluginKey>mavenbatch</pluginKey>
+ <pluginName>Maven Batch</pluginName>
+ <pluginClass>org.sonar.plugins.batch.maven.MavenBatchPlugin</pluginClass>
+ <pluginDescription>
+ <![CDATA[Inject MavenProject in each module.]]></pluginDescription>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenBatchPlugin.java b/plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenBatchPlugin.java
new file mode 100644
index 00000000000..5fd1c17484d
--- /dev/null
+++ b/plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenBatchPlugin.java
@@ -0,0 +1,34 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.batch.maven;
+
+import org.sonar.api.SonarPlugin;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class MavenBatchPlugin extends SonarPlugin {
+
+ @Override
+ public List getExtensions() {
+ return Arrays.asList(MavenProjectBuilder.class);
+ }
+
+}
diff --git a/plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenProjectBuilder.java b/plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenProjectBuilder.java
new file mode 100644
index 00000000000..6efa5cbfc37
--- /dev/null
+++ b/plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenProjectBuilder.java
@@ -0,0 +1,64 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.batch.maven;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
+import org.sonar.api.batch.SupportedEnvironment;
+import org.sonar.api.batch.bootstrap.ProjectBuilder;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+
+import java.util.List;
+
+/**
+ * Class that inject MavenProject in each module container
+ */
+@SupportedEnvironment("maven")
+public class MavenProjectBuilder extends ProjectBuilder {
+
+ private final MavenSession mavenSession;
+
+ public MavenProjectBuilder(MavenSession mavenSession) {
+ this.mavenSession = mavenSession;
+ }
+
+ @Override
+ public void build(Context context) {
+ ProjectReactor reactor = context.projectReactor();
+ for (ProjectDefinition moduleDef : reactor.getProjects()) {
+ setMavenProjectIfApplicable(moduleDef);
+ }
+ }
+
+ private void setMavenProjectIfApplicable(ProjectDefinition definition) {
+ if (mavenSession != null) {
+ String moduleKey = definition.getKey();
+ for (MavenProject mavenModule : (List<MavenProject>) mavenSession.getProjects()) {
+ // FIXME assumption that moduleKey was not modified by user and follow convention <groupId>:<artifactId>
+ String mavenModuleKey = mavenModule.getGroupId() + ":" + mavenModule.getArtifactId();
+ if (mavenModuleKey.equals(moduleKey) && !definition.getContainerExtensions().contains(mavenModule)) {
+ definition.addContainerExtension(mavenModule);
+ }
+ }
+ }
+ }
+
+}