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.io.File;
22 import java.util.Map;
23
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException;
26 import org.apache.maven.plugins.annotations.Component;
27 import org.apache.maven.plugins.annotations.Mojo;
28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.scm.manager.ScmManager;
30 import org.apache.maven.shared.release.DefaultReleaseManagerListener;
31 import org.apache.maven.shared.release.ReleaseExecutionException;
32 import org.apache.maven.shared.release.ReleaseFailureException;
33 import org.apache.maven.shared.release.ReleasePerformRequest;
34 import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
35 import org.codehaus.plexus.util.StringUtils;
36
37
38
39
40
41
42
43
44
45
46 @Mojo(name = "perform", aggregator = true, requiresProject = false)
47 public class PerformReleaseMojo extends AbstractReleaseMojo {
48
49
50
51
52 @Parameter(property = "goals")
53 String goals;
54
55
56
57
58
59
60 @Parameter(property = "releaseProfiles")
61 private String releaseProfiles;
62
63
64
65
66 @Parameter(defaultValue = "${project.build.directory}/checkout", property = "workingDirectory", required = true)
67 private File workingDirectory;
68
69
70
71
72
73 @Parameter(property = "connectionUrl")
74 private String connectionUrl;
75
76
77
78
79
80
81
82
83
84
85 @Parameter(defaultValue = "false", property = "localCheckout")
86 private boolean localCheckout;
87
88
89
90
91 @Parameter(property = "username")
92 private String username;
93
94
95
96
97 @Parameter(property = "password")
98 private String password;
99
100
101
102
103 @Parameter(defaultValue = "true", property = "scmShallowClone")
104 private boolean scmShallowClone = true;
105
106
107
108
109
110
111
112
113
114 @Parameter(defaultValue = "false", property = "useReleaseProfile")
115 @Deprecated
116 private boolean useReleaseProfile;
117
118
119
120
121
122 @Parameter(defaultValue = "false", property = "dryRun")
123 private boolean dryRun;
124
125
126
127
128
129
130
131
132
133 @Parameter
134 private Map<String, String> providerImplementations;
135
136
137
138
139 @Component
140 private ScmManager scmManager;
141
142 @Override
143 protected String getAdditionalProfiles() {
144 return releaseProfiles;
145 }
146
147 @Override
148 public void execute() throws MojoExecutionException, MojoFailureException {
149 if (providerImplementations != null) {
150 for (Map.Entry<String, String> providerEntry : providerImplementations.entrySet()) {
151 getLog().info("Change the default '" + providerEntry.getKey() + "' provider implementation to '"
152 + providerEntry.getValue() + "'.");
153 scmManager.setScmProviderImplementation(providerEntry.getKey(), providerEntry.getValue());
154 }
155 }
156
157
158
159 if (goals != null) {
160 goals = StringUtils.join(StringUtils.split(goals), " ");
161 }
162
163 try {
164 setDeploymentRepository();
165
166 ReleaseDescriptorBuilder releaseDescriptor = createReleaseDescriptor();
167 if (connectionUrl != null) {
168 releaseDescriptor.setScmSourceUrl(connectionUrl);
169 }
170
171 if (username != null) {
172 releaseDescriptor.setScmUsername(username);
173 }
174
175 if (password != null) {
176 releaseDescriptor.setScmPassword(password);
177 }
178
179 releaseDescriptor.setScmShallowClone(scmShallowClone);
180
181 releaseDescriptor.setLocalCheckout(localCheckout);
182
183 releaseDescriptor.setCheckoutDirectory(workingDirectory.getAbsolutePath());
184 releaseDescriptor.setUseReleaseProfile(useReleaseProfile);
185
186 createGoals();
187 releaseDescriptor.setPerformGoals(goals);
188
189 ReleasePerformRequest performRequest = new ReleasePerformRequest();
190 performRequest.setReleaseDescriptorBuilder(releaseDescriptor);
191 performRequest.setReleaseEnvironment(getReleaseEnvironment());
192 performRequest.setReactorProjects(getReactorProjects());
193 performRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog(), dryRun));
194 performRequest.setDryRun(dryRun);
195
196 releaseManager.perform(performRequest);
197 } catch (ReleaseExecutionException e) {
198 throw new MojoExecutionException(e.getMessage(), e);
199 } catch (ReleaseFailureException e) {
200 throw new MojoFailureException(e.getMessage(), e);
201 }
202 }
203
204
205 void setDeploymentRepository() {}
206
207
208 void createGoals() {
209 if (goals == null) {
210
211 goals = "deploy";
212 if (project.getDistributionManagement() != null
213 && project.getDistributionManagement().getSite() != null) {
214 goals += " site-deploy";
215 }
216 }
217 }
218 }