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