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.html 816531 2012-05-08 11:38:11Z hboutemy $
37 * @aggregator
38 * @goal branch
39 * @since 2.0-beta-6
40 */
41 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 * Additional files that will skipped when checking for
158 * modifications on the working copy.
159 *
160 * Is ignored, when checkModificationExcludes is set.
161 *
162 *
163 * @parameter
164 * @since 2.1
165 */
166 private String[] checkModificationExcludes;
167
168 /**
169 * Command-line version of checkModificationExcludes
170 *
171 *
172 * @parameter expression="${checkModificationExcludeList}"
173 * @since 2.1
174 */
175 private String checkModificationExcludeList;
176
177 /**
178 * Default version to use when preparing a release or a branch.
179 *
180 * @parameter expression="${releaseVersion}"
181 * @since 2.0
182 */
183 private String releaseVersion;
184
185 /**
186 * Default version to use for new local working copy.
187 *
188 * @parameter expression="${developmentVersion}"
189 * @since 2.0
190 */
191 private String developmentVersion;
192
193 /**
194 * {@inheritDoc}
195 */
196 public void execute()
197 throws MojoExecutionException, MojoFailureException
198 {
199 super.execute();
200
201 ReleaseDescriptor config = createReleaseDescriptor();
202 config.setAddSchema( addSchema );
203 config.setScmUseEditMode( useEditMode );
204 config.setUpdateDependencies( updateDependencies );
205 config.setAutoVersionSubmodules( autoVersionSubmodules );
206 config.setScmReleaseLabel( branchName );
207 config.setScmBranchBase( branchBase );
208 config.setBranchCreation( true );
209 config.setUpdateBranchVersions( updateBranchVersions );
210 config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions );
211 config.setUpdateVersionsToSnapshot( updateVersionsToSnapshot );
212 config.setRemoteTagging( remoteTagging );
213 config.setDefaultReleaseVersion( releaseVersion );
214 config.setDefaultDevelopmentVersion( developmentVersion );
215 config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeBranch );
216
217 // Create a config containing values from the session properties (ie command line properties with cli).
218 ReleaseDescriptor sysPropertiesConfig
219 = ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() );
220 mergeCommandLineConfig( config, sysPropertiesConfig );
221
222 if ( checkModificationExcludeList != null )
223 {
224 checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," );
225 }
226
227 if ( checkModificationExcludes != null )
228 {
229 config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) );
230 }
231
232 try
233 {
234 releaseManager.branch( config, getReleaseEnvironment(), reactorProjects, dryRun );
235 }
236 catch ( ReleaseExecutionException e )
237 {
238 throw new MojoExecutionException( e.getMessage(), e );
239 }
240 catch ( ReleaseFailureException e )
241 {
242 throw new MojoFailureException( e.getMessage(), e );
243 }
244 }
245 }