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.shared.release.ReleaseExecutionException;
27 import org.apache.maven.shared.release.ReleaseFailureException;
28 import org.apache.maven.shared.release.ReleasePerformRequest;
29 import org.apache.maven.shared.release.config.ReleaseDescriptor;
30 import org.codehaus.plexus.util.StringUtils;
31
32 /**
33 * Perform a release from SCM, either from a specified tag, or the tag representing the previous release in
34 * the working copy created by <tt>release:prepare</tt>.
35 * 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>.
36 *
37 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
38 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
39 * @version $Id: PerformReleaseMojo.java 1329473 2012-04-23 21:58:55Z rfscholte $
40 * @aggregator
41 * @requiresProject false
42 * @goal perform
43 */
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 <distributionManagement>/<site> element.
50 *
51 * @parameter expression="${goals}"
52 */
53 private String goals;
54
55 /**
56 * Comma separated profiles to enable on deployment, in addition to active profiles for project execution.
57 *
58 * @parameter expression="${releaseProfiles}"
59 * @since 2.0-beta-8
60 */
61 private String releaseProfiles;
62
63 /**
64 * The checkout directory.
65 *
66 * @parameter expression="${workingDirectory}" default-value="${project.build.directory}/checkout"
67 * @required
68 */
69 private File workingDirectory;
70
71 /**
72 * The SCM URL to checkout from. If omitted, the one from the <code>release.properties</code> file is used, followed
73 * by the URL from the current POM.
74 *
75 * @parameter expression="${connectionUrl}"
76 */
77 private String connectionUrl;
78
79 /**
80 * Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate.
81 * If set to true, the release plugin sets the property "performRelease" to true, which activates the profile
82 * "release-profile", which is inherited from the super pom.
83 *
84 * @parameter expression="${useReleaseProfile}" default-value="true"
85 */
86 private boolean useReleaseProfile;
87
88 /**
89 * {@inheritDoc}
90 */
91 protected String getAdditionalProfiles()
92 {
93 return releaseProfiles;
94 }
95
96 /**
97 * Dry run: don't checkout anything from the scm repository, or modify the checkout.
98 * The goals (by default at least {@code deploy}) will be executed against the <strong>current</strong> project.
99 *
100 * @parameter expression="${dryRun}" default-value="false"
101 */
102 private boolean dryRun;
103
104 /**
105 * {@inheritDoc}
106 */
107 public void execute()
108 throws MojoExecutionException, MojoFailureException
109 {
110 super.execute();
111
112 // goals may be splitted into multiple line in configuration.
113 // Let's build a single line command
114 if ( goals != null )
115 {
116 goals = StringUtils.join( StringUtils.split( goals ), " " );
117 }
118
119 try
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-deploy";
139 }
140 }
141 releaseDescriptor.setPerformGoals( goals );
142
143 ReleasePerformRequest performRequest = new ReleasePerformRequest();
144 performRequest.setReleaseDescriptor( releaseDescriptor );
145 performRequest.setReleaseEnvironment( getReleaseEnvironment() );
146 performRequest.setReactorProjects( getReactorProjects() );
147 performRequest.setDryRun( dryRun );
148
149 releaseManager.perform( performRequest );
150 }
151 catch ( ReleaseExecutionException e )
152 {
153 throw new MojoExecutionException( e.getMessage(), e );
154 }
155 catch ( ReleaseFailureException e )
156 {
157 throw new MojoFailureException( e.getMessage(), e );
158 }
159 }
160 }