aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-04-02 16:55:09 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-04-02 16:55:59 +0200
commitb863d3fb4ceb9b0a34a8455d7a7263460d4b7807 (patch)
tree3ed646885d9a6d12adcc48c299fa2613d3ae78d1 /plugins
parentfba37d16e7689b6a280646d5989c1336fc02b0af (diff)
downloadsonarqube-b863d3fb4ceb9b0a34a8455d7a7263460d4b7807.tar.gz
sonarqube-b863d3fb4ceb9b0a34a8455d7a7263460d4b7807.zip
SONAR-5190 Make default bootstrapper support Maven
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java2
-rw-r--r--plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectBuilder.java71
-rw-r--r--plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenBatchPluginTest.java2
3 files changed, 73 insertions, 2 deletions
diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java
index 05ecc3595c2..64375e5f696 100644
--- a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java
+++ b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java
@@ -27,6 +27,6 @@ import java.util.List;
public final class MavenBatchPlugin extends SonarPlugin {
public List getExtensions() {
- return ImmutableList.of(MavenProjectBootstrapper.class, DefaultMavenPluginExecutor.class, MavenProjectConverter.class);
+ return ImmutableList.of(MavenProjectBootstrapper.class, DefaultMavenPluginExecutor.class, MavenProjectConverter.class, MavenProjectBuilder.class);
}
}
diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectBuilder.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectBuilder.java
new file mode 100644
index 00000000000..efbef8f43e3
--- /dev/null
+++ b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectBuilder.java
@@ -0,0 +1,71 @@
+/*
+ * 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.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();
+ MavenProject foundMavenModule = null;
+ for (MavenProject mavenModule : (List<MavenProject>) mavenSession.getSortedProjects()) {
+ String mavenModuleKey = mavenModule.getGroupId() + ":" + mavenModule.getArtifactId();
+ if (mavenModuleKey.equals(moduleKey)) {
+ foundMavenModule = mavenModule;
+ break;
+ }
+ }
+ if (foundMavenModule == null) {
+ throw new IllegalStateException("Unable to find Maven project in reactor with key " + moduleKey);
+ }
+ if (!definition.getContainerExtensions().contains(foundMavenModule)) {
+ definition.addContainerExtension(foundMavenModule);
+ }
+ }
+ }
+
+}
diff --git a/plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenBatchPluginTest.java b/plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenBatchPluginTest.java
index 2a7b0739a08..0504cb99f3f 100644
--- a/plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenBatchPluginTest.java
+++ b/plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenBatchPluginTest.java
@@ -28,7 +28,7 @@ public class MavenBatchPluginTest {
@Test
public void testGetExtensions() {
MavenBatchPlugin plugin = new MavenBatchPlugin();
- assertThat(plugin.getExtensions()).hasSize(3);
+ assertThat(plugin.getExtensions()).hasSize(4);
}
}