1 package com.atlassian.maven.plugins.amps;
2
3 import java.util.List;
4
5 import org.apache.maven.execution.MavenSession;
6 import org.apache.maven.plugin.AbstractMojo;
7 import org.apache.maven.plugin.BuildPluginManager;
8 import org.apache.maven.plugin.PluginManager;
9 import org.apache.maven.project.MavenProject;
10 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
11 import org.jfrog.maven.annomojo.annotations.MojoComponent;
12 import org.jfrog.maven.annomojo.annotations.MojoParameter;
13
14 public abstract class AbstractAmpsMojo extends AbstractMojo
15 {
16
17
18
19 @MojoParameter (expression = "${project}", required = true, readonly = true)
20 private MavenProject project;
21
22
23
24
25 @MojoParameter (expression = "${reactorProjects}", required = true, readonly = true)
26 private List<MavenProject> reactor;
27
28
29
30
31 @MojoParameter (expression = "${session}", required = true, readonly = true)
32 private MavenSession session;
33
34
35
36
37 @MojoComponent
38 private PluginManager pluginManager;
39
40
41
42
43 @MojoParameter (expression = "${plugin.artifactId}", required = true, readonly = true)
44 private String pluginArtifactId;
45
46
47
48
49 @MojoParameter (expression = "${plugin.version}", required = true, readonly = true)
50 private String pluginVersion;
51
52
53
54
55 private MavenContext mavenContext;
56
57
58
59
60 private MavenGoals mavenGoals;
61
62 protected MavenContext getMavenContext()
63 {
64 if (mavenContext == null)
65 {
66 try
67 {
68 Object buildPluginManager = (BuildPluginManager) session.lookup("org.apache.maven.plugin.BuildPluginManager");
69
70
71 mavenContext = new MavenContext(project, reactor, session, (BuildPluginManager) buildPluginManager, getLog());
72 }
73 catch (ComponentLookupException e)
74 {
75
76 mavenContext = new MavenContext(project, reactor, session, pluginManager, getLog());
77 }
78 }
79 return mavenContext;
80 }
81
82 protected MavenGoals getMavenGoals()
83 {
84 if (mavenGoals == null)
85 {
86 mavenGoals = new MavenGoals(getMavenContext());
87 }
88 return mavenGoals;
89 }
90
91 protected PluginInformation getPluginInformation()
92 {
93 if (pluginArtifactId == null)
94 {
95 return new PluginInformation("amps", "");
96 }
97 final String productId = pluginArtifactId.replaceAll("maven-(.*)-plugin", "$1");
98 return new PluginInformation(productId, pluginVersion);
99 }
100 }