1 package org.apache.maven.plugins.release;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.maven.model.Profile;
28 import org.apache.maven.plugin.AbstractMojo;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31 import org.apache.maven.project.MavenProject;
32 import org.apache.maven.scm.manager.ScmManager;
33 import org.apache.maven.settings.Settings;
34 import org.apache.maven.shared.release.ReleaseManager;
35 import org.apache.maven.shared.release.config.ReleaseDescriptor;
36 import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
37 import org.apache.maven.shared.release.env.ReleaseEnvironment;
38 import org.codehaus.plexus.util.StringUtils;
39
40
41
42
43
44
45
46 public abstract class AbstractReleaseMojo
47 extends AbstractMojo
48 {
49
50
51
52
53
54 private String username;
55
56
57
58
59
60
61 private String password;
62
63
64
65
66
67
68 private String tag;
69
70
71
72
73
74
75
76
77 private String tagBase;
78
79
80
81
82
83
84 protected File basedir;
85
86
87
88
89
90
91 protected Settings settings;
92
93
94
95
96
97
98 protected MavenProject project;
99
100
101
102
103 protected ReleaseManager releaseManager;
104
105
106
107
108
109
110 private String arguments;
111
112
113
114
115
116
117 private String pomFileName;
118
119
120
121
122
123
124
125 private String scmCommentPrefix;
126
127
128
129
130
131
132 protected List reactorProjects;
133
134
135
136
137
138
139
140 private Map providerImplementations;
141
142
143
144
145
146
147
148 protected File mavenHome;
149
150
151
152
153
154
155
156 protected File javaHome;
157
158
159
160
161
162
163
164 protected File localRepoDirectory;
165
166
167
168
169
170
171
172 protected String mavenExecutorId;
173
174
175
176
177
178
179
180
181
182
183
184 private boolean localCheckout;
185
186
187
188
189
190
191 private ScmManager scmManager;
192
193
194
195
196
197
198
199 protected ReleaseEnvironment getReleaseEnvironment()
200 {
201 return new DefaultReleaseEnvironment().setSettings( settings )
202 .setJavaHome( javaHome )
203 .setMavenHome( mavenHome )
204 .setLocalRepositoryDirectory( localRepoDirectory )
205 .setMavenExecutorId( mavenExecutorId );
206 }
207
208
209
210
211 public void execute()
212 throws MojoExecutionException, MojoFailureException
213 {
214 if ( providerImplementations != null )
215 {
216 for ( Iterator i = providerImplementations.keySet().iterator(); i.hasNext(); )
217 {
218 String providerType = (String) i.next();
219 String providerImplementation = (String) providerImplementations.get( providerType );
220 getLog().info( "Change the default '" + providerType + "' provider implementation to '"
221 + providerImplementation + "'." );
222 scmManager.setScmProviderImplementation( providerType, providerImplementation );
223 }
224 }
225 }
226
227
228
229
230
231
232 protected ReleaseDescriptor createReleaseDescriptor()
233 {
234 ReleaseDescriptor descriptor = new ReleaseDescriptor();
235
236 descriptor.setInteractive( settings.isInteractiveMode() );
237
238 descriptor.setScmPassword( password );
239 descriptor.setScmReleaseLabel( tag );
240 descriptor.setScmTagBase( tagBase );
241 descriptor.setScmUsername( username );
242 descriptor.setScmCommentPrefix( scmCommentPrefix );
243
244 descriptor.setWorkingDirectory( basedir.getAbsolutePath() );
245
246 descriptor.setPomFileName( pomFileName );
247
248 descriptor.setLocalCheckout( localCheckout );
249
250 List profiles = project.getActiveProfiles();
251
252 String arguments = this.arguments;
253 if ( profiles != null && !profiles.isEmpty() )
254 {
255 if ( !StringUtils.isEmpty( arguments ) )
256 {
257 arguments += " -P ";
258 }
259 else
260 {
261 arguments = "-P ";
262 }
263
264 for ( Iterator it = profiles.iterator(); it.hasNext(); )
265 {
266 Profile profile = (Profile) it.next();
267
268 arguments += profile.getId();
269 if ( it.hasNext() )
270 {
271 arguments += ",";
272 }
273 }
274
275 String additionalProfiles = getAdditionalProfiles();
276 if ( additionalProfiles != null )
277 {
278 if ( !profiles.isEmpty() )
279 {
280 arguments += ",";
281 }
282 arguments += additionalProfiles;
283 }
284 }
285 descriptor.setAdditionalArguments( arguments );
286
287 return descriptor;
288 }
289
290
291
292
293
294
295 protected String getAdditionalProfiles()
296 {
297 return null;
298 }
299
300
301
302
303
304
305 void setReleaseManager( ReleaseManager releaseManager )
306 {
307 this.releaseManager = releaseManager;
308 }
309
310
311
312
313
314
315 Settings getSettings()
316 {
317 return settings;
318 }
319
320
321
322
323
324
325 public void setBasedir( File basedir )
326 {
327 this.basedir = basedir;
328 }
329
330
331
332
333
334
335 public List getReactorProjects()
336 {
337 return reactorProjects;
338 }
339
340
341
342
343
344
345 protected void addArgument( String argument )
346 {
347 if ( arguments != null )
348 {
349 arguments += " " + argument;
350 }
351 else
352 {
353 arguments = argument;
354 }
355 }
356 }