1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.release;
20
21 import java.util.Arrays;
22
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.plugins.annotations.Parameter;
27 import org.apache.maven.shared.release.DefaultReleaseManagerListener;
28 import org.apache.maven.shared.release.ReleaseBranchRequest;
29 import org.apache.maven.shared.release.ReleaseExecutionException;
30 import org.apache.maven.shared.release.ReleaseFailureException;
31 import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
32 import org.codehaus.plexus.configuration.PlexusConfiguration;
33
34
35
36
37
38
39
40
41
42 @Mojo(name = "branch", aggregator = true)
43 public class BranchReleaseMojo extends AbstractScmReleaseMojo {
44
45
46
47
48
49 @Parameter(property = "branchName")
50 private String branchName;
51
52
53
54
55
56
57
58
59 @Parameter(property = "branchBase")
60 private String branchBase;
61
62
63
64
65
66
67 @Parameter(defaultValue = "false", property = "updateBranchVersions")
68 private boolean updateBranchVersions;
69
70
71
72
73
74
75 @Parameter(defaultValue = "true", property = "updateWorkingCopyVersions")
76 private boolean updateWorkingCopyVersions;
77
78
79
80
81
82
83
84
85
86
87
88
89
90 @Parameter(defaultValue = "false", property = "suppressCommitBeforeBranch")
91 private boolean suppressCommitBeforeBranch;
92
93
94
95
96
97
98 @Parameter(defaultValue = "true", property = "updateVersionsToSnapshot")
99 private boolean updateVersionsToSnapshot;
100
101
102
103
104
105
106 @Parameter(defaultValue = "false", property = "useEditMode")
107 private boolean useEditMode;
108
109
110
111
112
113
114 @Parameter(defaultValue = "true", property = "updateDependencies")
115 private boolean updateDependencies;
116
117
118
119
120
121
122
123 @Parameter(defaultValue = "false", property = "autoVersionSubmodules")
124 private boolean autoVersionSubmodules;
125
126
127
128
129
130
131
132
133
134 @Parameter(defaultValue = "false", property = "dryRun")
135 private boolean dryRun;
136
137
138
139
140
141
142 @Parameter(defaultValue = "true", property = "addSchema")
143 private boolean addSchema;
144
145
146
147
148
149
150
151 @Parameter(defaultValue = "true", property = "remoteTagging")
152 private boolean remoteTagging;
153
154
155
156
157
158
159
160
161
162 @Parameter
163 private String[] checkModificationExcludes;
164
165
166
167
168
169
170 @Parameter(property = "checkModificationExcludeList")
171 private String checkModificationExcludeList;
172
173
174
175
176
177
178
179 @Parameter(property = "releaseVersion")
180 private String releaseVersion;
181
182
183
184
185
186
187
188 @Parameter(property = "developmentVersion")
189 private String developmentVersion;
190
191
192
193
194
195
196
197
198 @Parameter(defaultValue = "default", property = "projectVersionPolicyId")
199 private String projectVersionPolicyId;
200
201
202
203
204
205
206 @Parameter(property = "projectVersionPolicyConfig")
207 private PlexusConfiguration projectVersionPolicyConfig;
208
209
210
211
212
213
214
215
216 @Parameter(property = "projectNamingPolicyId")
217 private String projectBranchNamingPolicyId;
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 @Parameter(defaultValue = "@{prefix} prepare branch @{releaseLabel}", property = "scmBranchCommitComment")
236 private String scmBranchCommitComment = "@{prefix} prepare branch @{releaseLabel}";
237
238
239
240
241
242
243
244 @Parameter(defaultValue = "false", property = "pinExternals")
245 private boolean pinExternals;
246
247 @Override
248 public void execute() throws MojoExecutionException, MojoFailureException {
249 super.execute();
250
251 final ReleaseDescriptorBuilder config = createReleaseDescriptor();
252 config.setAddSchema(addSchema);
253 config.setScmUseEditMode(useEditMode);
254 config.setUpdateDependencies(updateDependencies);
255 config.setAutoVersionSubmodules(autoVersionSubmodules);
256 config.setScmReleaseLabel(branchName);
257 config.setScmBranchBase(branchBase);
258 config.setBranchCreation(true);
259 config.setUpdateBranchVersions(updateBranchVersions);
260 config.setUpdateWorkingCopyVersions(updateWorkingCopyVersions);
261 config.setUpdateVersionsToSnapshot(updateVersionsToSnapshot);
262 config.setRemoteTagging(remoteTagging);
263 config.setDefaultReleaseVersion(releaseVersion);
264 config.setDefaultDevelopmentVersion(developmentVersion);
265 config.setSuppressCommitBeforeTagOrBranch(suppressCommitBeforeBranch);
266 config.setProjectVersionPolicyId(projectVersionPolicyId);
267 if (projectVersionPolicyConfig != null) {
268 config.setProjectVersionPolicyConfig(projectVersionPolicyConfig.toString());
269 }
270 config.setProjectNamingPolicyId(projectBranchNamingPolicyId);
271 config.setScmBranchCommitComment(scmBranchCommitComment);
272 config.setPinExternals(pinExternals);
273
274 if (checkModificationExcludeList != null) {
275 checkModificationExcludes =
276 checkModificationExcludeList.replaceAll("\\s", "").split(",");
277 }
278
279 if (checkModificationExcludes != null) {
280 config.setCheckModificationExcludes(Arrays.asList(checkModificationExcludes));
281 }
282
283 try {
284 ReleaseBranchRequest branchRequest = new ReleaseBranchRequest();
285 branchRequest.setReleaseDescriptorBuilder(config);
286 branchRequest.setReleaseEnvironment(getReleaseEnvironment());
287 branchRequest.setReactorProjects(getReactorProjects());
288 branchRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog(), dryRun));
289 branchRequest.setDryRun(dryRun);
290 branchRequest.setUserProperties(session.getUserProperties());
291
292 releaseManager.branch(branchRequest);
293 } catch (ReleaseExecutionException e) {
294 throw new MojoExecutionException(e.getMessage(), e);
295 } catch (ReleaseFailureException e) {
296 throw new MojoFailureException(e.getMessage(), e);
297 }
298 }
299 }