View Javadoc
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
100      * {@link org.apache.maven.scm.provider.ScmProvider}.
101      *
102      * @since 2.0-beta-6
103      * @see ScmManager#setScmProviderImplementation(String, String)
104      */
105     @Parameter
106     private Map<String, String> providerImplementations;
107     
108     /**
109      * The SCM manager.
110      */
111     @Component
112     private ScmManager scmManager;
113 
114     /**
115      * {@inheritDoc}
116      */
117     public void execute()
118         throws MojoExecutionException, MojoFailureException
119     {
120         if ( providerImplementations != null )
121         {
122             for ( Map.Entry<String, String> providerEntry : providerImplementations.entrySet() )
123             {
124                 getLog().info( "Change the default '" + providerEntry.getKey() + "' provider implementation to '"
125                     + providerEntry.getValue() + "'." );
126                 scmManager.setScmProviderImplementation( providerEntry.getKey(), providerEntry.getValue() );
127             }
128         }
129     }
130     
131     @Override
132     protected ReleaseDescriptor createReleaseDescriptor()
133     {
134         ReleaseDescriptor descriptor = super.createReleaseDescriptor();
135 
136         descriptor.setScmPassword( password );
137         descriptor.setScmReleaseLabel( tag );
138         descriptor.setScmTagNameFormat( tagNameFormat );
139         descriptor.setScmTagBase( tagBase );
140         descriptor.setScmUsername( username );
141         descriptor.setScmCommentPrefix( scmCommentPrefix );
142 
143         descriptor.setPushChanges( pushChanges );
144 
145         return descriptor;
146     }
147 }