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.config.ReleaseDescriptor;
31  import org.codehaus.plexus.util.StringUtils;
32  
33  /**
34   * Perform a release from SCM to a staging repository.
35   * 
36   * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
37   * @version $Id: StageReleaseMojo.java 1420401 2012-12-11 20:58:35Z rfscholte $
38   * @since 2.0-beta-8
39   */
40  @Mojo( name = "stage", aggregator = true, requiresProject = false )
41  public class StageReleaseMojo
42      extends AbstractScmReleaseMojo
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       * @since 2.0-beta-8
49       */
50      @Parameter( property = "goals" )
51      private String goals;
52  
53      /**
54       * Comma separated profiles to enable on deployment, in addition to active profiles for project execution.
55       * 
56       * @since 2.0-beta-8
57       */
58      @Parameter( property = "releaseProfiles" )
59      private String releaseProfiles;
60  
61      /**
62       * The checkout directory.
63       * 
64       * @since 2.0-beta-8
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       * @since 2.0-beta-8
74       */
75      @Parameter( property = "connectionUrl" )
76      private String connectionUrl;
77  
78      /**
79       * Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate.
80       * 
81       * @since 2.0-beta-8
82       */
83      @Parameter( defaultValue = "true", property = "useReleaseProfile" )
84      private boolean useReleaseProfile;
85  
86      /**
87       * URL of the staging repository to use.
88       * 
89       * @since 2.0-beta-8
90       */
91      @Parameter( property = "stagingRepository", required = true )
92      private String stagingRepository;
93  
94      /**
95       * {@inheritDoc}
96       */
97      protected String getAdditionalProfiles()
98      {
99          return releaseProfiles;
100     }
101 
102     /**
103      * {@inheritDoc}
104      */
105     public void execute()
106         throws MojoExecutionException, MojoFailureException
107     {
108         super.execute();
109 
110         // goals may be splitted into multiple line in configuration.
111         // Let's build a single line command
112         if ( goals != null )
113         {
114             goals = StringUtils.join( StringUtils.split( goals ), " " );
115         }
116 
117         try
118         {
119             addArgument( "-DaltDeploymentRepository=\"" + stagingRepository + "\"" );
120 
121             // Note that the working directory here is not the same as in the release configuration, so don't reuse that
122             ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
123             if ( connectionUrl != null )
124             {
125                 releaseDescriptor.setScmSourceUrl( connectionUrl );
126             }
127 
128             releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
129             releaseDescriptor.setUseReleaseProfile( useReleaseProfile );
130 
131             if ( goals == null )
132             {
133                 // set default
134                 goals = "deploy";
135                 if ( project.getDistributionManagement() != null
136                     && project.getDistributionManagement().getSite() != null )
137                 {
138                     goals += " site:stage-deploy";
139                 }
140             }
141 
142             goals = StringUtils.replace( goals, "site-deploy", "site:stage-deploy" );
143             goals = StringUtils.replace( goals, "site:deploy", "site:stage-deploy" );
144 
145             releaseDescriptor.setPerformGoals( goals );
146 
147             releaseManager.perform( releaseDescriptor, getReleaseEnvironment(), getReactorProjects(), false );
148         }
149         catch ( ReleaseExecutionException e )
150         {
151             throw new MojoExecutionException( e.getMessage(), e );
152         }
153         catch ( ReleaseFailureException e )
154         {
155             throw new MojoFailureException( e.getMessage(), e );
156         }
157     }
158 }