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.Map;
22
23 import org.apache.maven.artifact.ArtifactUtils;
24 import org.apache.maven.model.Scm;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException;
27 import org.apache.maven.plugins.annotations.Component;
28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.project.MavenProject;
30 import org.apache.maven.scm.manager.ScmManager;
31 import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
32
33
34
35
36
37
38
39 public abstract class AbstractScmReleaseMojo extends AbstractReleaseMojo {
40
41
42
43 @Parameter(property = "username")
44 private String username;
45
46
47
48
49 @Parameter(property = "password")
50 private String password;
51
52
53
54
55 @Parameter(alias = "releaseLabel", property = "tag")
56 private String tag;
57
58
59
60
61
62
63
64
65
66
67
68
69
70 @Parameter(defaultValue = "@{project.artifactId}-@{project.version}", property = "tagNameFormat")
71 private String tagNameFormat;
72
73
74
75
76
77
78 @Parameter(property = "tagBase")
79 private String tagBase;
80
81
82
83
84
85
86 @Parameter(defaultValue = "[maven-release-plugin] ", property = "scmCommentPrefix")
87 private String scmCommentPrefix;
88
89
90
91
92 @Parameter(defaultValue = "true", property = "scmShallowClone")
93 private boolean scmShallowClone = true;
94
95
96
97
98
99
100 @Parameter(defaultValue = "true", property = "pushChanges")
101 private boolean pushChanges = true;
102
103
104
105
106
107
108
109 @Parameter(property = "workItem")
110 private String workItem;
111
112
113
114
115
116
117
118
119
120 @Parameter
121 private Map<String, String> providerImplementations;
122
123
124
125
126 @Component
127 private ScmManager scmManager;
128
129 @Override
130 public void execute() throws MojoExecutionException, MojoFailureException {
131 if (providerImplementations != null) {
132 for (Map.Entry<String, String> providerEntry : providerImplementations.entrySet()) {
133 getLog().info("Change the default '" + providerEntry.getKey() + "' provider implementation to '"
134 + providerEntry.getValue() + "'.");
135 scmManager.setScmProviderImplementation(providerEntry.getKey(), providerEntry.getValue());
136 }
137 }
138 }
139
140 @Override
141 protected ReleaseDescriptorBuilder createReleaseDescriptor() {
142 ReleaseDescriptorBuilder descriptor = super.createReleaseDescriptor();
143
144 descriptor.setScmPassword(password);
145 descriptor.setScmReleaseLabel(tag);
146 descriptor.setScmTagNameFormat(tagNameFormat);
147 descriptor.setScmTagBase(tagBase);
148 descriptor.setScmUsername(username);
149 descriptor.setScmCommentPrefix(scmCommentPrefix);
150 descriptor.setScmShallowClone(scmShallowClone);
151
152 descriptor.setPushChanges(pushChanges);
153 descriptor.setWorkItem(workItem);
154
155 if (project.getScm() != null) {
156 if (project.getScm().getDeveloperConnection() != null) {
157 descriptor.setScmSourceUrl(project.getScm().getDeveloperConnection());
158 } else if (project.getScm().getConnection() != null) {
159 descriptor.setScmSourceUrl(project.getScm().getConnection());
160 }
161 }
162
163
164 descriptor.setScmId(project.getProperties().getProperty("project.scm.id"));
165
166 for (MavenProject reactorProject : session.getProjects()) {
167 if (reactorProject.getScm() != null) {
168 String projectId =
169 ArtifactUtils.versionlessKey(reactorProject.getGroupId(), reactorProject.getArtifactId());
170
171 descriptor.addOriginalScmInfo(projectId, buildScm(reactorProject));
172 }
173 }
174
175 return descriptor;
176 }
177
178
179
180
181
182
183
184 protected Scm buildScm(MavenProject project) {
185 Scm scm;
186 if (project.getOriginalModel().getScm() == null) {
187 scm = null;
188 } else {
189 scm = new Scm();
190 scm.setConnection(project.getOriginalModel().getScm().getConnection());
191 scm.setDeveloperConnection(project.getOriginalModel().getScm().getDeveloperConnection());
192 scm.setTag(project.getOriginalModel().getScm().getTag());
193 scm.setUrl(project.getOriginalModel().getScm().getUrl());
194 }
195 return scm;
196 }
197 }