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