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.model.Plugin;
26  import org.apache.maven.plugin.descriptor.MojoDescriptor;
27  import org.codehaus.plexus.util.xml.Xpp3Dom;
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 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, Xpp3Dom configuration) {
100         this.mojoDescriptor = mojoDescriptor;
101         this.configuration = configuration;
102         this.executionId = null;
103     }
104 
105     
106 
107 
108 
109 
110     public Source getSource() {
111         return source;
112     }
113 
114     public String getExecutionId() {
115         return executionId;
116     }
117 
118     public Plugin getPlugin() {
119         if (mojoDescriptor != null) {
120             return mojoDescriptor.getPluginDescriptor().getPlugin();
121         }
122 
123         return plugin;
124     }
125 
126     public MojoDescriptor getMojoDescriptor() {
127         return mojoDescriptor;
128     }
129 
130     public Xpp3Dom getConfiguration() {
131         return configuration;
132     }
133 
134     public void setConfiguration(Xpp3Dom configuration) {
135         this.configuration = configuration;
136     }
137 
138     public String identify() {
139         StringBuilder sb = new StringBuilder(256);
140 
141         sb.append(executionId);
142         sb.append(configuration.toString());
143 
144         return sb.toString();
145     }
146 
147     public String getLifecyclePhase() {
148         return lifecyclePhase;
149     }
150 
151     public void setLifecyclePhase(String lifecyclePhase) {
152         this.lifecyclePhase = lifecyclePhase;
153     }
154 
155     @Override
156     public String toString() {
157         StringBuilder buffer = new StringBuilder(128);
158         if (mojoDescriptor != null) {
159             buffer.append(mojoDescriptor.getId());
160         }
161         buffer.append(" {execution: ").append(executionId).append('}');
162         return buffer.toString();
163     }
164 
165     public String getGroupId() {
166         if (mojoDescriptor != null) {
167             return mojoDescriptor.getPluginDescriptor().getGroupId();
168         }
169 
170         return plugin.getGroupId();
171     }
172 
173     public String getArtifactId() {
174         if (mojoDescriptor != null) {
175             return mojoDescriptor.getPluginDescriptor().getArtifactId();
176         }
177 
178         return plugin.getArtifactId();
179     }
180 
181     public String getVersion() {
182         if (mojoDescriptor != null) {
183             return mojoDescriptor.getPluginDescriptor().getVersion();
184         }
185 
186         return plugin.getVersion();
187     }
188 
189     public String getGoal() {
190         if (mojoDescriptor != null) {
191             return mojoDescriptor.getGoal();
192         }
193 
194         return goal;
195     }
196 
197     public void setMojoDescriptor(MojoDescriptor mojoDescriptor) {
198         this.mojoDescriptor = mojoDescriptor;
199     }
200 
201     public Map<String, List<MojoExecution>> getForkedExecutions() {
202         return forkedExecutions;
203     }
204 
205     public void setForkedExecutions(String projectKey, List<MojoExecution> forkedExecutions) {
206         this.forkedExecutions.put(projectKey, forkedExecutions);
207     }
208 }