View Javadoc
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.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.Parameter;
28  import org.apache.maven.shared.release.ReleaseExecutionException;
29  import org.apache.maven.shared.release.ReleaseFailureException;
30  import org.apache.maven.shared.release.config.ReleaseDescriptor;
31  import org.apache.maven.shared.release.config.ReleaseUtils;
32  
33  /**
34   * Branch a project in SCM, using the same steps as the <tt>release:prepare</tt> goal, creating a branch instead of a tag.
35   * 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>.
36   *
37   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
38   * @version $Id: BranchReleaseMojo.java 1395771 2012-10-08 20:55:03Z rfscholte $
39   * @since 2.0-beta-6
40   */
41  @Mojo( name = "branch", aggregator = true )
42  public class BranchReleaseMojo
43      extends AbstractScmReleaseMojo
44  {
45      /**
46       * The branch name to use.
47       *
48       * @required
49       * @since 2.0-beta-6
50       */
51      @Parameter( property = "branchName", required = true )
52      private String branchName;
53  
54      /**
55       * The branch base directory in SVN, you must define it if you don't use the standard svn layout (trunk/tags/branches).
56       * For example, <code>http://svn.apache.org/repos/asf/maven/plugins/branches</code>. The URL is an SVN URL and does not
57       * include the SCM provider and protocol.
58       *
59       * @since 2.0
60       */
61      @Parameter( property = "branchBase" )
62      private String branchBase;
63  
64      /**
65       * Whether to update versions in the branch.
66       *
67       * @since 2.0-beta-6
68       */
69      @Parameter( defaultValue = "false", property = "updateBranchVersions" )
70      private boolean updateBranchVersions;
71  
72      /**
73       * Whether to update versions in the working copy.
74       *
75       * @since 2.0-beta-6
76       */
77      @Parameter( defaultValue = "true", property = "updateWorkingCopyVersions" )
78      private boolean updateWorkingCopyVersions;
79  
80      /**
81       * Whether to suppress a commit of changes to the working copy
82       * before the tag is created.
83       * <br/>
84       * <br/>This requires <code>remoteTagging</code> to be set to false.
85       * <br/>
86       * <br/><code>suppressCommitBeforeBranch</code> is useful when you want
87       * to avoid poms with released versions in all revisions of your
88       * trunk or development branch.
89       *
90       * @since 2.1
91       */
92      @Parameter( defaultValue = "false", property = "suppressCommitBeforeBranch" )
93      private boolean suppressCommitBeforeBranch;
94  
95      /**
96       * Whether to update versions to SNAPSHOT in the branch.
97       *
98       * @since 2.0-beta-6
99       */
100     @Parameter( defaultValue = "true", property = "updateVersionsToSnapshot" )
101     private boolean updateVersionsToSnapshot;
102 
103     /**
104      * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations.
105      *
106      * @since 2.0-beta-6
107      */
108     @Parameter( defaultValue = "false", property = "useEditMode" )
109     private boolean useEditMode;
110 
111     /**
112      * Whether to update dependencies version to the next development version.
113      *
114      * @since 2.0-beta-6
115      */
116     @Parameter( defaultValue = "true", property = "updateDependencies" )
117     private boolean updateDependencies;
118 
119     /**
120      * Whether to automatically assign submodules the parent version.  If set to false,
121      * the user will be prompted for the version of each submodules.
122      *
123      * @since 2.0-beta-6
124      */
125     @Parameter( defaultValue = "false", property = "autoVersionSubmodules" )
126     private boolean autoVersionSubmodules;
127 
128     /**
129      * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout.
130      * Running <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to
131      * poms and scm operations (only listed on the console) are working as expected.
132      * Modified POMs are written alongside the originals without modifying them.
133      *
134      * @since 2.0-beta-6
135      */
136     @Parameter( defaultValue = "false", property = "dryRun" )
137     private boolean dryRun;
138 
139     /**
140      * Whether to add a schema to the POM if it was previously missing on release.
141      *
142      * @since 2.0-beta-6
143      */
144     @Parameter( defaultValue = "true", property = "addSchema" )
145     private boolean addSchema;
146 
147     /**
148      * currently only implemented with svn scm. Enable a workaround to prevent issue
149      * due to svn client > 1.5.0 (http://jira.codehaus.org/browse/SCM-406)
150      *
151      * @since 2.0
152      */
153     @Parameter( defaultValue = "true", property = "remoteTagging" )
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      * @since 2.1
163      */
164     @Parameter
165     private String[] checkModificationExcludes;
166 
167     /**
168      * Command-line version of checkModificationExcludes.
169      *
170      * @since 2.1
171      */
172     @Parameter( property = "checkModificationExcludeList" )
173     private String checkModificationExcludeList;
174 
175     /**
176      * Specify the new version for the branch. 
177      * This parameter is only meaningful if {@link #updateBranchVersions} = {@code true}.
178      *
179      * @since 2.0
180      */
181     @Parameter( property = "releaseVersion" )
182     private String releaseVersion;
183 
184     /**
185      * Specify the new version for the working copy.
186      * This parameter is only meaningful if {@link #updateWorkingCopyVersions} = {@code true}.
187      *
188      * @since 2.0
189      */
190     @Parameter( property = "developmentVersion" )
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(), getReactorProjects(), 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 }