1 package org.apache.maven.scm.plugin;
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 org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.scm.ScmBranchParameters;
24 import org.apache.maven.scm.ScmException;
25 import org.apache.maven.scm.command.branch.BranchScmResult;
26 import org.apache.maven.scm.provider.ScmProvider;
27 import org.apache.maven.scm.repository.ScmRepository;
28
29 import java.io.IOException;
30
31 /**
32 * Branch the project.
33 *
34 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
35 *
36 * @goal branch
37 * @aggregator
38 */
39 public class BranchMojo
40 extends AbstractScmMojo
41 {
42 /**
43 * The branch name.
44 *
45 * @parameter expression="${branch}"
46 * @required
47 */
48 private String branch;
49
50 /**
51 * The message applied to the tag creation.
52 *
53 * @parameter expression="${message}"
54 */
55 private String message;
56
57 /**
58 * currently only implemented with svn scm. Enable a workaround to prevent issue
59 * due to svn client > 1.5.0 (http://jira.codehaus.org/browse/SCM-406)
60 *
61 *
62 * @parameter expression="${remoteBranching}" default-value="true"
63 * @since 1.3
64 */
65 private boolean remoteBranching;
66
67 /** {@inheritDoc} */
68 public void execute()
69 throws MojoExecutionException
70 {
71 super.execute();
72
73 try
74 {
75 ScmRepository repository = getScmRepository();
76 ScmProvider provider = getScmManager().getProviderByRepository( repository );
77
78 String finalBranch = provider.sanitizeTagName( branch );
79 getLog().info( "Final Branch Name: '" + finalBranch + "'" );
80
81 ScmBranchParameters scmBranchParameters = new ScmBranchParameters( message );
82 scmBranchParameters.setRemoteBranching( remoteBranching );
83
84 BranchScmResult result = provider.branch( repository, getFileSet(), finalBranch, scmBranchParameters );
85
86 checkResult( result );
87 }
88 catch ( IOException e )
89 {
90 throw new MojoExecutionException( "Cannot run branch command : ", e );
91 }
92 catch ( ScmException e )
93 {
94 throw new MojoExecutionException( "Cannot run branch command : ", e );
95 }
96 }
97 }