Permalink
Browse files

Make mojo-executor-mojo work with Maven 2 and 3.

Try to get a BuildPluginManager at runtime and use it. Otherwise,
fall back to the Maven 2 implementation. Allow building with
either version of Maven.
  • Loading branch information...
josephw committed Aug 20, 2011
1 parent 24c9cec commit 46289527b2d932e9171fd8ba593e6c3991276a6d
@@ -18,10 +18,13 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.twdata.maven.mojoexecutor.MojoExecutor.ExecutionEnvironment;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
@@ -83,7 +86,17 @@
private PluginManager pluginManager;
public void execute() throws MojoExecutionException {
ExecutionEnvironment env;
try {
Object o = mavenSession.lookup("org.apache.maven.plugin.BuildPluginManager");
env = executionEnvironment(mavenProject, mavenSession, (BuildPluginManager) o);
} catch (ComponentLookupException e) {
env = executionEnvironment(mavenProject, mavenSession, pluginManager);
}
executeMojo(plugin, goal, toXpp3Dom(configuration),
executionEnvironment(mavenProject, mavenSession, pluginManager));
env);
}
}
View
@@ -208,8 +208,8 @@
<message>Use junit:junit-dep instead of junit.</message>
</bannedDependencies>
<requireMavenVersion>
<version>[2.2.1,3.0)</version>
<message>Version 1.x of Mojo Executor requires Maven 2. Use Mojo Executor 2.x with Maven 3.</message>
<version>[2.2.1,4.0)</version>
<message>Version 1.5.x of Mojo Executor requires Maven 2 or Maven 3.</message>
</requireMavenVersion>
</rules>
</configuration>

0 comments on commit 4628952

Please sign in to comment.