From 5dd7b6e298dde08601a09a5acc11e215961a6c63 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 16 Mar 2015 15:35:26 +0100 Subject: SONAR-3821 Drop any Maven dependency --- plugins/sonar-batch-maven-plugin/pom.xml | 53 ++++++++++++++++++ .../plugins/batch/maven/MavenBatchPlugin.java | 34 ++++++++++++ .../plugins/batch/maven/MavenProjectBuilder.java | 64 ++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 plugins/sonar-batch-maven-plugin/pom.xml create mode 100644 plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenBatchPlugin.java create mode 100644 plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenProjectBuilder.java (limited to 'plugins') 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 @@ + + + 4.0.0 + + + org.codehaus.sonar + sonar + 5.2-SNAPSHOT + ../.. + + + org.codehaus.sonar.plugins + sonar-batch-maven-plugin + SonarQube :: Batch Maven Plugin + sonar-plugin + Inject MavenProject in each module. + + + + com.google.code.findbugs + jsr305 + provided + + + org.codehaus.sonar + sonar-plugin-api + provided + + + org.apache.maven + maven-core + 3.0 + provided + + + + + + + org.codehaus.sonar + sonar-packaging-maven-plugin + + mavenbatch + Maven Batch + org.sonar.plugins.batch.maven.MavenBatchPlugin + + + + + + + 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) mavenSession.getProjects()) { + // FIXME assumption that moduleKey was not modified by user and follow convention : + String mavenModuleKey = mavenModule.getGroupId() + ":" + mavenModule.getArtifactId(); + if (mavenModuleKey.equals(moduleKey) && !definition.getContainerExtensions().contains(mavenModule)) { + definition.addContainerExtension(mavenModule); + } + } + } + } + +} -- cgit v1.2.3