View Javadoc
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.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.Parameter;
25  import org.apache.maven.scm.ScmBranchParameters;
26  import org.apache.maven.scm.ScmException;
27  import org.apache.maven.scm.command.branch.BranchScmResult;
28  import org.apache.maven.scm.provider.ScmProvider;
29  import org.apache.maven.scm.repository.ScmRepository;
30  
31  import java.io.IOException;
32  
33  /**
34   * Branch the project.
35   *
36   * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
37   */
38  @Mojo( name = "branch", aggregator = true )
39  public class BranchMojo
40      extends AbstractScmMojo
41  {
42      /**
43       * The branch name.
44       */
45      @Parameter( property = "branch", required = true )
46      private String branch;
47  
48      /**
49       * The message applied to the tag creation.
50       */
51      @Parameter( property = "message" )
52      private String message;
53      
54      /**
55       * currently only implemented with svn scm. Enable a workaround to prevent issue 
56       * due to svn client > 1.5.0 (https://issues.apache.org/jira/browse/SCM-406)
57       *
58       * @since 1.3
59       */    
60      @Parameter( property = "remoteBranching", defaultValue = "true" )
61      private boolean remoteBranching;     
62  
63      /**
64       * Currently only implemented with Subversion. Enable the "--pin-externals"
65       * option in svn copy commands which is new in Subversion 1.9.
66       *
67       * @since 1.11.0
68       *
69       * @see https://subversion.apache.org/docs/release-notes/1.9.html
70       */
71      @Parameter( property = "pinExternals", defaultValue = "false" )
72      private boolean pinExternals;
73  
74      /** {@inheritDoc} */
75      public void execute()
76          throws MojoExecutionException
77      {
78          super.execute();
79  
80          try
81          {
82              ScmRepository repository = getScmRepository();
83              ScmProvider provider = getScmManager().getProviderByRepository( repository );
84  
85              String finalBranch = provider.sanitizeTagName( branch );
86              getLog().info( "Final Branch Name: '" + finalBranch + "'" );
87  
88              ScmBranchParameters scmBranchParameters = new ScmBranchParameters( message );
89              scmBranchParameters.setRemoteBranching( remoteBranching );
90              scmBranchParameters.setPinExternals( pinExternals );
91              
92              BranchScmResult result = provider.branch( repository, getFileSet(), finalBranch, scmBranchParameters );
93  
94              checkResult( result );
95          }
96          catch ( IOException e )
97          {
98              throw new MojoExecutionException( "Cannot run branch command", e );
99          }
100         catch ( ScmException e )
101         {
102             throw new MojoExecutionException( "Cannot run branch command", e );
103         }
104     }
105 }