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 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.Parameter;
28 import org.apache.maven.scm.manager.ScmManager;
29 import org.apache.maven.shared.release.config.ReleaseDescriptor;
30
31 /**
32 * Abstract Mojo containing SCM parameters
33 *
34 * @author Robert Scholte
35 */
36 // Extra layer since 2.4. Don't use @since doclet, these would be inherited by the subclasses
37 public abstract class AbstractScmReleaseMojo
38 extends AbstractReleaseMojo
39 {
40 /**
41 * The SCM username to use.
42 */
43 @Parameter( property = "username" )
44 private String username;
45
46 /**
47 * The SCM password to use.
48 */
49 @Parameter( property = "password" )
50 private String password;
51
52 /**
53 * The SCM tag to use.
54 */
55 @Parameter( alias = "releaseLabel", property = "tag" )
56 private String tag;
57
58 /**
59 * Format to use when generating the tag name if none is specified. Property interpolation is performed on the
60 * tag, but in order to ensure that the interpolation occurs during release, you must use <code>@{...}</code>
61 * to reference the properties rather than <code>${...}</code>. The following properties are available:
62 * <ul>
63 * <li><code>groupId</code> or <code>project.groupId</code> - The groupId of the root project.
64 * <li><code>artifactId</code> or <code>project.artifactId</code> - The artifactId of the root project.
65 * <li><code>version</code> or <code>project.version</code> - The release version of the root project.
66 * </ul>
67 *
68 * @since 2.2.0
69 */
70 @Parameter( defaultValue = "@{project.artifactId}-@{project.version}", property = "tagNameFormat" )
71 private String tagNameFormat;
72
73 /**
74 * The tag base directory in SVN, you must define it if you don't use the standard svn layout (trunk/tags/branches).
75 * For example, <code>http://svn.apache.org/repos/asf/maven/plugins/tags</code>. The URL is an SVN URL and does not
76 * include the SCM provider and protocol.
77 */
78 @Parameter( property = "tagBase" )
79 private String tagBase;
80
81 /**
82 * The message prefix to use for all SCM changes.
83 *
84 * @since 2.0-beta-5
85 */
86 @Parameter( defaultValue = "[maven-release-plugin] ", property = "scmCommentPrefix" )
87 private String scmCommentPrefix;
88
89 /**
90 * Implemented with git will or not push changes to the upstream repository.
91 * <code>true</code> by default to preserve backward compatibility.
92 * @since 2.1
93 */
94 @Parameter( defaultValue = "true", property = "pushChanges" )
95 private boolean pushChanges = true;
96
97 /**
98 * Add a new or overwrite the default implementation per provider.
99 * The key is the scm prefix and the value is the role hint of the {@link org.apache.maven.scm.provider.ScmProvider}.
100 *
101 * @since 2.0-beta-6
102 * @see ScmManager#setScmProviderImplementation(String, String)
103 */
104 @Parameter
105 private Map<String, String> providerImplementations;
106
107 /**
108 * The SCM manager.
109 */
110 @Component
111 private ScmManager scmManager;
112
113 /**
114 * {@inheritDoc}
115 */
116 public void execute()
117 throws MojoExecutionException, MojoFailureException
118 {
119 if ( providerImplementations != null )
120 {
121 for ( Map.Entry<String, String> providerEntry : providerImplementations.entrySet() )
122 {
123 getLog().info( "Change the default '" + providerEntry.getKey() + "' provider implementation to '"
124 + providerEntry.getValue() + "'." );
125 scmManager.setScmProviderImplementation( providerEntry.getKey(), providerEntry.getValue() );
126 }
127 }
128 }
129
130 @Override
131 protected ReleaseDescriptor createReleaseDescriptor()
132 {
133 ReleaseDescriptor descriptor = super.createReleaseDescriptor();
134
135 descriptor.setScmPassword( password );
136 descriptor.setScmReleaseLabel( tag );
137 descriptor.setScmTagNameFormat( tagNameFormat );
138 descriptor.setScmTagBase( tagBase );
139 descriptor.setScmUsername( username );
140 descriptor.setScmCommentPrefix( scmCommentPrefix );
141
142 descriptor.setPushChanges( pushChanges );
143
144 return descriptor;
145 }
146 }