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 java.io.File;
23  
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.plugin.MojoFailureException;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.Parameter;
28  import org.apache.maven.shared.release.ReleaseExecutionException;
29  import org.apache.maven.shared.release.ReleaseFailureException;
30  import org.apache.maven.shared.release.ReleasePerformRequest;
31  import org.apache.maven.shared.release.config.ReleaseDescriptor;
32  import org.codehaus.plexus.util.StringUtils;
33  
34  /**
35   * Perform a release from SCM, either from a specified tag, or the tag representing the previous release in
36   * the working copy created by <tt>release:prepare</tt>.
37   * For more info see <a href="http://maven.apache.org/plugins/maven-release-plugin/examples/perform-release.html"
38   * >http://maven.apache.org/plugins/maven-release-plugin/examples/perform-release.html</a>.
39   *
40   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
41   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
42   * @version $Id: PerformReleaseMojo.java 1672745 2015-04-10 20:08:41Z mfriedenhagen $
43   */
44  @Mojo( name = "perform", aggregator = true, requiresProject = false )
45  public class PerformReleaseMojo
46      extends AbstractReleaseMojo
47  {
48      /**
49       * A space separated list of goals to execute on deployment. Default value is either <code>deploy</code> or
50       * <code>deploy site-deploy</code>, if the project has a &lt;distributionManagement&gt;/&lt;site&gt; element.
51       */
52      @Parameter( property = "goals" )
53      String goals;
54  
55      /**
56       * Comma separated profiles to enable on deployment, in addition to active profiles for project execution.
57       *
58       * @since 2.0-beta-8
59       */
60      @Parameter( property = "releaseProfiles" )
61      private String releaseProfiles;
62  
63      /**
64       * The checkout directory.
65       */
66      @Parameter( defaultValue = "${project.build.directory}/checkout", property = "workingDirectory", required = true )
67      private File workingDirectory;
68  
69      /**
70       * The SCM URL to checkout from. If omitted, the one from the <code>release.properties</code> file is used, followed
71       * by the URL from the current POM.
72       */
73      @Parameter( property = "connectionUrl" )
74      private String connectionUrl;
75  
76      /**
77       * Use a local checkout instead of doing a checkout from the upstream repository.
78       * ATTENTION: This will only work with distributed SCMs which support the file:// protocol
79       * like e.g. git, jgit or hg!
80       *
81       * TODO: we should think about having the defaults for the various SCM providers provided via modello!
82       *
83       * @since 2.0 for release:perform and 2.5.2 for release:stage
84       */
85      @Parameter( defaultValue = "false", property = "localCheckout" )
86      private boolean localCheckout;
87      
88      /**
89       * The SCM username to use.
90       */
91      @Parameter( property = "username" )
92      private String username;
93  
94      /**
95       * The SCM password to use.
96       */
97      @Parameter( property = "password" )
98      private String password;
99      
100     /**
101      * Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate.
102      * If set to true, the release plugin sets the property "performRelease" to true, which activates the profile
103      * "release-profile", which is inherited from the super pom.
104      */
105     @Parameter( defaultValue = "true", property = "useReleaseProfile" )
106     private boolean useReleaseProfile;
107 
108     /**
109      * Dry run: don't checkout anything from the scm repository, or modify the checkout.
110      * The goals (by default at least {@code deploy}) will <strong>not</strong> be executed.
111      */
112     @Parameter( defaultValue = "false", property = "dryRun" )
113     private boolean dryRun;
114 
115     /**
116      * {@inheritDoc}
117      */
118     protected String getAdditionalProfiles()
119     {
120         return releaseProfiles;
121     }
122     
123     /**
124      * {@inheritDoc}
125      */
126     public void execute()
127         throws MojoExecutionException, MojoFailureException
128     {
129         // goals may be splitted into multiple line in configuration.
130         // Let's build a single line command
131         if ( goals != null )
132         {
133             goals = StringUtils.join( StringUtils.split( goals ), " " );
134         }
135 
136         try
137         {
138             setDeploymentRepository();
139             // Note that the working directory here is not the same as in the release configuration, so don't reuse that
140             ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
141             if ( connectionUrl != null )
142             {
143                 releaseDescriptor.setScmSourceUrl( connectionUrl );
144             }
145             
146             if ( username != null )
147             {
148                 releaseDescriptor.setScmUsername( username );
149             }
150             
151             if ( password != null )
152             {
153                 releaseDescriptor.setScmPassword( password );
154             }
155             
156             releaseDescriptor.setLocalCheckout( localCheckout );
157 
158             releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
159             releaseDescriptor.setUseReleaseProfile( useReleaseProfile );
160 
161             createGoals();
162             releaseDescriptor.setPerformGoals( goals );
163             
164             ReleasePerformRequest performRequest  = new ReleasePerformRequest();
165             performRequest.setReleaseDescriptor( releaseDescriptor );
166             performRequest.setReleaseEnvironment( getReleaseEnvironment() );
167             performRequest.setReactorProjects( getReactorProjects() );
168             performRequest.setDryRun( dryRun );
169 
170             releaseManager.perform( performRequest );
171         }
172         catch ( ReleaseExecutionException e )
173         {
174             throw new MojoExecutionException( e.getMessage(), e );
175         }
176         catch ( ReleaseFailureException e )
177         {
178             throw new MojoFailureException( e.getMessage(), e );
179         }
180     }
181 
182     /** Just here so it may be overridden by StageReleaseMojo */
183     void setDeploymentRepository()
184     {
185     }
186 
187     /** Just here so it may be overridden by StageReleaseMojo */
188     void createGoals()
189     {
190         if ( goals == null )
191         {
192             // set default
193             goals = "deploy";
194             if ( project.getDistributionManagement() != null
195                 && project.getDistributionManagement().getSite() != null )
196             {
197                 goals += " site-deploy";
198             }
199         }
200     }
201 }