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