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
65
66
67
68
69
70
71 @Parameter( property = "pinExternals", defaultValue = "false" )
72 private boolean pinExternals;
73
74
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 }