Coverage Report - org.apache.maven.plugins.release.PrepareReleaseMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
PrepareReleaseMojo
100%
29/29
50%
2/4
4
 
 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.plugin.MojoExecutionException;
 23  
 import org.apache.maven.plugin.MojoFailureException;
 24  
 import org.apache.maven.shared.release.ReleaseExecutionException;
 25  
 import org.apache.maven.shared.release.ReleaseFailureException;
 26  
 import org.apache.maven.shared.release.config.ReleaseDescriptor;
 27  
 import org.apache.maven.shared.release.config.ReleaseUtils;
 28  
 
 29  
 /**
 30  
  * Prepare for a release in SCM.
 31  
  *
 32  
  * @author <a href="mailto:jdcasey@apache.org">John Casey</a>
 33  
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
 34  
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
 35  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 36  
  * @version $Id$
 37  
  * @aggregator
 38  
  * @goal prepare
 39  
  * @requiresDependencyResolution test
 40  
  * @todo [!] check how this works with version ranges
 41  
  */
 42  3
 public class PrepareReleaseMojo
 43  
     extends AbstractReleaseMojo
 44  
 {
 45  
 
 46  
     /**
 47  
      * Resume a previous release attempt from the point where it was stopped.
 48  
      * 
 49  
      * @parameter expression="${resume}" default-value="true"
 50  
      */
 51  
     private boolean resume;
 52  
 
 53  
     /**
 54  
      * Whether to generate <code>release-pom.xml</code> files that contain resolved information about the project.
 55  
      * 
 56  
      * @parameter default-value="false" expression="${generateReleasePoms}"
 57  
      */
 58  
     private boolean generateReleasePoms;
 59  
 
 60  
     /**
 61  
      * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations.
 62  
      * 
 63  
      * @parameter expression="${useEditMode}" default-value="false"
 64  
      */
 65  
     private boolean useEditMode;
 66  
 
 67  
     /**
 68  
      * Whether to update dependencies version to the next development version.
 69  
      * 
 70  
      * @parameter expression="${updateDependencies}" default-value="true"
 71  
      */
 72  
     private boolean updateDependencies;
 73  
 
 74  
     /**
 75  
      * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the
 76  
      * version of each submodules.
 77  
      * 
 78  
      * @parameter expression="${autoVersionSubmodules}" default-value="false"
 79  
      */
 80  
     private boolean autoVersionSubmodules;
 81  
 
 82  
     /**
 83  
      * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout. Running
 84  
      * <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to poms and scm
 85  
      * operations (only listed on the console) are working as expected. Modified POMs are written alongside the
 86  
      * originals without modifying them.
 87  
      * 
 88  
      * @parameter expression="${dryRun}" default-value="false"
 89  
      */
 90  
     private boolean dryRun;
 91  
 
 92  
     /**
 93  
      * Whether to add a schema to the POM if it was previously missing on release.
 94  
      * 
 95  
      * @parameter expression="${addSchema}" default-value="true"
 96  
      */
 97  
     private boolean addSchema;
 98  
 
 99  
     /**
 100  
      * Goals to run as part of the preparation step, after transformation but before committing. Space delimited.
 101  
      * 
 102  
      * @parameter expression="${preparationGoals}" default-value="clean verify"
 103  
      */
 104  
     private String preparationGoals;
 105  
 
 106  
     /**
 107  
      * Commits to do are atomic or by project.
 108  
      * 
 109  
      * @parameter expression="${commitByProject}" default-value="false"
 110  
      */
 111  
     private boolean commitByProject;
 112  
 
 113  
     /**
 114  
      * Whether to allow timestamped SNAPSHOT dependencies. Default is to fail when finding any SNAPSHOT.
 115  
      * 
 116  
      * @parameter expression="${ignoreSnapshots}" default-value="false"
 117  
      */
 118  
     private boolean allowTimestampedSnapshots;
 119  
 
 120  
     /**
 121  
      * Whether to allow usage of a SNAPSHOT version of the Release Plugin. This in an internal property used to support
 122  
      * testing of the plugin itself in batch mode.
 123  
      * 
 124  
      * @parameter expression="${allowReleasePluginSnapshot}" default-value="false"
 125  
      * @readonly
 126  
      */
 127  
     private boolean allowReleasePluginSnapshot;
 128  
 
 129  
     /**
 130  
      * Default version to use when preparing a release or a branch.
 131  
      * 
 132  
      * @parameter expression="${releaseVersion}"
 133  
      */
 134  
     private String releaseVersion;
 135  
 
 136  
     /**
 137  
      * Default version to use for new local working copy.
 138  
      * 
 139  
      * @parameter expression="${developmentVersion}"
 140  
      */
 141  
     private String developmentVersion;
 142  
     
 143  
     /**
 144  
      * currently only implemented with svn scm. Enable a workaround to prevent issue 
 145  
      * due to svn client > 1.5.0 (http://jira.codehaus.org/browse/SCM-406)
 146  
      *      
 147  
      * 
 148  
      * @parameter expression="${remoteTagging}" default-value="true"
 149  
      * @since 2.0-beta-9
 150  
      */    
 151  
     private boolean remoteTagging;
 152  
     
 153  
     /**
 154  
      * {@inheritDoc}
 155  
      */
 156  
     public void execute()
 157  
         throws MojoExecutionException, MojoFailureException
 158  
     {
 159  3
         super.execute();
 160  
 
 161  3
         ReleaseDescriptor config = createReleaseDescriptor();
 162  3
         config.setAddSchema( addSchema );
 163  3
         config.setGenerateReleasePoms( generateReleasePoms );
 164  3
         config.setScmUseEditMode( useEditMode );
 165  3
         config.setPreparationGoals( preparationGoals );
 166  3
         config.setCommitByProject( commitByProject );
 167  3
         config.setUpdateDependencies( updateDependencies );
 168  3
         config.setAutoVersionSubmodules( autoVersionSubmodules );
 169  3
         config.setAllowTimestampedSnapshots( allowTimestampedSnapshots );
 170  3
         config.setSnapshotReleasePluginAllowed( allowReleasePluginSnapshot );
 171  3
         config.setDefaultReleaseVersion( releaseVersion );
 172  3
         config.setDefaultDevelopmentVersion( developmentVersion );
 173  3
         config.setRemoteTagging( remoteTagging );
 174  
 
 175  
         // Create a config containing values from the system properties (command line properties).
 176  3
         ReleaseDescriptor sysPropertiesConfig
 177  
                 = ReleaseUtils.copyPropertiesToReleaseDescriptor( System.getProperties() );
 178  3
         mergeCommandLineConfig( config, sysPropertiesConfig );
 179  
 
 180  
         try
 181  
         {
 182  3
             releaseManager.prepare( config, getReleaseEnvironment(), reactorProjects, resume, dryRun );
 183  
         }
 184  1
         catch ( ReleaseExecutionException e )
 185  
         {
 186  1
             throw new MojoExecutionException( e.getMessage(), e );
 187  
         }
 188  1
         catch ( ReleaseFailureException e )
 189  
         {
 190  1
             throw new MojoFailureException( e.getMessage() );
 191  1
         }
 192  1
     }
 193  
 
 194  
     /**
 195  
      * This method takes some of the release configuration picked up from the command line system properties and copies
 196  
      * it into the release config object.
 197  
      * 
 198  
      * @param config The release configuration to merge the system properties into, must not be <code>null</code>.
 199  
      * @param sysPropertiesConfig The configuration from the system properties to merge in, must not be
 200  
      *            <code>null</code>.
 201  
      */
 202  
     private void mergeCommandLineConfig( ReleaseDescriptor config, ReleaseDescriptor sysPropertiesConfig )
 203  
     {
 204  
         // If the user specifies versions, these should be override the existing versions
 205  3
         if ( sysPropertiesConfig.getReleaseVersions() != null )
 206  
         {
 207  3
             config.getReleaseVersions().putAll( sysPropertiesConfig.getReleaseVersions() );
 208  
         }
 209  3
         if ( sysPropertiesConfig.getDevelopmentVersions() != null )
 210  
         {
 211  3
             config.getDevelopmentVersions().putAll( sysPropertiesConfig.getDevelopmentVersions() );
 212  
         }
 213  3
     }
 214  
 
 215  
 }