Coverage Report - org.apache.maven.plugins.release.StageReleaseMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
StageReleaseMojo
64%
16/25
30%
3/10
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 java.io.File;
 23  
 
 24  
 import org.apache.maven.plugin.MojoExecutionException;
 25  
 import org.apache.maven.plugin.MojoFailureException;
 26  
 import org.apache.maven.shared.release.ReleaseExecutionException;
 27  
 import org.apache.maven.shared.release.ReleaseFailureException;
 28  
 import org.apache.maven.shared.release.config.ReleaseDescriptor;
 29  
 import org.codehaus.plexus.util.StringUtils;
 30  
 
 31  
 /**
 32  
  * Perform a release from SCM to a staging repository.
 33  
  *
 34  
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
 35  
  * @version $Id: org.apache.maven.plugins.release.StageReleaseMojo.html 816525 2012-05-08 11:35:10Z hboutemy $
 36  
  * @aggregator
 37  
  * @requiresProject false
 38  
  * @goal stage
 39  
  * @since 2.0-beta-8
 40  
  */
 41  3
 public class StageReleaseMojo
 42  
     extends AbstractReleaseMojo
 43  
 {
 44  
     /**
 45  
      * A comma or space separated list of goals to execute on deployment. Default value is either <code>deploy</code> or
 46  
      * <code>deploy site-deploy</code>, if the project has a &lt;distributionManagement&gt;/&lt;site&gt; element.
 47  
      *
 48  
      * @parameter expression="${goals}"
 49  
      * @since 2.0-beta-8
 50  
      */
 51  
     private String goals;
 52  
 
 53  
     /**
 54  
      * Comma separated profiles to enable on deployment, in addition to active profiles for project execution.
 55  
      *
 56  
      * @parameter expression="${releaseProfiles}"
 57  
      * @since 2.0-beta-8
 58  
      */
 59  
     private String releaseProfiles;
 60  
 
 61  
     /**
 62  
      * The checkout directory.
 63  
      *
 64  
      * @parameter expression="${workingDirectory}" default-value="${project.build.directory}/checkout"
 65  
      * @required
 66  
      * @since 2.0-beta-8
 67  
      */
 68  
     private File workingDirectory;
 69  
 
 70  
     /**
 71  
      * The SCM URL to checkout from. If omitted, the one from the <code>release.properties</code> file is used, followed
 72  
      * by the URL from the current POM.
 73  
      *
 74  
      * @parameter expression="${connectionUrl}"
 75  
      * @since 2.0-beta-8
 76  
      */
 77  
     private String connectionUrl;
 78  
 
 79  
     /**
 80  
      * Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate.
 81  
      *
 82  
      * @parameter expression="${useReleaseProfile}" default-value="true"
 83  
      * @since 2.0-beta-8
 84  
      */
 85  
     private boolean useReleaseProfile;
 86  
 
 87  
     /**
 88  
      * URL of the staging repository to use.
 89  
      *
 90  
      * @parameter expression="${stagingRepository}"
 91  
      * @required
 92  
      * @since 2.0-beta-8
 93  
      */
 94  
     private String stagingRepository;
 95  
 
 96  
     /**
 97  
      * {@inheritDoc}
 98  
      */
 99  
     protected String getAdditionalProfiles()
 100  
     {
 101  0
         return releaseProfiles;
 102  
     }
 103  
 
 104  
     /**
 105  
      * {@inheritDoc}
 106  
      */
 107  
     public void execute()
 108  
         throws MojoExecutionException, MojoFailureException
 109  
     {
 110  3
         super.execute();
 111  
 
 112  
         // goals may be splitted into multiple line in configuration.
 113  
         // Let's build a single line command
 114  3
         if ( goals != null )
 115  
         {
 116  3
             goals = StringUtils.join( StringUtils.split( goals ), " " );
 117  
         }
 118  
 
 119  
         try
 120  
         {
 121  3
             addArgument( "-DaltDeploymentRepository=\"" + stagingRepository + "\"" );
 122  
 
 123  
             // Note that the working directory here is not the same as in the release configuration, so don't reuse that
 124  3
             ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
 125  3
             if ( connectionUrl != null )
 126  
             {
 127  0
                 releaseDescriptor.setScmSourceUrl( connectionUrl );
 128  
             }
 129  
 
 130  3
             releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
 131  3
             releaseDescriptor.setUseReleaseProfile( useReleaseProfile );
 132  
 
 133  3
             if ( goals == null )
 134  
             {
 135  
                 // set default
 136  0
                 goals = "deploy";
 137  0
                 if ( project.getDistributionManagement() != null
 138  
                     && project.getDistributionManagement().getSite() != null )
 139  
                 {
 140  0
                     goals += " site:stage-deploy";
 141  
                 }
 142  
             }
 143  
 
 144  3
             goals = StringUtils.replace( goals, "site-deploy", "site:stage-deploy" );
 145  3
             goals = StringUtils.replace( goals, "site:deploy", "site:stage-deploy" );
 146  
 
 147  3
             releaseDescriptor.setPerformGoals( goals );
 148  
 
 149  3
             releaseManager.perform( releaseDescriptor, getReleaseEnvironment(), reactorProjects, false );
 150  
         }
 151  0
         catch ( ReleaseExecutionException e )
 152  
         {
 153  0
             throw new MojoExecutionException( e.getMessage(), e );
 154  
         }
 155  0
         catch ( ReleaseFailureException e )
 156  
         {
 157  0
             throw new MojoFailureException( e.getMessage(), e );
 158  3
         }
 159  3
     }
 160  
 }