Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PrepareReleaseMojo |
|
| 4.0;4 |
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 | /** | |
30 | * Prepare for a release in SCM. | |
31 | * | |
32 | * @author <a href="mailto:jdcasey@apache.org">John Casey</a> | |
33 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> | |
34 | * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> | |
35 | * @author <a href="mailto:brett@apache.org">Brett Porter</a> | |
36 | * @version $Id$ | |
37 | * @aggregator | |
38 | * @goal prepare | |
39 | * @requiresDependencyResolution test | |
40 | * @todo [!] check how this works with version ranges | |
41 | */ | |
42 | 3 | public class PrepareReleaseMojo |
43 | extends AbstractReleaseMojo | |
44 | { | |
45 | ||
46 | /** | |
47 | * Resume a previous release attempt from the point where it was stopped. | |
48 | * | |
49 | * @parameter expression="${resume}" default-value="true" | |
50 | */ | |
51 | private boolean resume; | |
52 | ||
53 | /** | |
54 | * Whether to generate <code>release-pom.xml</code> files that contain resolved information about the project. | |
55 | * | |
56 | * @parameter default-value="false" expression="${generateReleasePoms}" | |
57 | */ | |
58 | private boolean generateReleasePoms; | |
59 | ||
60 | /** | |
61 | * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations. | |
62 | * | |
63 | * @parameter expression="${useEditMode}" default-value="false" | |
64 | */ | |
65 | private boolean useEditMode; | |
66 | ||
67 | /** | |
68 | * Whether to update dependencies version to the next development version. | |
69 | * | |
70 | * @parameter expression="${updateDependencies}" default-value="true" | |
71 | */ | |
72 | private boolean updateDependencies; | |
73 | ||
74 | /** | |
75 | * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the | |
76 | * version of each submodules. | |
77 | * | |
78 | * @parameter expression="${autoVersionSubmodules}" default-value="false" | |
79 | */ | |
80 | private boolean autoVersionSubmodules; | |
81 | ||
82 | /** | |
83 | * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout. Running | |
84 | * <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to poms and scm | |
85 | * operations (only listed on the console) are working as expected. Modified POMs are written alongside the | |
86 | * originals without modifying them. | |
87 | * | |
88 | * @parameter expression="${dryRun}" default-value="false" | |
89 | */ | |
90 | private boolean dryRun; | |
91 | ||
92 | /** | |
93 | * Whether to add a schema to the POM if it was previously missing on release. | |
94 | * | |
95 | * @parameter expression="${addSchema}" default-value="true" | |
96 | */ | |
97 | private boolean addSchema; | |
98 | ||
99 | /** | |
100 | * Goals to run as part of the preparation step, after transformation but before committing. Space delimited. | |
101 | * | |
102 | * @parameter expression="${preparationGoals}" default-value="clean verify" | |
103 | */ | |
104 | private String preparationGoals; | |
105 | ||
106 | /** | |
107 | * Commits to do are atomic or by project. | |
108 | * | |
109 | * @parameter expression="${commitByProject}" default-value="false" | |
110 | */ | |
111 | private boolean commitByProject; | |
112 | ||
113 | /** | |
114 | * Whether to allow timestamped SNAPSHOT dependencies. Default is to fail when finding any SNAPSHOT. | |
115 | * | |
116 | * @parameter expression="${ignoreSnapshots}" default-value="false" | |
117 | */ | |
118 | private boolean allowTimestampedSnapshots; | |
119 | ||
120 | /** | |
121 | * Default version to use when preparing a release or a branch. | |
122 | * | |
123 | * @parameter expression="${releaseVersion}" | |
124 | */ | |
125 | private String releaseVersion; | |
126 | ||
127 | /** | |
128 | * Default version to use for new local working copy. | |
129 | * | |
130 | * @parameter expression="${developmentVersion}" | |
131 | */ | |
132 | private String developmentVersion; | |
133 | ||
134 | /** | |
135 | * {@inheritDoc} | |
136 | */ | |
137 | public void execute() | |
138 | throws MojoExecutionException, MojoFailureException | |
139 | { | |
140 | 3 | super.execute(); |
141 | ||
142 | 3 | ReleaseDescriptor config = createReleaseDescriptor(); |
143 | 3 | config.setAddSchema( addSchema ); |
144 | 3 | config.setGenerateReleasePoms( generateReleasePoms ); |
145 | 3 | config.setScmUseEditMode( useEditMode ); |
146 | 3 | config.setPreparationGoals( preparationGoals ); |
147 | 3 | config.setCommitByProject( commitByProject ); |
148 | 3 | config.setUpdateDependencies( updateDependencies ); |
149 | 3 | config.setAutoVersionSubmodules( autoVersionSubmodules ); |
150 | 3 | config.setAllowTimestampedSnapshots( allowTimestampedSnapshots ); |
151 | 3 | config.setDefaultReleaseVersion( releaseVersion ); |
152 | 3 | config.setDefaultDevelopmentVersion( developmentVersion ); |
153 | ||
154 | // Create a config containing values from the system properties (command line properties). | |
155 | 3 | ReleaseDescriptor sysPropertiesConfig |
156 | = ReleaseUtils.copyPropertiesToReleaseDescriptor( System.getProperties() ); | |
157 | 3 | mergeCommandLineConfig( config, sysPropertiesConfig ); |
158 | ||
159 | try | |
160 | { | |
161 | 3 | releaseManager.prepare( config, getReleaseEnvironment(), reactorProjects, resume, dryRun ); |
162 | } | |
163 | 1 | catch ( ReleaseExecutionException e ) |
164 | { | |
165 | 1 | throw new MojoExecutionException( e.getMessage(), e ); |
166 | } | |
167 | 1 | catch ( ReleaseFailureException e ) |
168 | { | |
169 | 1 | throw new MojoFailureException( e.getMessage() ); |
170 | 1 | } |
171 | 1 | } |
172 | ||
173 | /** | |
174 | * This method takes some of the release configuration picked up from the command line system properties and copies | |
175 | * it into the release config object. | |
176 | * | |
177 | * @param config The release configuration to merge the system properties into, must not be <code>null</code>. | |
178 | * @param sysPropertiesConfig The configuration from the system properties to merge in, must not be | |
179 | * <code>null</code>. | |
180 | */ | |
181 | private void mergeCommandLineConfig( ReleaseDescriptor config, ReleaseDescriptor sysPropertiesConfig ) | |
182 | { | |
183 | // If the user specifies versions, these should be override the existing versions | |
184 | 3 | if ( sysPropertiesConfig.getReleaseVersions() != null ) |
185 | { | |
186 | 3 | config.getReleaseVersions().putAll( sysPropertiesConfig.getReleaseVersions() ); |
187 | } | |
188 | 3 | if ( sysPropertiesConfig.getDevelopmentVersions() != null ) |
189 | { | |
190 | 3 | config.getDevelopmentVersions().putAll( sysPropertiesConfig.getDevelopmentVersions() ); |
191 | } | |
192 | 3 | } |
193 | ||
194 | } |