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 1389085 2012-09-23 15:50:37Z rfscholte $
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 second 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      * {@inheritDoc}
222      */
223     public void execute()
224         throws MojoExecutionException, MojoFailureException
225     {
226         if ( generateReleasePoms )
227         {
228             throw new MojoFailureException(
229                                             "Generating release POMs is no longer supported in release:prepare. Please run release:prepare-with-pom instead." );
230         }
231 
232         prepareRelease( generateReleasePoms );
233     }
234 
235     protected void prepareRelease( boolean generateReleasePoms )
236         throws MojoExecutionException, MojoFailureException
237     {
238         // this is here so the subclass can call it without getting the extra generateReleasePoms check in execute()
239         // above
240         super.execute();
241 
242         ReleaseDescriptor config = createReleaseDescriptor();
243         config.setAddSchema( addSchema );
244         config.setGenerateReleasePoms( generateReleasePoms );
245         config.setScmUseEditMode( useEditMode );
246         config.setPreparationGoals( preparationGoals );
247         config.setCompletionGoals( completionGoals );
248         config.setCommitByProject( commitByProject );
249         config.setUpdateDependencies( updateDependencies );
250         config.setAutoVersionSubmodules( autoVersionSubmodules );
251         config.setAllowTimestampedSnapshots( allowTimestampedSnapshots );
252         config.setSnapshotReleasePluginAllowed( allowReleasePluginSnapshot );
253         config.setDefaultReleaseVersion( releaseVersion );
254         config.setDefaultDevelopmentVersion( developmentVersion );
255         config.setRemoteTagging( remoteTagging );
256         config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions );
257         config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTag );
258         config.setWaitBeforeTagging( waitBeforeTagging );
259 
260         if ( checkModificationExcludeList != null )
261         {
262             checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," );
263         }
264 
265         if ( checkModificationExcludes != null )
266         {
267             config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) );
268         }
269 
270         // Create a config containing values from the session properties (ie command line properties with cli).
271         ReleaseDescriptor sysPropertiesConfig =
272             ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() );
273         mergeCommandLineConfig( config, sysPropertiesConfig );
274 
275         try
276         {
277             releaseManager.prepare( config, getReleaseEnvironment(), getReactorProjects(), resume, dryRun );
278         }
279         catch ( ReleaseExecutionException e )
280         {
281             throw new MojoExecutionException( e.getMessage(), e );
282         }
283         catch ( ReleaseFailureException e )
284         {
285             throw new MojoFailureException( e.getMessage(), e );
286         }
287     }
288 
289 }