Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PrepareReleaseMojo |
|
| 3.6666666666666665;3,667 |
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.execution.MavenSession; | |
23 | import org.apache.maven.plugin.MojoExecutionException; | |
24 | import org.apache.maven.plugin.MojoFailureException; | |
25 | import org.apache.maven.shared.release.ReleaseExecutionException; | |
26 | import org.apache.maven.shared.release.ReleaseFailureException; | |
27 | import org.apache.maven.shared.release.config.ReleaseDescriptor; | |
28 | import org.apache.maven.shared.release.config.ReleaseUtils; | |
29 | ||
30 | /** | |
31 | * Prepare for a release in SCM. | |
32 | * For more info see <a href="/plugins/maven-release-plugin/examples/prepare-release.html">this example</a>. | |
33 | * | |
34 | * @author <a href="mailto:jdcasey@apache.org">John Casey</a> | |
35 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> | |
36 | * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> | |
37 | * @author <a href="mailto:brett@apache.org">Brett Porter</a> | |
38 | * @version $Id$ | |
39 | * @aggregator | |
40 | * @goal prepare | |
41 | * @todo [!] check how this works with version ranges | |
42 | */ | |
43 | 9 | public class PrepareReleaseMojo |
44 | extends AbstractReleaseMojo | |
45 | { | |
46 | ||
47 | /** | |
48 | * Resume a previous release attempt from the point where it was stopped. | |
49 | * | |
50 | * @parameter expression="${resume}" default-value="true" | |
51 | */ | |
52 | private boolean resume; | |
53 | ||
54 | /** | |
55 | * @deprecated Please use release:prepare-with-pom instead. | |
56 | * | |
57 | * @parameter default-value="false" expression="${generateReleasePoms}" | |
58 | */ | |
59 | private boolean generateReleasePoms; | |
60 | ||
61 | /** | |
62 | * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations. | |
63 | * | |
64 | * @parameter expression="${useEditMode}" default-value="false" | |
65 | */ | |
66 | private boolean useEditMode; | |
67 | ||
68 | /** | |
69 | * Whether to update dependencies version to the next development version. | |
70 | * | |
71 | * @parameter expression="${updateDependencies}" default-value="true" | |
72 | * @since 2.0-beta-5 | |
73 | */ | |
74 | private boolean updateDependencies; | |
75 | ||
76 | /** | |
77 | * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the | |
78 | * version of each submodules. | |
79 | * | |
80 | * @parameter expression="${autoVersionSubmodules}" default-value="false" | |
81 | * @since 2.0-beta-5 | |
82 | */ | |
83 | private boolean autoVersionSubmodules; | |
84 | ||
85 | /** | |
86 | * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout. Running | |
87 | * <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to poms and scm | |
88 | * operations (only listed on the console) are working as expected. Modified POMs are written alongside the | |
89 | * originals without modifying them. | |
90 | * | |
91 | * @parameter expression="${dryRun}" default-value="false" | |
92 | */ | |
93 | private boolean dryRun; | |
94 | ||
95 | /** | |
96 | * Whether to add a schema to the POM if it was previously missing on release. | |
97 | * | |
98 | * @parameter expression="${addSchema}" default-value="true" | |
99 | */ | |
100 | private boolean addSchema; | |
101 | ||
102 | /** | |
103 | * Goals to run as part of the preparation step, after transformation but before committing. Space delimited. | |
104 | * | |
105 | * @parameter expression="${preparationGoals}" default-value="clean verify" | |
106 | */ | |
107 | private String preparationGoals; | |
108 | ||
109 | /** | |
110 | * Commits to do are atomic or by project. | |
111 | * | |
112 | * @parameter expression="${commitByProject}" default-value="false" | |
113 | * @since 2.0-beta-5 | |
114 | */ | |
115 | private boolean commitByProject; | |
116 | ||
117 | /** | |
118 | * Whether to allow timestamped SNAPSHOT dependencies. Default is to fail when finding any SNAPSHOT. | |
119 | * | |
120 | * @parameter expression="${ignoreSnapshots}" default-value="false" | |
121 | * @since 2.0-beta-7 | |
122 | */ | |
123 | private boolean allowTimestampedSnapshots; | |
124 | ||
125 | /** | |
126 | * Whether to allow usage of a SNAPSHOT version of the Release Plugin. This in an internal property used to support | |
127 | * testing of the plugin itself in batch mode. | |
128 | * | |
129 | * @parameter expression="${allowReleasePluginSnapshot}" default-value="false" | |
130 | * @readonly | |
131 | * @since 2.0-beta-9 | |
132 | */ | |
133 | private boolean allowReleasePluginSnapshot; | |
134 | ||
135 | /** | |
136 | * Default version to use when preparing a release or a branch. | |
137 | * | |
138 | * @parameter expression="${releaseVersion}" | |
139 | * @since 2.0-beta-8 | |
140 | */ | |
141 | private String releaseVersion; | |
142 | ||
143 | /** | |
144 | * Default version to use for new local working copy. | |
145 | * | |
146 | * @parameter expression="${developmentVersion}" | |
147 | * @since 2.0-beta-8 | |
148 | */ | |
149 | private String developmentVersion; | |
150 | ||
151 | /** | |
152 | * currently only implemented with svn scm. Enable a workaround to prevent issue | |
153 | * due to svn client > 1.5.0 (http://jira.codehaus.org/browse/SCM-406) | |
154 | * | |
155 | * | |
156 | * @parameter expression="${remoteTagging}" default-value="true" | |
157 | * @since 2.0-beta-9 | |
158 | */ | |
159 | private boolean remoteTagging; | |
160 | ||
161 | /** | |
162 | * @parameter expression="${session}" | |
163 | * @readonly | |
164 | * @required | |
165 | * @since 2.0 | |
166 | */ | |
167 | protected MavenSession session; | |
168 | ||
169 | /** | |
170 | * {@inheritDoc} | |
171 | */ | |
172 | public void execute() | |
173 | throws MojoExecutionException, MojoFailureException | |
174 | { | |
175 | 9 | if ( generateReleasePoms ) |
176 | { | |
177 | 0 | throw new MojoFailureException( |
178 | "Generating release POMs is no longer supported in release:prepare. Please run release:prepare-with-pom instead." ); | |
179 | } | |
180 | ||
181 | 9 | prepareRelease( generateReleasePoms ); |
182 | 3 | } |
183 | ||
184 | protected void prepareRelease( boolean generateReleasePoms ) | |
185 | throws MojoExecutionException, MojoFailureException | |
186 | { | |
187 | // this is here so the subclass can call it without getting the extra generateReleasePoms check in execute() above | |
188 | 9 | super.execute(); |
189 | ||
190 | 9 | ReleaseDescriptor config = createReleaseDescriptor(); |
191 | 9 | config.setAddSchema( addSchema ); |
192 | 9 | config.setGenerateReleasePoms( generateReleasePoms ); |
193 | 9 | config.setScmUseEditMode( useEditMode ); |
194 | 9 | config.setPreparationGoals( preparationGoals ); |
195 | 9 | config.setCommitByProject( commitByProject ); |
196 | 9 | config.setUpdateDependencies( updateDependencies ); |
197 | 9 | config.setAutoVersionSubmodules( autoVersionSubmodules ); |
198 | 9 | config.setAllowTimestampedSnapshots( allowTimestampedSnapshots ); |
199 | 9 | config.setSnapshotReleasePluginAllowed( allowReleasePluginSnapshot ); |
200 | 9 | config.setDefaultReleaseVersion( releaseVersion ); |
201 | 9 | config.setDefaultDevelopmentVersion( developmentVersion ); |
202 | 9 | config.setRemoteTagging( remoteTagging ); |
203 | ||
204 | // Create a config containing values from the session properties (ie command line properties with cli). | |
205 | 9 | ReleaseDescriptor sysPropertiesConfig |
206 | = ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() ); | |
207 | 9 | mergeCommandLineConfig( config, sysPropertiesConfig ); |
208 | ||
209 | try | |
210 | { | |
211 | 9 | releaseManager.prepare( config, getReleaseEnvironment(), reactorProjects, resume, dryRun ); |
212 | } | |
213 | 3 | catch ( ReleaseExecutionException e ) |
214 | { | |
215 | 3 | throw new MojoExecutionException( e.getMessage(), e ); |
216 | } | |
217 | 3 | catch ( ReleaseFailureException e ) |
218 | { | |
219 | 3 | throw new MojoFailureException( e.getMessage(), e ); |
220 | 3 | } |
221 | 3 | } |
222 | ||
223 | /** | |
224 | * This method takes some of the release configuration picked up from the command line system properties and copies | |
225 | * it into the release config object. | |
226 | * | |
227 | * @param config The release configuration to merge the system properties into, must not be <code>null</code>. | |
228 | * @param sysPropertiesConfig The configuration from the system properties to merge in, must not be | |
229 | * <code>null</code>. | |
230 | */ | |
231 | private void mergeCommandLineConfig( ReleaseDescriptor config, ReleaseDescriptor sysPropertiesConfig ) | |
232 | { | |
233 | // If the user specifies versions, these should override the existing versions | |
234 | 9 | if ( sysPropertiesConfig.getReleaseVersions() != null ) |
235 | { | |
236 | 9 | config.getReleaseVersions().putAll( sysPropertiesConfig.getReleaseVersions() ); |
237 | } | |
238 | 9 | if ( sysPropertiesConfig.getDevelopmentVersions() != null ) |
239 | { | |
240 | 9 | config.getDevelopmentVersions().putAll( sysPropertiesConfig.getDevelopmentVersions() ); |
241 | } | |
242 | 9 | } |
243 | ||
244 | } |