Coverage Report - org.apache.maven.plugins.release.PrepareReleaseMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
PrepareReleaseMojo
0%
0/34
0%
0/6
5
 
 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: org.apache.maven.plugins.release.PrepareReleaseMojo.html 816529 2012-05-08 11:36:38Z hboutemy $
 43  
  * @aggregator
 44  
  * @goal prepare
 45  
  * @todo [!] check how this works with version ranges
 46  
  */
 47  0
 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  
      * Commits to do are atomic or by project.
 115  
      *
 116  
      * @parameter expression="${commitByProject}" default-value="false"
 117  
      * @since 2.0-beta-5
 118  
      */
 119  
     private boolean commitByProject;
 120  
 
 121  
     /**
 122  
      * Whether to allow timestamped SNAPSHOT dependencies. Default is to fail when finding any SNAPSHOT.
 123  
      *
 124  
      * @parameter expression="${ignoreSnapshots}" default-value="false"
 125  
      * @since 2.0-beta-7
 126  
      */
 127  
     private boolean allowTimestampedSnapshots;
 128  
 
 129  
     /**
 130  
      * Whether to allow usage of a SNAPSHOT version of the Release Plugin. This in an internal property used to support
 131  
      * testing of the plugin itself in batch mode.
 132  
      *
 133  
      * @parameter expression="${allowReleasePluginSnapshot}" default-value="false"
 134  
      * @readonly
 135  
      * @since 2.0-beta-9
 136  
      */
 137  
     private boolean allowReleasePluginSnapshot;
 138  
 
 139  
      /**
 140  
      * Additional files that will skipped when checking for
 141  
      * modifications on the working copy.
 142  
      *
 143  
      * Is ignored, when checkModificationExcludes is set.
 144  
      *
 145  
      *
 146  
      * @parameter
 147  
      * @since 2.1
 148  
      */
 149  
     private String[] checkModificationExcludes;
 150  
 
 151  
     /**
 152  
      * Command-line version of checkModificationExcludes
 153  
      *
 154  
      *
 155  
      * @parameter expression="${checkModificationExcludeList}"
 156  
      * @since 2.1
 157  
      */
 158  
     private String checkModificationExcludeList;
 159  
 
 160  
     /**
 161  
      * Default version to use when preparing a release or a branch.
 162  
      *
 163  
      * @parameter expression="${releaseVersion}"
 164  
      * @since 2.0-beta-8
 165  
      */
 166  
     private String releaseVersion;
 167  
 
 168  
     /**
 169  
      * Default version to use for new local working copy.
 170  
      *
 171  
      * @parameter expression="${developmentVersion}"
 172  
      * @since 2.0-beta-8
 173  
      */
 174  
     private String developmentVersion;
 175  
 
 176  
     /**
 177  
      * Currently only implemented with svn scm.
 178  
      *
 179  
      * <ul>
 180  
      *   <li>Enables a workaround to prevent issue
 181  
      * due to svn client > 1.5.0 (fixed in 1.6.5)
 182  
      * (http://jira.codehaus.org/browse/SCM-406)</li>
 183  
      *   <li>You may not want to use this in conjunction
 184  
      * with <code>suppressCommitBeforeTag</code>, such that no poms with
 185  
      * released versions are committed to the working
 186  
      * copy ever.</li>
 187  
      * </ul>
 188  
      *
 189  
      * @parameter expression="${remoteTagging}" default-value="true"
 190  
      * @since 2.0-beta-9
 191  
      */
 192  
     private boolean remoteTagging;
 193  
 
 194  
     /**
 195  
      * Whether to bump the working copy versions to <code>developmentVersion</code>.
 196  
      *
 197  
      * @parameter expression="${updateWorkingCopyVersions}" default-value="true"
 198  
      * @since 2.1
 199  
      */
 200  
     private boolean updateWorkingCopyVersions;
 201  
 
 202  
     /**
 203  
      * Whether to suppress a commit of changes to the working copy
 204  
      * before the tag is created.
 205  
      * <br/>
 206  
      * <br/>This requires <code>remoteTagging</code> to be set to false.
 207  
      * <br/>
 208  
      * <br/><code>suppressCommitBeforeTag</code> is useful when you want
 209  
      * to avoid poms with released versions in all revisions of your
 210  
      * trunk or development branch.
 211  
      *
 212  
      * @parameter expression="${suppressCommitBeforeTag}" default-value="false"
 213  
      * @since 2.1
 214  
      */
 215  
     private boolean suppressCommitBeforeTag;
 216  
 
 217  
     /**
 218  
      * @parameter expression="${session}"
 219  
      * @readonly
 220  
      * @required
 221  
      * @since 2.0
 222  
      */
 223  
     protected MavenSession session;
 224  
 
 225  
     /**
 226  
      * {@inheritDoc}
 227  
      */
 228  
     public void execute()
 229  
         throws MojoExecutionException, MojoFailureException
 230  
     {
 231  0
         if ( generateReleasePoms )
 232  
         {
 233  0
             throw new MojoFailureException(
 234  
                 "Generating release POMs is no longer supported in release:prepare. Please run release:prepare-with-pom instead." );
 235  
         }
 236  
 
 237  0
         prepareRelease( generateReleasePoms );
 238  0
     }
 239  
 
 240  
     protected void prepareRelease( boolean generateReleasePoms )
 241  
         throws MojoExecutionException, MojoFailureException
 242  
     {
 243  
         // this is here so the subclass can call it without getting the extra generateReleasePoms check in execute() above
 244  0
         super.execute();
 245  
 
 246  0
         ReleaseDescriptor config = createReleaseDescriptor();
 247  0
         config.setAddSchema( addSchema );
 248  0
         config.setGenerateReleasePoms( generateReleasePoms );
 249  0
         config.setScmUseEditMode( useEditMode );
 250  0
         config.setPreparationGoals( preparationGoals );
 251  0
         config.setCommitByProject( commitByProject );
 252  0
         config.setUpdateDependencies( updateDependencies );
 253  0
         config.setAutoVersionSubmodules( autoVersionSubmodules );
 254  0
         config.setAllowTimestampedSnapshots( allowTimestampedSnapshots );
 255  0
         config.setSnapshotReleasePluginAllowed( allowReleasePluginSnapshot );
 256  0
         config.setDefaultReleaseVersion( releaseVersion );
 257  0
         config.setDefaultDevelopmentVersion( developmentVersion );
 258  0
         config.setRemoteTagging( remoteTagging );
 259  0
         config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions );
 260  0
         config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTag );
 261  
 
 262  0
         if ( checkModificationExcludeList != null )
 263  
         {
 264  0
             checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," );
 265  
         }
 266  
 
 267  0
         if ( checkModificationExcludes != null )
 268  
         {
 269  0
             config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) );
 270  
         }
 271  
 
 272  
         // Create a config containing values from the session properties (ie command line properties with cli).
 273  0
         ReleaseDescriptor sysPropertiesConfig
 274  
                 = ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() );
 275  0
         mergeCommandLineConfig( config, sysPropertiesConfig );
 276  
 
 277  
         try
 278  
         {
 279  0
             releaseManager.prepare( config, getReleaseEnvironment(), reactorProjects, resume, dryRun );
 280  
         }
 281  0
         catch ( ReleaseExecutionException e )
 282  
         {
 283  0
             throw new MojoExecutionException( e.getMessage(), e );
 284  
         }
 285  0
         catch ( ReleaseFailureException e )
 286  
         {
 287  0
             throw new MojoFailureException( e.getMessage(), e );
 288  0
         }
 289  0
     }
 290  
 
 291  
 }