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