1 package org.apache.maven.scm.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
35
36
37
38 @Mojo( name = "branch", aggregator = true )
39 public class BranchMojo
40 extends AbstractScmMojo
41 {
42
43
44
45 @Parameter( property = "branch", required = true )
46 private String branch;
47
48
49
50
51 @Parameter( property = "message" )
52 private String message;
53
54
55
56
57
58
59
60 @Parameter( property = "remoteBranching", defaultValue = "true" )
61 private boolean remoteBranching;
62
63
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 }