1 package org.apache.maven.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.LinkedHashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.maven.model.Plugin;
27 import org.apache.maven.plugin.descriptor.MojoDescriptor;
28 import org.codehaus.plexus.util.xml.Xpp3Dom;
29
30
31
32
33 public class MojoExecution
34 {
35
36 private Plugin plugin;
37
38 private String goal;
39
40 private String executionId;
41
42 private MojoDescriptor mojoDescriptor;
43
44 private Xpp3Dom configuration;
45
46
47
48
49 public enum Source
50 {
51
52
53
54
55 CLI,
56
57
58
59
60 LIFECYCLE,
61 }
62
63 private Source source = Source.LIFECYCLE;
64
65
66
67
68
69 private String lifecyclePhase;
70
71
72
73
74
75 private Map<String, List<MojoExecution>> forkedExecutions = new LinkedHashMap<>();
76
77 public MojoExecution( Plugin plugin, String goal, String executionId )
78 {
79 this.plugin = plugin;
80 this.goal = goal;
81 this.executionId = executionId;
82 }
83
84 public MojoExecution( MojoDescriptor mojoDescriptor )
85 {
86 this.mojoDescriptor = mojoDescriptor;
87 this.executionId = null;
88 this.configuration = null;
89 }
90
91 public MojoExecution( MojoDescriptor mojoDescriptor, String executionId, Source source )
92 {
93 this.mojoDescriptor = mojoDescriptor;
94 this.executionId = executionId;
95 this.configuration = null;
96 this.source = source;
97 }
98
99 public MojoExecution( MojoDescriptor mojoDescriptor, String executionId )
100 {
101 this.mojoDescriptor = mojoDescriptor;
102 this.executionId = executionId;
103 this.configuration = null;
104 }
105
106 public MojoExecution( MojoDescriptor mojoDescriptor, Xpp3Dom configuration )
107 {
108 this.mojoDescriptor = mojoDescriptor;
109 this.configuration = configuration;
110 this.executionId = null;
111 }
112
113
114
115
116
117
118 public Source getSource()
119 {
120 return source;
121 }
122
123 public String getExecutionId()
124 {
125 return executionId;
126 }
127
128 public Plugin getPlugin()
129 {
130 if ( mojoDescriptor != null )
131 {
132 return mojoDescriptor.getPluginDescriptor().getPlugin();
133 }
134
135 return plugin;
136 }
137
138 public MojoDescriptor getMojoDescriptor()
139 {
140 return mojoDescriptor;
141 }
142
143 public Xpp3Dom getConfiguration()
144 {
145 return configuration;
146 }
147
148 public void setConfiguration( Xpp3Dom configuration )
149 {
150 this.configuration = configuration;
151 }
152
153 public String identify()
154 {
155 StringBuilder sb = new StringBuilder( 256 );
156
157 sb.append( executionId );
158 sb.append( configuration.toString() );
159
160 return sb.toString();
161 }
162
163 public String getLifecyclePhase()
164 {
165 return lifecyclePhase;
166 }
167
168 public void setLifecyclePhase( String lifecyclePhase )
169 {
170 this.lifecyclePhase = lifecyclePhase;
171 }
172
173 @Override
174 public String toString()
175 {
176 StringBuilder buffer = new StringBuilder( 128 );
177 if ( mojoDescriptor != null )
178 {
179 buffer.append( mojoDescriptor.getId() );
180 }
181 buffer.append( " {execution: " ).append( executionId ).append( '}' );
182 return buffer.toString();
183 }
184
185 public String getGroupId()
186 {
187 if ( mojoDescriptor != null )
188 {
189 return mojoDescriptor.getPluginDescriptor().getGroupId();
190 }
191
192 return plugin.getGroupId();
193 }
194
195 public String getArtifactId()
196 {
197 if ( mojoDescriptor != null )
198 {
199 return mojoDescriptor.getPluginDescriptor().getArtifactId();
200 }
201
202 return plugin.getArtifactId();
203 }
204
205 public String getVersion()
206 {
207 if ( mojoDescriptor != null )
208 {
209 return mojoDescriptor.getPluginDescriptor().getVersion();
210 }
211
212 return plugin.getVersion();
213 }
214
215 public String getGoal()
216 {
217 if ( mojoDescriptor != null )
218 {
219 return mojoDescriptor.getGoal();
220 }
221
222 return goal;
223 }
224
225 public void setMojoDescriptor( MojoDescriptor mojoDescriptor )
226 {
227 this.mojoDescriptor = mojoDescriptor;
228 }
229
230 public Map<String, List<MojoExecution>> getForkedExecutions()
231 {
232 return forkedExecutions;
233 }
234
235 public void setForkedExecutions( String projectKey, List<MojoExecution> forkedExecutions )
236 {
237 this.forkedExecutions.put( projectKey, forkedExecutions );
238 }
239
240 }