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 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.
33   *
34   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
35   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
36   * @version $Id$
37   * @aggregator
38   * @requiresProject false
39   * @goal perform
40   */
41  public class PerformReleaseMojo
42      extends AbstractReleaseMojo
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       * @parameter expression="${goals}"
49       */
50      private String goals;
51  
52      /**
53       * Comma separated profiles to enable on deployment, in addition to active profiles for project execution.
54       * 
55       * @parameter expression="${releaseProfiles}"
56       */
57      private String releaseProfiles;
58  
59      /**
60       * The checkout directory.
61       * 
62       * @parameter expression="${workingDirectory}" default-value="${project.build.directory}/checkout"
63       * @required
64       */
65      private File workingDirectory;
66  
67      /**
68       * The SCM URL to checkout from. If omitted, the one from the <code>release.properties</code> file is used, followed
69       * by the URL from the current POM.
70       * 
71       * @parameter expression="${connectionUrl}"
72       */
73      private String connectionUrl;
74  
75      /**
76       * Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate.
77       * 
78       * @parameter expression="${useReleaseProfile}" default-value="true"
79       */
80      private boolean useReleaseProfile;
81  
82      /**
83       * {@inheritDoc}
84       */
85      protected String getAdditionalProfiles()
86      {
87          return releaseProfiles;
88      }
89  
90      /**
91       * {@inheritDoc}
92       */
93      public void execute()
94          throws MojoExecutionException, MojoFailureException
95      {
96          super.execute();
97  
98          // goals may be splitted into multiple line in configuration.
99          // Let's build a single line command
100         if ( goals != null )
101         {
102             goals = StringUtils.join( StringUtils.split( goals ), " " );
103         }
104 
105         try
106         {
107             // Note that the working directory here is not the same as in the release configuration, so don't reuse that
108             ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
109             if ( connectionUrl != null )
110             {
111                 releaseDescriptor.setScmSourceUrl( connectionUrl );
112             }
113 
114             releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
115             releaseDescriptor.setUseReleaseProfile( useReleaseProfile );
116 
117             if ( goals == null )
118             {
119                 // set default
120                 goals = "deploy";
121                 if ( project.getDistributionManagement() != null
122                     && project.getDistributionManagement().getSite() != null )
123                 {
124                     goals += " site-deploy";
125                 }
126             }
127             releaseDescriptor.setPerformGoals( goals );
128 
129             releaseManager.perform( releaseDescriptor, getReleaseEnvironment(), reactorProjects );
130         }
131         catch ( ReleaseExecutionException e )
132         {
133             throw new MojoExecutionException( e.getMessage(), e );
134         }
135         catch ( ReleaseFailureException e )
136         {
137             throw new MojoFailureException( e.getMessage() );
138         }
139     }
140 }