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.HashMap;
23  import java.util.Map;
24  
25  import org.apache.maven.artifact.ArtifactUtils;
26  import org.apache.maven.model.Scm;
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugin.MojoFailureException;
29  import org.apache.maven.plugins.annotations.Mojo;
30  import org.apache.maven.plugins.annotations.Parameter;
31  import org.apache.maven.shared.release.ReleaseExecutionException;
32  import org.apache.maven.shared.release.ReleaseFailureException;
33  import org.apache.maven.shared.release.config.ReleaseDescriptor;
34  import org.apache.maven.shared.release.config.ReleaseUtils;
35  
36  /**
37   * Update the POM versions for a project. This performs the normal version updates of the <tt>release:prepare</tt> goal
38   * without making other modifications to the SCM such as tagging. For more info see <a
39   * href="http://maven.apache.org/plugins/maven-release-plugin/examples/update-versions.html"
40   * >http://maven.apache.org/plugins/maven-release-plugin/examples/update-versions.html</a>.
41   * 
42   * @author Paul Gier
43   * @version $Id: UpdateVersionsMojo.java 1420401 2012-12-11 20:58:35Z rfscholte $
44   * @since 2.0
45   */
46  @Mojo( name = "update-versions", aggregator = true )
47  public class UpdateVersionsMojo
48      extends AbstractReleaseMojo
49  {
50  
51      /**
52       * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the
53       * version of each submodules.
54       * 
55       * @since 2.0
56       */
57      @Parameter( defaultValue = "false", property = "autoVersionSubmodules" )
58      private boolean autoVersionSubmodules;
59  
60      /**
61       * Whether to add a schema to the POM if it was previously missing on release.
62       * 
63       * @since 2.0
64       */
65      @Parameter( defaultValue = "true", property = "addSchema" )
66      private boolean addSchema;
67  
68      /**
69       * Default version to use for new local working copy.
70       * 
71       * @since 2.0
72       */
73      @Parameter( property = "developmentVersion" )
74      private String developmentVersion;
75  
76      /**
77       * {@inheritDoc}
78       */
79      public void execute()
80          throws MojoExecutionException, MojoFailureException
81      {
82          ReleaseDescriptor config = createReleaseDescriptor();
83          config.setAddSchema( addSchema );
84          config.setAutoVersionSubmodules( autoVersionSubmodules );
85          config.setDefaultDevelopmentVersion( developmentVersion );
86  
87          Map<String, Scm> originalScmInfo = new HashMap<String, Scm>();
88          originalScmInfo.put( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ),
89                               project.getScm() );
90          config.setOriginalScmInfo( originalScmInfo );
91  
92          // Create a config containing values from the session properties (ie command line properties with cli).
93          ReleaseDescriptor sysPropertiesConfig =
94              ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() );
95          mergeCommandLineConfig( config, sysPropertiesConfig );
96  
97          try
98          {
99              releaseManager.updateVersions( config, getReleaseEnvironment(), getReactorProjects() );
100         }
101         catch ( ReleaseExecutionException e )
102         {
103             throw new MojoExecutionException( e.getMessage(), e );
104         }
105         catch ( ReleaseFailureException e )
106         {
107             throw new MojoFailureException( e.getMessage(), e );
108         }
109     }
110 }