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.config.ReleaseDescriptor; 29 import org.codehaus.plexus.util.StringUtils; 30 31 /** 32 * Perform a release from SCM, either from a specified tag, or the tag representing the previous release in 33 * the working copy created by <tt>release:prepare</tt>. 34 * 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>. 35 * 36 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 37 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 38 * @version $Id: PerformReleaseMojo.html 816536 2012-05-08 11:41:06Z hboutemy $ 39 * @aggregator 40 * @requiresProject false 41 * @goal perform 42 */ 43 public class PerformReleaseMojo 44 extends AbstractReleaseMojo 45 { 46 /** 47 * A space separated list of goals to execute on deployment. Default value is either <code>deploy</code> or 48 * <code>deploy site-deploy</code>, if the project has a <distributionManagement>/<site> element. 49 * 50 * @parameter expression="${goals}" 51 */ 52 private String goals; 53 54 /** 55 * Comma separated profiles to enable on deployment, in addition to active profiles for project execution. 56 * 57 * @parameter expression="${releaseProfiles}" 58 * @since 2.0-beta-8 59 */ 60 private String releaseProfiles; 61 62 /** 63 * The checkout directory. 64 * 65 * @parameter expression="${workingDirectory}" default-value="${project.build.directory}/checkout" 66 * @required 67 */ 68 private File workingDirectory; 69 70 /** 71 * The SCM URL to checkout from. If omitted, the one from the <code>release.properties</code> file is used, followed 72 * by the URL from the current POM. 73 * 74 * @parameter expression="${connectionUrl}" 75 */ 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 * If set to true, the release plugin sets the property "performRelease" to true, which activates the profile 81 * "release-profile", which is inherited from the super pom. 82 * 83 * @parameter expression="${useReleaseProfile}" default-value="true" 84 */ 85 private boolean useReleaseProfile; 86 87 /** 88 * {@inheritDoc} 89 */ 90 protected String getAdditionalProfiles() 91 { 92 return releaseProfiles; 93 } 94 95 /** 96 * {@inheritDoc} 97 */ 98 public void execute() 99 throws MojoExecutionException, MojoFailureException 100 { 101 super.execute(); 102 103 // goals may be splitted into multiple line in configuration. 104 // Let's build a single line command 105 if ( goals != null ) 106 { 107 goals = StringUtils.join( StringUtils.split( goals ), " " ); 108 } 109 110 try 111 { 112 // Note that the working directory here is not the same as in the release configuration, so don't reuse that 113 ReleaseDescriptor releaseDescriptor = createReleaseDescriptor(); 114 if ( connectionUrl != null ) 115 { 116 releaseDescriptor.setScmSourceUrl( connectionUrl ); 117 } 118 119 releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() ); 120 releaseDescriptor.setUseReleaseProfile( useReleaseProfile ); 121 122 if ( goals == null ) 123 { 124 // set default 125 goals = "deploy"; 126 if ( project.getDistributionManagement() != null 127 && project.getDistributionManagement().getSite() != null ) 128 { 129 goals += " site-deploy"; 130 } 131 } 132 releaseDescriptor.setPerformGoals( goals ); 133 134 releaseManager.perform( releaseDescriptor, getReleaseEnvironment(), reactorProjects ); 135 } 136 catch ( ReleaseExecutionException e ) 137 { 138 throw new MojoExecutionException( e.getMessage(), e ); 139 } 140 catch ( ReleaseFailureException e ) 141 { 142 throw new MojoFailureException( e.getMessage(), e ); 143 } 144 } 145 }