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