Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BranchReleaseMojo |
|
| 7.0;7 |
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 java.util.Arrays; | |
23 | ||
24 | import org.apache.maven.plugin.MojoExecutionException; | |
25 | import org.apache.maven.plugin.MojoFailureException; | |
26 | import org.apache.maven.shared.release.ReleaseExecutionException; | |
27 | import org.apache.maven.shared.release.ReleaseFailureException; | |
28 | import org.apache.maven.shared.release.config.ReleaseDescriptor; | |
29 | import org.apache.maven.shared.release.config.ReleaseUtils; | |
30 | ||
31 | /** | |
32 | * Branch a project in SCM, using the same steps as the <tt>release:prepare</tt> goal, creating a branch instead of a tag. | |
33 | * For more info see <a href="http://maven.apache.org/plugins/maven-release-plugin/examples/branch.html">http://maven.apache.org/plugins/maven-release-plugin/examples/branch.html</a>. | |
34 | * | |
35 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> | |
36 | * @version $Id: BranchReleaseMojo.java 1329473 2012-04-23 21:58:55Z rfscholte $ | |
37 | * @aggregator | |
38 | * @goal branch | |
39 | * @since 2.0-beta-6 | |
40 | */ | |
41 | 0 | public class BranchReleaseMojo |
42 | extends AbstractReleaseMojo | |
43 | { | |
44 | /** | |
45 | * The branch name to use. | |
46 | * | |
47 | * @parameter expression="${branchName}" | |
48 | * @required | |
49 | * @since 2.0-beta-6 | |
50 | */ | |
51 | private String branchName; | |
52 | ||
53 | /** | |
54 | * The branch base directory in SVN, you must define it if you don't use the standard svn layout (trunk/tags/branches). | |
55 | * For example, <code>http://svn.apache.org/repos/asf/maven/plugins/branches</code>. The URL is an SVN URL and does not | |
56 | * include the SCM provider and protocol. | |
57 | * | |
58 | * @parameter expression="${branchBase}" | |
59 | * @since 2.0 | |
60 | */ | |
61 | private String branchBase; | |
62 | ||
63 | /** | |
64 | * Whether to update versions in the branch. | |
65 | * | |
66 | * @parameter expression="${updateBranchVersions}" default-value="false" | |
67 | * @since 2.0-beta-6 | |
68 | */ | |
69 | private boolean updateBranchVersions; | |
70 | ||
71 | /** | |
72 | * Whether to update versions in the working copy. | |
73 | * | |
74 | * @parameter expression="${updateWorkingCopyVersions}" default-value="true" | |
75 | * @since 2.0-beta-6 | |
76 | */ | |
77 | private boolean updateWorkingCopyVersions; | |
78 | ||
79 | /** | |
80 | * Whether to suppress a commit of changes to the working copy | |
81 | * before the tag is created. | |
82 | * <br/> | |
83 | * <br/>This requires <code>remoteTagging</code> to be set to false. | |
84 | * <br/> | |
85 | * <br/><code>suppressCommitBeforeBranch</code> is useful when you want | |
86 | * to avoid poms with released versions in all revisions of your | |
87 | * trunk or development branch. | |
88 | * | |
89 | * @parameter expression="${suppressCommitBeforeBranch}" default-value="false" | |
90 | * @since 2.1 | |
91 | */ | |
92 | private boolean suppressCommitBeforeBranch; | |
93 | ||
94 | /** | |
95 | * Whether to update versions to SNAPSHOT in the branch. | |
96 | * | |
97 | * @parameter expression="${updateVersionsToSnapshot}" default-value="true" | |
98 | * @since 2.0-beta-6 | |
99 | */ | |
100 | private boolean updateVersionsToSnapshot; | |
101 | ||
102 | /** | |
103 | * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations. | |
104 | * | |
105 | * @parameter expression="${useEditMode}" default-value="false" | |
106 | * @since 2.0-beta-6 | |
107 | */ | |
108 | private boolean useEditMode; | |
109 | ||
110 | /** | |
111 | * Whether to update dependencies version to the next development version. | |
112 | * | |
113 | * @parameter expression="${updateDependencies}" default-value="true" | |
114 | * @since 2.0-beta-6 | |
115 | */ | |
116 | private boolean updateDependencies; | |
117 | ||
118 | /** | |
119 | * Whether to automatically assign submodules the parent version. If set to false, | |
120 | * the user will be prompted for the version of each submodules. | |
121 | * | |
122 | * @parameter expression="${autoVersionSubmodules}" default-value="false" | |
123 | * @since 2.0-beta-6 | |
124 | */ | |
125 | private boolean autoVersionSubmodules; | |
126 | ||
127 | /** | |
128 | * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout. | |
129 | * Running <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to | |
130 | * poms and scm operations (only listed on the console) are working as expected. | |
131 | * Modified POMs are written alongside the originals without modifying them. | |
132 | * | |
133 | * @parameter expression="${dryRun}" default-value="false" | |
134 | * @since 2.0-beta-6 | |
135 | */ | |
136 | private boolean dryRun; | |
137 | ||
138 | /** | |
139 | * Whether to add a schema to the POM if it was previously missing on release. | |
140 | * | |
141 | * @parameter expression="${addSchema}" default-value="true" | |
142 | * @since 2.0-beta-6 | |
143 | */ | |
144 | private boolean addSchema; | |
145 | ||
146 | /** | |
147 | * currently only implemented with svn scm. Enable a workaround to prevent issue | |
148 | * due to svn client > 1.5.0 (http://jira.codehaus.org/browse/SCM-406) | |
149 | * | |
150 | * | |
151 | * @parameter expression="${remoteTagging}" default-value="true" | |
152 | * @since 2.0 | |
153 | */ | |
154 | private boolean remoteTagging; | |
155 | ||
156 | /** | |
157 | * A list of additional exclude filters that will be skipped when checking for | |
158 | * modifications on the working copy. | |
159 | * | |
160 | * Is ignored, when checkModificationExcludes is set. | |
161 | * | |
162 | * @parameter | |
163 | * @since 2.1 | |
164 | */ | |
165 | private String[] checkModificationExcludes; | |
166 | ||
167 | /** | |
168 | * Command-line version of checkModificationExcludes. | |
169 | * | |
170 | * @parameter expression="${checkModificationExcludeList}" | |
171 | * @since 2.1 | |
172 | */ | |
173 | private String checkModificationExcludeList; | |
174 | ||
175 | /** | |
176 | * Default version to use when preparing a release or a branch. | |
177 | * | |
178 | * @parameter expression="${releaseVersion}" | |
179 | * @since 2.0 | |
180 | */ | |
181 | private String releaseVersion; | |
182 | ||
183 | /** | |
184 | * Default version to use for new local working copy. | |
185 | * | |
186 | * @parameter expression="${developmentVersion}" | |
187 | * @since 2.0 | |
188 | */ | |
189 | private String developmentVersion; | |
190 | ||
191 | /** | |
192 | * {@inheritDoc} | |
193 | */ | |
194 | public void execute() | |
195 | throws MojoExecutionException, MojoFailureException | |
196 | { | |
197 | 0 | super.execute(); |
198 | ||
199 | 0 | ReleaseDescriptor config = createReleaseDescriptor(); |
200 | 0 | config.setAddSchema( addSchema ); |
201 | 0 | config.setScmUseEditMode( useEditMode ); |
202 | 0 | config.setUpdateDependencies( updateDependencies ); |
203 | 0 | config.setAutoVersionSubmodules( autoVersionSubmodules ); |
204 | 0 | config.setScmReleaseLabel( branchName ); |
205 | 0 | config.setScmBranchBase( branchBase ); |
206 | 0 | config.setBranchCreation( true ); |
207 | 0 | config.setUpdateBranchVersions( updateBranchVersions ); |
208 | 0 | config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions ); |
209 | 0 | config.setUpdateVersionsToSnapshot( updateVersionsToSnapshot ); |
210 | 0 | config.setRemoteTagging( remoteTagging ); |
211 | 0 | config.setDefaultReleaseVersion( releaseVersion ); |
212 | 0 | config.setDefaultDevelopmentVersion( developmentVersion ); |
213 | 0 | config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeBranch ); |
214 | ||
215 | // Create a config containing values from the session properties (ie command line properties with cli). | |
216 | 0 | ReleaseDescriptor sysPropertiesConfig |
217 | = ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() ); | |
218 | 0 | mergeCommandLineConfig( config, sysPropertiesConfig ); |
219 | ||
220 | 0 | if ( checkModificationExcludeList != null ) |
221 | { | |
222 | 0 | checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," ); |
223 | } | |
224 | ||
225 | 0 | if ( checkModificationExcludes != null ) |
226 | { | |
227 | 0 | config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) ); |
228 | } | |
229 | ||
230 | try | |
231 | { | |
232 | 0 | releaseManager.branch( config, getReleaseEnvironment(), getReactorProjects(), dryRun ); |
233 | } | |
234 | 0 | catch ( ReleaseExecutionException e ) |
235 | { | |
236 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
237 | } | |
238 | 0 | catch ( ReleaseFailureException e ) |
239 | { | |
240 | 0 | throw new MojoFailureException( e.getMessage(), e ); |
241 | 0 | } |
242 | 0 | } |
243 | } |