Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PrepareReleaseMojo |
|
| 5.0;5 |
1 | package org.apache.maven.plugins.release; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.maven.plugin.MojoExecutionException; | |
23 | import org.apache.maven.plugin.MojoFailureException; | |
24 | import org.apache.maven.shared.release.ReleaseExecutionException; | |
25 | import org.apache.maven.shared.release.ReleaseFailureException; | |
26 | import org.apache.maven.shared.release.config.ReleaseDescriptor; | |
27 | import org.apache.maven.shared.release.config.ReleaseUtils; | |
28 | ||
29 | import java.util.Arrays; | |
30 | ||
31 | /** | |
32 | * Prepare for a release in SCM. Steps through several phases to ensure the POM is ready to be | |
33 | * released and then prepares SCM to eventually contain a tagged version of the release and a record | |
34 | * in the local copy of the parameters used. This can be followed by a call to <tt>release:perform</tt>. | |
35 | * For more info see <a href="http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html">http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html</a>. | |
36 | * | |
37 | * @author <a href="mailto:jdcasey@apache.org">John Casey</a> | |
38 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> | |
39 | * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> | |
40 | * @author <a href="mailto:brett@apache.org">Brett Porter</a> | |
41 | * @version $Id: PrepareReleaseMojo.java 1333174 2012-05-02 19:52:18Z rfscholte $ | |
42 | * @aggregator | |
43 | * @goal prepare | |
44 | * @todo [!] check how this works with version ranges | |
45 | */ | |
46 | 3 | public class PrepareReleaseMojo |
47 | extends AbstractReleaseMojo | |
48 | { | |
49 | ||
50 | /** | |
51 | * Resume a previous release attempt from the point where it was stopped. | |
52 | * | |
53 | * @parameter expression="${resume}" default-value="true" | |
54 | */ | |
55 | private boolean resume; | |
56 | ||
57 | /** | |
58 | * @deprecated Please use release:prepare-with-pom instead. | |
59 | * | |
60 | * @parameter default-value="false" expression="${generateReleasePoms}" | |
61 | */ | |
62 | private boolean generateReleasePoms; | |
63 | ||
64 | /** | |
65 | * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations. | |
66 | * | |
67 | * @parameter expression="${useEditMode}" default-value="false" | |
68 | */ | |
69 | private boolean useEditMode; | |
70 | ||
71 | /** | |
72 | * Whether to update dependencies version to the next development version. | |
73 | * | |
74 | * @parameter expression="${updateDependencies}" default-value="true" | |
75 | * @since 2.0-beta-5 | |
76 | */ | |
77 | private boolean updateDependencies; | |
78 | ||
79 | /** | |
80 | * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the | |
81 | * version of each submodules. | |
82 | * | |
83 | * @parameter expression="${autoVersionSubmodules}" default-value="false" | |
84 | * @since 2.0-beta-5 | |
85 | */ | |
86 | private boolean autoVersionSubmodules; | |
87 | ||
88 | /** | |
89 | * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout. Running | |
90 | * <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to poms and scm | |
91 | * operations (only listed on the console) are working as expected. Modified POMs are written alongside the | |
92 | * originals without modifying them. | |
93 | * | |
94 | * @parameter expression="${dryRun}" default-value="false" | |
95 | */ | |
96 | private boolean dryRun; | |
97 | ||
98 | /** | |
99 | * Whether to add a schema to the POM if it was previously missing on release. | |
100 | * | |
101 | * @parameter expression="${addSchema}" default-value="true" | |
102 | */ | |
103 | private boolean addSchema; | |
104 | ||
105 | /** | |
106 | * Goals to run as part of the preparation step, after transformation but before committing. Space delimited. | |
107 | * | |
108 | * @parameter expression="${preparationGoals}" default-value="clean verify" | |
109 | */ | |
110 | private String preparationGoals; | |
111 | ||
112 | /** | |
113 | * Goals to run on completion of the preparation step, after transformation back to the next development version | |
114 | * but before committing. Space delimited. | |
115 | * | |
116 | * @parameter expression="${completionGoals}" default-value="" | |
117 | * @since 2.2 | |
118 | */ | |
119 | private String completionGoals; | |
120 | ||
121 | /** | |
122 | * Commits to do are atomic or by project. | |
123 | * | |
124 | * @parameter expression="${commitByProject}" default-value="false" | |
125 | * @since 2.0-beta-5 | |
126 | */ | |
127 | private boolean commitByProject; | |
128 | ||
129 | /** | |
130 | * Whether to allow timestamped SNAPSHOT dependencies. Default is to fail when finding any SNAPSHOT. | |
131 | * | |
132 | * @parameter expression="${ignoreSnapshots}" default-value="false" | |
133 | * @since 2.0-beta-7 | |
134 | */ | |
135 | private boolean allowTimestampedSnapshots; | |
136 | ||
137 | /** | |
138 | * Whether to allow usage of a SNAPSHOT version of the Release Plugin. This in an internal property used to support | |
139 | * testing of the plugin itself in batch mode. | |
140 | * | |
141 | * @parameter expression="${allowReleasePluginSnapshot}" default-value="false" | |
142 | * @readonly | |
143 | * @since 2.0-beta-9 | |
144 | */ | |
145 | private boolean allowReleasePluginSnapshot; | |
146 | ||
147 | /** | |
148 | * A list of additional exclude filters that will be skipped when checking for | |
149 | * modifications on the working copy. | |
150 | * | |
151 | * Is ignored, when checkModificationExcludes is set. | |
152 | * | |
153 | * @parameter | |
154 | * @since 2.1 | |
155 | */ | |
156 | private String[] checkModificationExcludes; | |
157 | ||
158 | /** | |
159 | * Command-line version of checkModificationExcludes. | |
160 | * | |
161 | * @parameter expression="${checkModificationExcludeList}" | |
162 | * @since 2.1 | |
163 | */ | |
164 | private String checkModificationExcludeList; | |
165 | ||
166 | /** | |
167 | * Default version to use when preparing a release or a branch. | |
168 | * | |
169 | * @parameter expression="${releaseVersion}" | |
170 | * @since 2.0-beta-8 | |
171 | */ | |
172 | private String releaseVersion; | |
173 | ||
174 | /** | |
175 | * Default version to use for new local working copy. | |
176 | * | |
177 | * @parameter expression="${developmentVersion}" | |
178 | * @since 2.0-beta-8 | |
179 | */ | |
180 | private String developmentVersion; | |
181 | ||
182 | /** | |
183 | * Currently only implemented with svn scm. | |
184 | * | |
185 | * <ul> | |
186 | * <li>Enables a workaround to prevent issue | |
187 | * due to svn client > 1.5.0 (fixed in 1.6.5) | |
188 | * (http://jira.codehaus.org/browse/SCM-406)</li> | |
189 | * <li>You may not want to use this in conjunction | |
190 | * with <code>suppressCommitBeforeTag</code>, such that no poms with | |
191 | * released versions are committed to the working | |
192 | * copy ever.</li> | |
193 | * </ul> | |
194 | * | |
195 | * @parameter expression="${remoteTagging}" default-value="true" | |
196 | * @since 2.0-beta-9 | |
197 | */ | |
198 | private boolean remoteTagging; | |
199 | ||
200 | /** | |
201 | * Whether to bump the working copy versions to <code>developmentVersion</code>. | |
202 | * | |
203 | * @parameter expression="${updateWorkingCopyVersions}" default-value="true" | |
204 | * @since 2.1 | |
205 | */ | |
206 | private boolean updateWorkingCopyVersions; | |
207 | ||
208 | /** | |
209 | * Whether to suppress a commit of changes to the working copy | |
210 | * before the tag is created. | |
211 | * <br/> | |
212 | * <br/>This requires <code>remoteTagging</code> to be set to false. | |
213 | * <br/> | |
214 | * <br/><code>suppressCommitBeforeTag</code> is useful when you want | |
215 | * to avoid poms with released versions in all revisions of your | |
216 | * trunk or development branch. | |
217 | * | |
218 | * @parameter expression="${suppressCommitBeforeTag}" default-value="false" | |
219 | * @since 2.1 | |
220 | */ | |
221 | private boolean suppressCommitBeforeTag; | |
222 | ||
223 | /** | |
224 | * Wait the specified number of second before creating the tag. | |
225 | * <br/><code>waitBeforeTagging</code> is useful when your source repository | |
226 | * is synced between several instances and access to it is determined by | |
227 | * geographical location, like the SVN repository at the Apache Software | |
228 | * Foundation. | |
229 | * | |
230 | * @parameter expression="${waitBeforeTagging}" default-value="0" | |
231 | * @since 2.2 | |
232 | */ | |
233 | private int waitBeforeTagging; | |
234 | ||
235 | /** | |
236 | * {@inheritDoc} | |
237 | */ | |
238 | public void execute() | |
239 | throws MojoExecutionException, MojoFailureException | |
240 | { | |
241 | 3 | if ( generateReleasePoms ) |
242 | { | |
243 | 0 | throw new MojoFailureException( |
244 | "Generating release POMs is no longer supported in release:prepare. Please run release:prepare-with-pom instead." ); | |
245 | } | |
246 | ||
247 | 3 | prepareRelease( generateReleasePoms ); |
248 | 1 | } |
249 | ||
250 | protected void prepareRelease( boolean generateReleasePoms ) | |
251 | throws MojoExecutionException, MojoFailureException | |
252 | { | |
253 | // this is here so the subclass can call it without getting the extra generateReleasePoms check in execute() above | |
254 | 3 | super.execute(); |
255 | ||
256 | 3 | ReleaseDescriptor config = createReleaseDescriptor(); |
257 | 3 | config.setAddSchema( addSchema ); |
258 | 3 | config.setGenerateReleasePoms( generateReleasePoms ); |
259 | 3 | config.setScmUseEditMode( useEditMode ); |
260 | 3 | config.setPreparationGoals( preparationGoals ); |
261 | 3 | config.setCompletionGoals( completionGoals ); |
262 | 3 | config.setCommitByProject( commitByProject ); |
263 | 3 | config.setUpdateDependencies( updateDependencies ); |
264 | 3 | config.setAutoVersionSubmodules( autoVersionSubmodules ); |
265 | 3 | config.setAllowTimestampedSnapshots( allowTimestampedSnapshots ); |
266 | 3 | config.setSnapshotReleasePluginAllowed( allowReleasePluginSnapshot ); |
267 | 3 | config.setDefaultReleaseVersion( releaseVersion ); |
268 | 3 | config.setDefaultDevelopmentVersion( developmentVersion ); |
269 | 3 | config.setRemoteTagging( remoteTagging ); |
270 | 3 | config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions ); |
271 | 3 | config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTag ); |
272 | 3 | config.setWaitBeforeTagging( waitBeforeTagging ); |
273 | ||
274 | 3 | if ( checkModificationExcludeList != null ) |
275 | { | |
276 | 0 | checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," ); |
277 | } | |
278 | ||
279 | 3 | if ( checkModificationExcludes != null ) |
280 | { | |
281 | 0 | config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) ); |
282 | } | |
283 | ||
284 | // Create a config containing values from the session properties (ie command line properties with cli). | |
285 | 3 | ReleaseDescriptor sysPropertiesConfig |
286 | = ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() ); | |
287 | 3 | mergeCommandLineConfig( config, sysPropertiesConfig ); |
288 | ||
289 | try | |
290 | { | |
291 | 3 | releaseManager.prepare( config, getReleaseEnvironment(), getReactorProjects(), resume, dryRun ); |
292 | } | |
293 | 1 | catch ( ReleaseExecutionException e ) |
294 | { | |
295 | 1 | throw new MojoExecutionException( e.getMessage(), e ); |
296 | } | |
297 | 1 | catch ( ReleaseFailureException e ) |
298 | { | |
299 | 1 | throw new MojoFailureException( e.getMessage(), e ); |
300 | 1 | } |
301 | 1 | } |
302 | ||
303 | } |