Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BranchReleaseMojo |
|
| 7.0;7 |
1 | package org.apache.maven.plugins.release; | |
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.plugin.MojoFailureException; | |
24 | import org.apache.maven.shared.release.ReleaseExecutionException; | |
25 | import org.apache.maven.shared.release.ReleaseFailureException; | |
26 | import org.apache.maven.shared.release.config.ReleaseDescriptor; | |
27 | import org.codehaus.plexus.util.StringUtils; | |
28 | ||
29 | /** | |
30 | * Branch a project in SCM. | |
31 | * | |
32 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> | |
33 | * @version $Id$ | |
34 | * @aggregator | |
35 | * @goal branch | |
36 | */ | |
37 | 0 | public class BranchReleaseMojo |
38 | extends AbstractReleaseMojo | |
39 | { | |
40 | /** | |
41 | * The branch name to use. | |
42 | * | |
43 | * @parameter expression="${branchName}" | |
44 | */ | |
45 | private String branchName; | |
46 | ||
47 | /** | |
48 | * Whether to update versions in the branch. | |
49 | * | |
50 | * @parameter expression="${updateBranchVersions}" default-value="false" | |
51 | */ | |
52 | private boolean updateBranchVersions; | |
53 | ||
54 | /** | |
55 | * Whether to update versions in the working copy. | |
56 | * | |
57 | * @parameter expression="${updateWorkingCopyVersions}" default-value="true" | |
58 | */ | |
59 | private boolean updateWorkingCopyVersions; | |
60 | ||
61 | /** | |
62 | * Whether to update versions to SNAPSHOT in the branch. | |
63 | * | |
64 | * @parameter expression="${updateVersionsToSnapshot}" default-value="true" | |
65 | */ | |
66 | private boolean updateVersionsToSnapshot; | |
67 | ||
68 | /** | |
69 | * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations. | |
70 | * | |
71 | * @parameter expression="${useEditMode}" default-value="false" | |
72 | */ | |
73 | private boolean useEditMode; | |
74 | ||
75 | /** | |
76 | * Whether to update dependencies version to the next development version. | |
77 | * | |
78 | * @parameter expression="${updateDependencies}" default-value="true" | |
79 | */ | |
80 | private boolean updateDependencies; | |
81 | ||
82 | /** | |
83 | * Whether to automatically assign submodules the parent version. If set to false, | |
84 | * the user will be prompted for the version of each submodules. | |
85 | * | |
86 | * @parameter expression="${autoVersionSubmodules}" default-value="false" | |
87 | */ | |
88 | private boolean autoVersionSubmodules; | |
89 | ||
90 | /** | |
91 | * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout. | |
92 | * Running <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to | |
93 | * poms and scm operations (only listed on the console) are working as expected. | |
94 | * Modified POMs are written alongside the originals without modifying them. | |
95 | * | |
96 | * @parameter expression="${dryRun}" default-value="false" | |
97 | */ | |
98 | private boolean dryRun; | |
99 | ||
100 | /** | |
101 | * Whether to add a schema to the POM if it was previously missing on release. | |
102 | * | |
103 | * @parameter expression="${addSchema}" default-value="true" | |
104 | */ | |
105 | private boolean addSchema; | |
106 | ||
107 | /** | |
108 | * {@inheritDoc} | |
109 | */ | |
110 | public void execute() | |
111 | throws MojoExecutionException, MojoFailureException | |
112 | { | |
113 | 0 | super.execute(); |
114 | ||
115 | 0 | if ( StringUtils.isEmpty( branchName ) ) |
116 | { | |
117 | 0 | throw new MojoExecutionException( "The branch name is required." ); |
118 | } | |
119 | ||
120 | 0 | ReleaseDescriptor config = createReleaseDescriptor(); |
121 | 0 | config.setAddSchema( addSchema ); |
122 | 0 | config.setScmUseEditMode( useEditMode ); |
123 | 0 | config.setUpdateDependencies( updateDependencies ); |
124 | 0 | config.setAutoVersionSubmodules( autoVersionSubmodules ); |
125 | 0 | config.setScmReleaseLabel( branchName ); |
126 | 0 | config.setBranchCreation( true ); |
127 | 0 | config.setUpdateBranchVersions( updateBranchVersions ); |
128 | 0 | config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions ); |
129 | 0 | config.setUpdateVersionsToSnapshot( updateVersionsToSnapshot ); |
130 | ||
131 | try | |
132 | { | |
133 | 0 | releaseManager.branch( config, getReleaseEnvironment(), reactorProjects, dryRun ); |
134 | } | |
135 | 0 | catch ( ReleaseExecutionException e ) |
136 | { | |
137 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
138 | } | |
139 | 0 | catch ( ReleaseFailureException e ) |
140 | { | |
141 | 0 | e.printStackTrace(); |
142 | 0 | throw new MojoFailureException( e.getMessage() ); |
143 | 0 | } |
144 | 0 | } |
145 | } |