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   * Prepare for a release in SCM. Steps through several phases to ensure the POM is ready to be released and then
35   * prepares SCM to eventually contain a tagged version of the release and a record in the local copy of the parameters
36   * used. This can be followed by a call to <tt>release:perform</tt>. For more info see <a
37   * href="http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html"
38   * >http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html</a>.
39   *
40   * @author <a href="mailto:jdcasey@apache.org">John Casey</a>
41   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
42   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
43   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
44   * @version $Id: PrepareReleaseMojo.java 1643023 2014-12-02 23:42:32Z hboutemy $
45   * @todo [!] check how this works with version ranges
46   */
47  @Mojo( name = "prepare", aggregator = true )
48  public class PrepareReleaseMojo
49      extends AbstractScmReleaseMojo
50  {
51  
52      /**
53       * Resume a previous release attempt from the point where it was stopped.
54       */
55      @Parameter( defaultValue = "true", property = "resume" )
56      private boolean resume;
57  
58      /**
59       * @deprecated Please use release:prepare-with-pom instead.
60       */
61      @Parameter( defaultValue = "false", property = "generateReleasePoms" )
62      private boolean generateReleasePoms;
63  
64      /**
65       * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations.
66       */
67      @Parameter( defaultValue = "false", property = "useEditMode" )
68      private boolean useEditMode;
69  
70      /**
71       * Whether to update dependencies version to the next development version.
72       *
73       * @since 2.0-beta-5
74       */
75      @Parameter( defaultValue = "true", property = "updateDependencies" )
76      private boolean updateDependencies;
77  
78      /**
79       * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the
80       * version of each submodules.
81       *
82       * @since 2.0-beta-5
83       */
84      @Parameter( defaultValue = "false", property = "autoVersionSubmodules" )
85      private boolean autoVersionSubmodules;
86  
87      /**
88       * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout. Running
89       * <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to poms and scm
90       * operations (only listed on the console) are working as expected. Modified POMs are written alongside the
91       * originals without modifying them.
92       */
93      @Parameter( defaultValue = "false", property = "dryRun" )
94      private boolean dryRun;
95  
96      /**
97       * Whether to add a schema to the POM if it was previously missing on release.
98       */
99      @Parameter( defaultValue = "true", property = "addSchema" )
100     private boolean addSchema;
101 
102     /**
103      * Goals to run as part of the preparation step, after transformation but before committing. Space delimited.
104      */
105     @Parameter( defaultValue = "clean verify", property = "preparationGoals" )
106     private String preparationGoals;
107 
108     /**
109      * Goals to run on completion of the preparation step, after transformation back to the next development version but
110      * before committing. Space delimited.
111      *
112      * @since 2.2
113      */
114     @Parameter( defaultValue = "", property = "completionGoals" )
115     private String completionGoals;
116 
117     /**
118      * Commits to do are atomic or by project.
119      *
120      * @since 2.0-beta-5
121      */
122     @Parameter( defaultValue = "false", property = "commitByProject" )
123     private boolean commitByProject;
124 
125     /**
126      * Whether to allow timestamped SNAPSHOT dependencies. Default is to fail when finding any SNAPSHOT.
127      *
128      * @since 2.0-beta-7
129      */
130     @Parameter( defaultValue = "false", property = "ignoreSnapshots" )
131     private boolean allowTimestampedSnapshots;
132 
133     /**
134      * Whether to allow usage of a SNAPSHOT version of the Release Plugin. This in an internal property used to support
135      * testing of the plugin itself in batch mode.
136      *
137      * @since 2.0-beta-9
138      */
139     @Parameter( defaultValue = "false", property = "allowReleasePluginSnapshot", readonly = true )
140     private boolean allowReleasePluginSnapshot;
141 
142     /**
143      * A list of additional exclude filters that will be skipped when checking for modifications on the working copy. Is
144      * ignored, when checkModificationExcludes is set.
145      *
146      * @since 2.1
147      */
148     @Parameter
149     private String[] checkModificationExcludes;
150 
151     /**
152      * Command-line version of checkModificationExcludes.
153      *
154      * @since 2.1
155      */
156     @Parameter( property = "checkModificationExcludeList" )
157     private String checkModificationExcludeList;
158 
159     /**
160      * Default version to use when preparing a release or a branch.
161      *
162      * @since 2.0-beta-8
163      */
164     @Parameter( property = "releaseVersion" )
165     private String releaseVersion;
166 
167     /**
168      * Default version to use for new local working copy.
169      *
170      * @since 2.0-beta-8
171      */
172     @Parameter( property = "developmentVersion" )
173     private String developmentVersion;
174 
175     /**
176      * Currently only implemented with svn scm.
177      * <ul>
178      * <li>Enables a workaround to prevent issue due to svn client > 1.5.0 (fixed in 1.6.5)
179      * (http://jira.codehaus.org/browse/SCM-406)</li>;
180      * <li>You may not want to use this in conjunction with <code>suppressCommitBeforeTag</code>, such that no poms with
181      * released versions are committed to the working copy ever.</li>
182      * </ul>
183      *
184      * @since 2.0-beta-9
185      */
186     @Parameter( defaultValue = "true", property = "remoteTagging" )
187     private boolean remoteTagging;
188 
189     /**
190      * Whether to bump the working copy versions to <code>developmentVersion</code>.
191      *
192      * @since 2.1
193      */
194     @Parameter( defaultValue = "true", property = "updateWorkingCopyVersions" )
195     private boolean updateWorkingCopyVersions;
196 
197     /**
198      * Whether to suppress a commit of changes to the working copy before the tag is created. <br/>
199      * <br/>
200      * This requires <code>remoteTagging</code> to be set to false. <br/>
201      * <br/>
202      * <code>suppressCommitBeforeTag</code> is useful when you want to avoid poms with released versions in all
203      * revisions of your trunk or development branch.
204      *
205      * @since 2.1
206      */
207     @Parameter( defaultValue = "false", property = "suppressCommitBeforeTag" )
208     private boolean suppressCommitBeforeTag;
209 
210     /**
211      * Wait the specified number of seconds before creating the tag. <br/>
212      * <code>waitBeforeTagging</code> is useful when your source repository is synced between several instances and
213      * access to it is determined by geographical location, like the SVN repository at the Apache Software Foundation.
214      *
215      * @since 2.2
216      */
217     @Parameter( defaultValue = "0", property = "waitBeforeTagging" )
218     private int waitBeforeTagging;
219 
220     /**
221      * The {@code VersionPolicy} ID.
222      *
223      * @since 3.0
224      */
225     @Parameter( defaultValue = "default", property = "projectVersionPolicyId" )
226     private String projectVersionPolicyId;
227 
228     /**
229      * {@inheritDoc}
230      */
231     public void execute()
232         throws MojoExecutionException, MojoFailureException
233     {
234         if ( generateReleasePoms )
235         {
236             throw new MojoFailureException( "Generating release POMs is no longer supported in release:prepare. "
237                 + "Please run release:prepare-with-pom instead." );
238         }
239 
240         prepareRelease( generateReleasePoms );
241     }
242 
243     protected void prepareRelease( boolean generateReleasePoms )
244         throws MojoExecutionException, MojoFailureException
245     {
246         // this is here so the subclass can call it without getting the extra generateReleasePoms check in execute()
247         // above
248         super.execute();
249 
250         ReleaseDescriptor config = createReleaseDescriptor();
251         config.setAddSchema( addSchema );
252         config.setGenerateReleasePoms( generateReleasePoms );
253         config.setScmUseEditMode( useEditMode );
254         config.setPreparationGoals( preparationGoals );
255         config.setCompletionGoals( completionGoals );
256         config.setCommitByProject( commitByProject );
257         config.setUpdateDependencies( updateDependencies );
258         config.setAutoVersionSubmodules( autoVersionSubmodules );
259         config.setAllowTimestampedSnapshots( allowTimestampedSnapshots );
260         config.setSnapshotReleasePluginAllowed( allowReleasePluginSnapshot );
261         config.setDefaultReleaseVersion( releaseVersion );
262         config.setDefaultDevelopmentVersion( developmentVersion );
263         config.setRemoteTagging( remoteTagging );
264         config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions );
265         config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTag );
266         config.setWaitBeforeTagging( waitBeforeTagging );
267         config.setProjectVersionPolicyId( projectVersionPolicyId );
268 
269         if ( checkModificationExcludeList != null )
270         {
271             checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," );
272         }
273 
274         if ( checkModificationExcludes != null )
275         {
276             config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) );
277         }
278 
279         // Create a config containing values from the session properties (ie command line properties with cli).
280         ReleaseDescriptor sysPropertiesConfig =
281             ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() );
282         mergeCommandLineConfig( config, sysPropertiesConfig );
283 
284         try
285         {
286             releaseManager.prepare( config, getReleaseEnvironment(), getReactorProjects(), resume, dryRun );
287         }
288         catch ( ReleaseExecutionException e )
289         {
290             throw new MojoExecutionException( e.getMessage(), e );
291         }
292         catch ( ReleaseFailureException e )
293         {
294             throw new MojoFailureException( e.getMessage(), e );
295         }
296     }
297 
298 }