1818 */
1919package org .apache .maven .plugins .release ;
2020
21- import javax .inject .Inject ;
22-
21+ import java .io .File ;
2322import java .util .Map ;
2423
2524import org .apache .maven .artifact .ArtifactUtils ;
3332import org .apache .maven .shared .release .config .ReleaseDescriptorBuilder ;
3433
3534/**
36- * Abstract Mojo containing SCM parameters
37- *
38- * @author Robert Scholte
35+ * Abstract Mojo containing SCM parameters for read operations.
3936 */
40- // Extra layer since 2.4. Don't use @since doclet, these would be inherited by the subclasses
41- public abstract class AbstractScmReleaseMojo extends AbstractReleaseMojo {
42- /**
43- * The SCM username to use.
44- */
45- @ Parameter (property = "username" )
46- private String username ;
47-
48- /**
49- * The SCM password to use.
50- */
51- @ Parameter (property = "password" )
52- private String password ;
53-
54- /**
55- * The SCM tag to use.
56- */
57- @ Parameter (alias = "releaseLabel" , property = "tag" )
58- private String tag ;
59-
60- /**
61- * Format to use when generating the tag name if none is specified. Property interpolation is performed on the
62- * tag, but in order to ensure that the interpolation occurs during release, you must use <code>@{...}</code>
63- * to reference the properties rather than <code>${...}</code>. The following properties are available:
64- * <ul>
65- * <li><code>groupId</code> or <code>project.groupId</code> - The groupId of the root project.
66- * <li><code>artifactId</code> or <code>project.artifactId</code> - The artifactId of the root project.
67- * <li><code>version</code> or <code>project.version</code> - The release version of the root project.
68- * </ul>
69- *
70- * @since 2.2.0
71- */
72- @ Parameter (defaultValue = "@{project.artifactId}-@{project.version}" , property = "tagNameFormat" )
73- private String tagNameFormat ;
74-
75- /**
76- * The tag base directory in SVN, you must define it if you don't use the standard svn layout (trunk/tags/branches).
77- * For example, <code>http://svn.apache.org/repos/asf/maven/plugins/tags</code>. The URL is an SVN URL and does not
78- * include the SCM provider and protocol.
79- */
80- @ Parameter (property = "tagBase" )
81- private String tagBase ;
37+ public abstract class AbstractScmReadReleaseMojo extends AbstractReleaseMojo {
8238
8339 /**
84- * The message prefix to use for all SCM changes.
85- *
86- * @since 2.0-beta-5
40+ * The server id of the server which provides the credentials for the SCM in the <a href="https://maven.apache.org/settings.html">settings.xml</a> file.
41+ * If not set the default lookup uses the SCM URL to construct the server id like this:
42+ * {@code server-id=scm-host[":"scm-port]}.
43+ * <p>
44+ * Currently the POM does not allow to specify a server id for the SCM section.
45+ * <p>
46+ * Explicit authentication information provided via {@link #username}, {@link #password} or {@link #privateKey} will take precedence.
47+ * @since 3.2.0
8748 */
88- @ Parameter (defaultValue = "[maven-release-plugin] " , property = "scmCommentPrefix " )
89- private String scmCommentPrefix ;
49+ @ Parameter (property = "project.scm.id " , defaultValue = "${project.scm.id} " )
50+ private String serverId ;
9051
9152 /**
92- * When cloning a repository if it should be a shallow clone or a full clone .
53+ * The username to use for authentication with the SCM .
9354 */
94- @ Parameter (defaultValue = "true" , property = "scmShallowClone " )
95- private boolean scmShallowClone = true ;
55+ @ Parameter (property = "username " )
56+ private String username ;
9657
9758 /**
98- * Implemented with git will or not push changes to the upstream repository.
99- * <code>true</code> by default to preserve backward compatibility.
100- * @since 2.1
59+ * The password to use for authentication with the SCM.
10160 */
102- @ Parameter (defaultValue = "true" , property = "pushChanges " )
103- private boolean pushChanges = true ;
61+ @ Parameter (property = "password " )
62+ private String password ;
10463
10564 /**
106- * A workItem for SCMs like RTC, TFS etc, that may require additional
107- * information to perform a pushChange operation.
108- *
109- * @since 3.0.0-M5
65+ * The path to the SSH private key to use for authentication with the SCM.
66+ * @since 3.2.0
11067 */
111- @ Parameter (property = "workItem " )
112- private String workItem ;
68+ @ Parameter (property = "privateKey " )
69+ private File privateKey ;
11370
11471 /**
11572 * Add a new or overwrite the default implementation per provider.
@@ -122,13 +79,18 @@ public abstract class AbstractScmReleaseMojo extends AbstractReleaseMojo {
12279 @ Parameter
12380 private Map <String , String > providerImplementations ;
12481
82+ /**
83+ * When cloning a repository if it should be a shallow clone or a full clone.
84+ */
85+ @ Parameter (defaultValue = "true" , property = "scmShallowClone" )
86+ private boolean scmShallowClone = true ;
87+
12588 /**
12689 * The SCM manager.
12790 */
12891 private final ScmManager scmManager ;
12992
130- @ Inject
131- protected AbstractScmReleaseMojo (ReleaseManager releaseManager , ScmManager scmManager ) {
93+ protected AbstractScmReadReleaseMojo (ReleaseManager releaseManager , ScmManager scmManager ) {
13294 super (releaseManager );
13395 this .scmManager = scmManager ;
13496 }
@@ -148,17 +110,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
148110 protected ReleaseDescriptorBuilder createReleaseDescriptor () {
149111 ReleaseDescriptorBuilder descriptor = super .createReleaseDescriptor ();
150112
113+ if (privateKey != null ) {
114+ descriptor .setScmPrivateKey (privateKey .getAbsolutePath ());
115+ }
151116 descriptor .setScmPassword (password );
152- descriptor .setScmReleaseLabel (tag );
153- descriptor .setScmTagNameFormat (tagNameFormat );
154- descriptor .setScmTagBase (tagBase );
155117 descriptor .setScmUsername (username );
156- descriptor .setScmCommentPrefix (scmCommentPrefix );
157118 descriptor .setScmShallowClone (scmShallowClone );
158119
159- descriptor .setPushChanges (pushChanges );
160- descriptor .setWorkItem (workItem );
161-
162120 if (project .getScm () != null ) {
163121 if (project .getScm ().getDeveloperConnection () != null ) {
164122 descriptor .setScmSourceUrl (project .getScm ().getDeveloperConnection ());
@@ -167,11 +125,11 @@ protected ReleaseDescriptorBuilder createReleaseDescriptor() {
167125 }
168126 }
169127
170- // As long as Scm.getId() does not exist, read it as a property
171- descriptor .setScmId (project .getProperties ().getProperty ("project.scm.id" ));
128+ descriptor .setScmId (serverId );
172129
173130 for (MavenProject reactorProject : session .getProjects ()) {
174- if (reactorProject .getScm () != null ) {
131+ if (reactorProject .getOriginalModel () != null
132+ && reactorProject .getOriginalModel ().getScm () != null ) {
175133 String projectId =
176134 ArtifactUtils .versionlessKey (reactorProject .getGroupId (), reactorProject .getArtifactId ());
177135
0 commit comments