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 (http://jira.codehaus.org/browse/SCM-406)
57       *
58       * @since 1.3
59       */    
60      @Parameter( property = "remoteBranching", defaultValue = "true" )
61      private boolean remoteBranching;     
62  
63      /** {@inheritDoc} */
64      public void execute()
65          throws MojoExecutionException
66      {
67          super.execute();
68  
69          try
70          {
71              ScmRepository repository = getScmRepository();
72              ScmProvider provider = getScmManager().getProviderByRepository( repository );
73  
74              String finalBranch = provider.sanitizeTagName( branch );
75              getLog().info( "Final Branch Name: '" + finalBranch + "'" );
76  
77              ScmBranchParameters scmBranchParameters = new ScmBranchParameters( message );
78              scmBranchParameters.setRemoteBranching( remoteBranching );
79              
80              BranchScmResult result = provider.branch( repository, getFileSet(), finalBranch, scmBranchParameters );
81  
82              checkResult( result );
83          }
84          catch ( IOException e )
85          {
86              throw new MojoExecutionException( "Cannot run branch command : ", e );
87          }
88          catch ( ScmException e )
89          {
90              throw new MojoExecutionException( "Cannot run branch command : ", e );
91          }
92      }
93  }