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 1430485 2013-01-08 20:20:17Z 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       * Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate.
89       * If set to true, the release plugin sets the property "performRelease" to true, which activates the profile
90       * "release-profile", which is inherited from the super pom.
91       */
92      @Parameter( defaultValue = "true", property = "useReleaseProfile" )
93      private boolean useReleaseProfile;
94  
95      /**
96       * Dry run: don't checkout anything from the scm repository, or modify the checkout.
97       * The goals (by default at least {@code deploy}) will <strong>not</strong> be executed.
98       */
99      @Parameter( defaultValue = "false", property = "dryRun" )
100     private boolean dryRun;
101 
102     /**
103      * {@inheritDoc}
104      */
105     protected String getAdditionalProfiles()
106     {
107         return releaseProfiles;
108     }
109     
110     /**
111      * {@inheritDoc}
112      */
113     public void execute()
114         throws MojoExecutionException, MojoFailureException
115     {
116         // goals may be splitted into multiple line in configuration.
117         // Let's build a single line command
118         if ( goals != null )
119         {
120             goals = StringUtils.join( StringUtils.split( goals ), " " );
121         }
122 
123         try
124         {
125             // Note that the working directory here is not the same as in the release configuration, so don't reuse that
126             ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
127             if ( connectionUrl != null )
128             {
129                 releaseDescriptor.setScmSourceUrl( connectionUrl );
130             }
131             releaseDescriptor.setLocalCheckout( localCheckout );
132 
133             releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
134             releaseDescriptor.setUseReleaseProfile( useReleaseProfile );
135 
136             if ( goals == null )
137             {
138                 // set default
139                 goals = "deploy";
140                 if ( project.getDistributionManagement() != null
141                     && project.getDistributionManagement().getSite() != null )
142                 {
143                     goals += " site-deploy";
144                 }
145             }
146             releaseDescriptor.setPerformGoals( goals );
147             
148             ReleasePerformRequest performRequest  = new ReleasePerformRequest();
149             performRequest.setReleaseDescriptor( releaseDescriptor );
150             performRequest.setReleaseEnvironment( getReleaseEnvironment() );
151             performRequest.setReactorProjects( getReactorProjects() );
152             performRequest.setDryRun( dryRun );
153 
154             releaseManager.perform( performRequest );
155         }
156         catch ( ReleaseExecutionException e )
157         {
158             throw new MojoExecutionException( e.getMessage(), e );
159         }
160         catch ( ReleaseFailureException e )
161         {
162             throw new MojoFailureException( e.getMessage(), e );
163         }
164     }
165 }