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 (http://jira.codehaus.org/browse/SCM-406) 057 * 058 * @since 1.3 059 */ 060 @Parameter( property = "remoteBranching", defaultValue = "true" ) 061 private boolean remoteBranching; 062 063 /** {@inheritDoc} */ 064 public void execute() 065 throws MojoExecutionException 066 { 067 super.execute(); 068 069 try 070 { 071 ScmRepository repository = getScmRepository(); 072 ScmProvider provider = getScmManager().getProviderByRepository( repository ); 073 074 String finalBranch = provider.sanitizeTagName( branch ); 075 getLog().info( "Final Branch Name: '" + finalBranch + "'" ); 076 077 ScmBranchParameters scmBranchParameters = new ScmBranchParameters( message ); 078 scmBranchParameters.setRemoteBranching( remoteBranching ); 079 080 BranchScmResult result = provider.branch( repository, getFileSet(), finalBranch, scmBranchParameters ); 081 082 checkResult( result ); 083 } 084 catch ( IOException e ) 085 { 086 throw new MojoExecutionException( "Cannot run branch command : ", e ); 087 } 088 catch ( ScmException e ) 089 { 090 throw new MojoExecutionException( "Cannot run branch command : ", e ); 091 } 092 } 093}