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 816529 2012-05-08 11:36:38Z 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 * 81 * @parameter expression="${useReleaseProfile}" default-value="true" 82 */ 83 private boolean useReleaseProfile; 84 85 /** 86 * {@inheritDoc} 87 */ 88 protected String getAdditionalProfiles() 89 { 90 return releaseProfiles; 91 } 92 93 /** 94 * {@inheritDoc} 95 */ 96 public void execute() 97 throws MojoExecutionException, MojoFailureException 98 { 99 super.execute(); 100 101 // goals may be splitted into multiple line in configuration. 102 // Let's build a single line command 103 if ( goals != null ) 104 { 105 goals = StringUtils.join( StringUtils.split( goals ), " " ); 106 } 107 108 try 109 { 110 // Note that the working directory here is not the same as in the release configuration, so don't reuse that 111 ReleaseDescriptor releaseDescriptor = createReleaseDescriptor(); 112 if ( connectionUrl != null ) 113 { 114 releaseDescriptor.setScmSourceUrl( connectionUrl ); 115 } 116 117 releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() ); 118 releaseDescriptor.setUseReleaseProfile( useReleaseProfile ); 119 120 if ( goals == null ) 121 { 122 // set default 123 goals = "deploy"; 124 if ( project.getDistributionManagement() != null 125 && project.getDistributionManagement().getSite() != null ) 126 { 127 goals += " site-deploy"; 128 } 129 } 130 releaseDescriptor.setPerformGoals( goals ); 131 132 releaseManager.perform( releaseDescriptor, getReleaseEnvironment(), reactorProjects ); 133 } 134 catch ( ReleaseExecutionException e ) 135 { 136 throw new MojoExecutionException( e.getMessage(), e ); 137 } 138 catch ( ReleaseFailureException e ) 139 { 140 throw new MojoFailureException( e.getMessage(), e ); 141 } 142 } 143 }