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  public class MojoExecution
31  {
32  
33      private Plugin plugin;
34  
35      private String goal;
36  
37      private String executionId;
38  
39      private MojoDescriptor mojoDescriptor;
40  
41      private Xpp3Dom configuration;
42  
43      
44  
45  
46      public enum Source
47      {
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<String, List<MojoExecution>>();
73  
74      public MojoExecution( Plugin plugin, String goal, String executionId )
75      {
76          this.plugin = plugin;
77          this.goal = goal;
78          this.executionId = executionId;
79      }
80  
81      public MojoExecution( MojoDescriptor mojoDescriptor )
82      {
83          this.mojoDescriptor = mojoDescriptor;
84          this.executionId = null;
85          this.configuration = null;
86      }
87  
88      public MojoExecution( MojoDescriptor mojoDescriptor, String executionId, Source source )
89      {
90          this.mojoDescriptor = mojoDescriptor;
91          this.executionId = executionId;
92          this.configuration = null;
93          this.source = source;
94      }
95  
96      public MojoExecution( MojoDescriptor mojoDescriptor, String executionId )
97      {
98          this.mojoDescriptor = mojoDescriptor;
99          this.executionId = executionId;
100         this.configuration = null;
101     }
102 
103     public MojoExecution( MojoDescriptor mojoDescriptor, Xpp3Dom configuration )
104     {
105         this.mojoDescriptor = mojoDescriptor;
106         this.configuration = configuration;
107         this.executionId = null;
108     }
109 
110     
111 
112 
113 
114 
115     public Source getSource()
116     {
117         return source;
118     }
119 
120     public String getExecutionId()
121     {
122         return executionId;
123     }
124 
125     public Plugin getPlugin()
126     {
127         if ( mojoDescriptor != null )
128         {
129             return mojoDescriptor.getPluginDescriptor().getPlugin();
130         }
131 
132         return plugin;
133     }
134 
135     public MojoDescriptor getMojoDescriptor()
136     {
137         return mojoDescriptor;
138     }
139 
140     public Xpp3Dom getConfiguration()
141     {
142         return configuration;
143     }
144 
145     public void setConfiguration( Xpp3Dom configuration )
146     {
147         this.configuration = configuration;
148     }
149 
150     public String identify()
151     {
152         StringBuilder sb = new StringBuilder( 256 );
153 
154         sb.append( executionId );
155         sb.append( configuration.toString() );
156 
157         return sb.toString();
158     }
159 
160     public String getLifecyclePhase()
161     {
162         return lifecyclePhase;
163     }
164 
165     public void setLifecyclePhase( String lifecyclePhase )
166     {
167         this.lifecyclePhase = lifecyclePhase;
168     }
169 
170     @Override
171     public String toString()
172     {
173         StringBuilder buffer = new StringBuilder( 128 );
174         if ( mojoDescriptor != null )
175         {
176             buffer.append( mojoDescriptor.getId() );
177         }
178         buffer.append( " {execution: " ).append( executionId ).append( "}" );
179         return buffer.toString();
180     }
181 
182     public String getGroupId()
183     {
184         if ( mojoDescriptor != null )
185         {
186             return mojoDescriptor.getPluginDescriptor().getGroupId();
187         }
188 
189         return plugin.getGroupId();
190     }
191 
192     public String getArtifactId()
193     {
194         if ( mojoDescriptor != null )
195         {
196             return mojoDescriptor.getPluginDescriptor().getArtifactId();
197         }
198 
199         return plugin.getArtifactId();
200     }
201 
202     public String getVersion()
203     {
204         if ( mojoDescriptor != null )
205         {
206             return mojoDescriptor.getPluginDescriptor().getVersion();
207         }
208 
209         return plugin.getVersion();
210     }
211 
212     public String getGoal()
213     {
214         if ( mojoDescriptor != null )
215         {
216             return mojoDescriptor.getGoal();
217         }
218 
219         return goal;
220     }
221 
222     public void setMojoDescriptor( MojoDescriptor mojoDescriptor )
223     {
224         this.mojoDescriptor = mojoDescriptor;
225     }
226 
227     public Map<String, List<MojoExecution>> getForkedExecutions()
228     {
229         return forkedExecutions;
230     }
231 
232     public void setForkedExecutions( String projectKey, List<MojoExecution> forkedExecutions )
233     {
234         this.forkedExecutions.put( projectKey, forkedExecutions );
235     }
236 
237 }