01: package org.apache.maven.lifecycle.statemgmt;
02:
03: import org.apache.maven.lifecycle.MojoBindingUtils;
04: import org.apache.maven.lifecycle.binding.MojoBindingFactory;
05: import org.apache.maven.lifecycle.model.MojoBinding;
06: import org.apache.maven.plugin.AbstractMojo;
07: import org.apache.maven.plugin.MojoExecutionException;
08: import org.apache.maven.plugin.MojoFailureException;
09: import org.apache.maven.plugin.descriptor.MojoDescriptor;
10: import org.apache.maven.plugin.descriptor.PluginDescriptor;
11: import org.apache.maven.plugin.loader.PluginLoader;
12: import org.apache.maven.plugin.loader.PluginLoaderException;
13: import org.apache.maven.project.MavenProject;
14:
15: public class ResolveLateBoundPluginMojo extends AbstractMojo {
16:
17: /**
18: * @component
19: */
20: private PluginLoader pluginLoader;
21:
22: private String groupId;
23:
24: private String artifactId;
25:
26: private String version;
27:
28: private String goal;
29:
30: private boolean includeReportConfig = false;
31:
32: private MavenProject project;
33:
34: private MojoBindingFactory bindingFactory;
35:
36: public void execute() throws MojoExecutionException,
37: MojoFailureException {
38: MojoBinding binding = bindingFactory.createMojoBinding(groupId,
39: artifactId, version, artifactId, project,
40: includeReportConfig);
41: try {
42: PluginDescriptor descriptor = pluginLoader.loadPlugin(
43: binding, project);
44:
45: MojoDescriptor mojoDescriptor = descriptor.getMojo(goal);
46:
47: if (mojoDescriptor == null) {
48: throw new MojoExecutionException("Resolved plugin: "
49: + descriptor.getId()
50: + " does not contain a mojo called \'" + goal
51: + "\'.");
52: }
53: } catch (PluginLoaderException e) {
54: throw new MojoExecutionException(
55: "Failed to load late-bound plugin: "
56: + MojoBindingUtils.createPluginKey(binding),
57: e);
58: }
59: }
60:
61: }
|