001package org.apache.maven.scm.plugin; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.plugin.MojoExecutionException; 023import org.apache.maven.plugins.annotations.Mojo; 024import org.apache.maven.plugins.annotations.Parameter; 025import org.apache.maven.scm.ScmBranchParameters; 026import org.apache.maven.scm.ScmException; 027import org.apache.maven.scm.command.branch.BranchScmResult; 028import org.apache.maven.scm.provider.ScmProvider; 029import org.apache.maven.scm.repository.ScmRepository; 030 031import java.io.IOException; 032 033/** 034 * Branch the project. 035 * 036 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a> 037 */ 038@Mojo( name = "branch", aggregator = true ) 039public class BranchMojo 040 extends AbstractScmMojo 041{ 042 /** 043 * The branch name. 044 */ 045 @Parameter( property = "branch", required = true ) 046 private String branch; 047 048 /** 049 * The message applied to the tag creation. 050 */ 051 @Parameter( property = "message" ) 052 private String message; 053 054 /** 055 * currently only implemented with svn scm. Enable a workaround to prevent issue 056 * due to svn client > 1.5.0 (https://issues.apache.org/jira/browse/SCM-406) 057 * 058 * @since 1.3 059 */ 060 @Parameter( property = "remoteBranching", defaultValue = "true" ) 061 private boolean remoteBranching; 062 063 /** 064 * Currently only implemented with Subversion. Enable the "--pin-externals" 065 * option in svn copy commands which is new in Subversion 1.9. 066 * 067 * @since 1.11.0 068 * 069 * @see https://subversion.apache.org/docs/release-notes/1.9.html 070 */ 071 @Parameter( property = "pinExternals", defaultValue = "false" ) 072 private boolean pinExternals; 073 074 /** {@inheritDoc} */ 075 public void execute() 076 throws MojoExecutionException 077 { 078 super.execute(); 079 080 try 081 { 082 ScmRepository repository = getScmRepository(); 083 ScmProvider provider = getScmManager().getProviderByRepository( repository ); 084 085 String finalBranch = provider.sanitizeTagName( branch ); 086 getLog().info( "Final Branch Name: '" + finalBranch + "'" ); 087 088 ScmBranchParameters scmBranchParameters = new ScmBranchParameters( message ); 089 scmBranchParameters.setRemoteBranching( remoteBranching ); 090 scmBranchParameters.setPinExternals( pinExternals ); 091 092 BranchScmResult result = provider.branch( repository, getFileSet(), finalBranch, scmBranchParameters ); 093 094 checkResult( result ); 095 } 096 catch ( IOException | ScmException e ) 097 { 098 throw new MojoExecutionException( "Cannot run branch command", e ); 099 } 100 } 101}