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