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.api.xml.Dom;
27 import org.apache.maven.model.Plugin;
28 import org.apache.maven.plugin.descriptor.MojoDescriptor;
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 org.codehaus.plexus.util.xml.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, org.codehaus.plexus.util.xml.Xpp3Dom configuration )
107 {
108 this.mojoDescriptor = mojoDescriptor;
109 this.configuration = configuration;
110 this.executionId = null;
111 }
112
113 public MojoExecution( MojoDescriptor mojoDescriptor, Dom configuration )
114 {
115 this.mojoDescriptor = mojoDescriptor;
116 this.configuration = new org.codehaus.plexus.util.xml.Xpp3Dom( configuration );
117 this.executionId = null;
118 }
119
120
121
122
123
124
125 public Source getSource()
126 {
127 return source;
128 }
129
130 public String getExecutionId()
131 {
132 return executionId;
133 }
134
135 public Plugin getPlugin()
136 {
137 if ( mojoDescriptor != null )
138 {
139 return mojoDescriptor.getPluginDescriptor().getPlugin();
140 }
141
142 return plugin;
143 }
144
145 public MojoDescriptor getMojoDescriptor()
146 {
147 return mojoDescriptor;
148 }
149
150 public org.codehaus.plexus.util.xml.Xpp3Dom getConfiguration()
151 {
152 return configuration;
153 }
154
155 public void setConfiguration( org.codehaus.plexus.util.xml.Xpp3Dom configuration )
156 {
157 this.configuration = configuration;
158 }
159
160 public void setConfiguration( Dom configuration )
161 {
162 this.configuration = configuration != null ? new org.codehaus.plexus.util.xml.Xpp3Dom( configuration ) : null;
163 }
164
165 public String identify()
166 {
167 StringBuilder sb = new StringBuilder( 256 );
168
169 sb.append( executionId );
170 sb.append( configuration.toString() );
171
172 return sb.toString();
173 }
174
175 public String getLifecyclePhase()
176 {
177 return lifecyclePhase;
178 }
179
180 public void setLifecyclePhase( String lifecyclePhase )
181 {
182 this.lifecyclePhase = lifecyclePhase;
183 }
184
185 @Override
186 public String toString()
187 {
188 StringBuilder buffer = new StringBuilder( 128 );
189 if ( mojoDescriptor != null )
190 {
191 buffer.append( mojoDescriptor.getId() );
192 }
193 buffer.append( " {execution: " ).append( executionId ).append( '}' );
194 return buffer.toString();
195 }
196
197 public String getGroupId()
198 {
199 if ( mojoDescriptor != null )
200 {
201 return mojoDescriptor.getPluginDescriptor().getGroupId();
202 }
203
204 return plugin.getGroupId();
205 }
206
207 public String getArtifactId()
208 {
209 if ( mojoDescriptor != null )
210 {
211 return mojoDescriptor.getPluginDescriptor().getArtifactId();
212 }
213
214 return plugin.getArtifactId();
215 }
216
217 public String getVersion()
218 {
219 if ( mojoDescriptor != null )
220 {
221 return mojoDescriptor.getPluginDescriptor().getVersion();
222 }
223
224 return plugin.getVersion();
225 }
226
227 public String getGoal()
228 {
229 if ( mojoDescriptor != null )
230 {
231 return mojoDescriptor.getGoal();
232 }
233
234 return goal;
235 }
236
237 public void setMojoDescriptor( MojoDescriptor mojoDescriptor )
238 {
239 this.mojoDescriptor = mojoDescriptor;
240 }
241
242 public Map<String, List<MojoExecution>> getForkedExecutions()
243 {
244 return forkedExecutions;
245 }
246
247 public void setForkedExecutions( String projectKey, List<MojoExecution> forkedExecutions )
248 {
249 this.forkedExecutions.put( projectKey, forkedExecutions );
250 }
251
252 }