Browse Source

SONAR-6998 Remove injection of MavenProject in module IoC container

tags/5.3-RC1
Julien HENRY 8 years ago
parent
commit
266e3139c3

+ 0
- 51
plugins/sonar-batch-maven-plugin/pom.xml View File

@@ -1,51 +0,0 @@
<?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>5.3-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<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>${project.groupId}</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.sonarsource.sonar-packaging-maven-plugin</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>

+ 0
- 34
plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenBatchPlugin.java View File

@@ -1,34 +0,0 @@
/*
* 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);
}

}

+ 0
- 64
plugins/sonar-batch-maven-plugin/src/main/java/org/sonar/plugins/batch/maven/MavenProjectBuilder.java View File

@@ -1,64 +0,0 @@
/*
* 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);
}
}
}
}

}

+ 0
- 11
pom.xml View File

@@ -28,7 +28,6 @@
<module>sonar-ws</module>
<module>sonar-testing-harness</module>
<module>plugins/sonar-xoo-plugin</module>
<module>plugins/sonar-batch-maven-plugin</module>
</modules>

<organization>
@@ -831,16 +830,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>

+ 0
- 1
sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java View File

@@ -112,7 +112,6 @@ public class ModuleScanContainer extends ComponentContainer {
SensorsExecutor.class,
InitializersExecutor.class,
ProjectInitializer.class,
moduleDefinition.getContainerExtensions(),

// file system
ModuleInputFileCache.class,

+ 1
- 19
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java View File

@@ -83,7 +83,6 @@ public class ProjectDefinition {
private Map<String, String> properties = new HashMap<>();
private ProjectDefinition parent = null;
private List<ProjectDefinition> subProjects = new ArrayList<>();
private List<Object> containerExtensions = new ArrayList<>();

private ProjectDefinition(Properties p) {
for (Entry<Object, Object> entry : p.entrySet()) {
@@ -124,7 +123,7 @@ public class ProjectDefinition {
return workDir;
}

public ProjectDefinition setBuildDir( File d) {
public ProjectDefinition setBuildDir(File d) {
this.buildDir = d;
return this;
}
@@ -553,23 +552,6 @@ public class ProjectDefinition {
appendProperty(LIBRARIES_PROPERTY, path);
}

/**
* Adds an extension, which would be available in PicoContainer during analysis of this project.
*
* @since 2.8
*/
public ProjectDefinition addContainerExtension(Object extension) {
containerExtensions.add(extension);
return this;
}

/**
* @since 2.8
*/
public List<Object> getContainerExtensions() {
return containerExtensions;
}

/**
* @since 2.8
*/

Loading…
Cancel
Save