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