View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.release;
20  
21  import javax.inject.Inject;
22  
23  import org.apache.maven.artifact.ArtifactUtils;
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.plugin.MojoFailureException;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.Parameter;
28  import org.apache.maven.shared.release.DefaultReleaseManagerListener;
29  import org.apache.maven.shared.release.ReleaseExecutionException;
30  import org.apache.maven.shared.release.ReleaseFailureException;
31  import org.apache.maven.shared.release.ReleaseManager;
32  import org.apache.maven.shared.release.ReleaseUpdateVersionsRequest;
33  import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
34  import org.codehaus.plexus.configuration.PlexusConfiguration;
35  
36  /**
37   * Update the POM versions for a project. This performs the normal version updates of the <code>release:prepare</code>
38   * goal without making other modifications to the SCM such as tagging. For more info see <a
39   * href="https://maven.apache.org/plugins/maven-release-plugin/usage/update-versions.html"
40   * >https://maven.apache.org/plugins/maven-release-plugin/usage/update-versions.html</a>.
41   *
42   * @author Paul Gier
43   * @since 2.0
44   */
45  @Mojo(name = "update-versions", aggregator = true)
46  public class UpdateVersionsMojo extends AbstractReleaseMojo {
47  
48      /**
49       * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the
50       * version of each submodules.
51       *
52       * @since 2.0
53       */
54      @Parameter(defaultValue = "false", property = "autoVersionSubmodules")
55      private boolean autoVersionSubmodules;
56  
57      /**
58       * Whether to add a schema to the POM if it was previously missing on release.
59       *
60       * @since 2.0
61       */
62      @Parameter(defaultValue = "true", property = "addSchema")
63      private boolean addSchema;
64  
65      /**
66       * Default version to use for new local working copy.
67       *
68       * @since 2.0
69       */
70      @Parameter(property = "developmentVersion")
71      private String developmentVersion;
72  
73      /**
74       * Whether to update dependencies version to the next development version.
75       *
76       * @since 2.5.2
77       */
78      @Parameter(defaultValue = "true", property = "updateDependencies")
79      private boolean updateDependencies;
80  
81      /**
82       * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations.
83       *
84       * @since 2.5.2
85       */
86      @Parameter(defaultValue = "false", property = "useEditMode")
87      private boolean useEditMode;
88  
89      /**
90       * The role-hint for the VersionPolicy implementation used to calculate the project versions.
91       *
92       * @since 3.0.0-M5
93       */
94      @Parameter(defaultValue = "default", property = "projectVersionPolicyId")
95      private String projectVersionPolicyId;
96  
97      /**
98       * Optional config for the VersionPolicy implementation used to calculate the project versions.
99       *
100      * @since 3.0.0
101      */
102     @Parameter(property = "projectVersionPolicyConfig")
103     private PlexusConfiguration projectVersionPolicyConfig;
104 
105     @Inject
106     public UpdateVersionsMojo(ReleaseManager releaseManager) {
107         super(releaseManager);
108     }
109 
110     @Override
111     public void execute() throws MojoExecutionException, MojoFailureException {
112         final ReleaseDescriptorBuilder config = createReleaseDescriptor();
113         config.setAddSchema(addSchema);
114         config.setAutoVersionSubmodules(autoVersionSubmodules);
115         config.setDefaultDevelopmentVersion(developmentVersion);
116         config.setScmUseEditMode(useEditMode);
117         config.setUpdateDependencies(updateDependencies);
118         config.setProjectVersionPolicyId(projectVersionPolicyId);
119         if (projectVersionPolicyConfig != null) {
120             config.setProjectVersionPolicyConfig(projectVersionPolicyConfig.toString());
121         }
122         config.addOriginalScmInfo(
123                 ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()), project.getScm());
124 
125         try {
126             ReleaseUpdateVersionsRequest updateVersionsRequest = new ReleaseUpdateVersionsRequest();
127             updateVersionsRequest.setReleaseDescriptorBuilder(config);
128             updateVersionsRequest.setReleaseEnvironment(getReleaseEnvironment());
129             updateVersionsRequest.setReactorProjects(getReactorProjects());
130             updateVersionsRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog()));
131             updateVersionsRequest.setUserProperties(session.getUserProperties());
132 
133             releaseManager.updateVersions(updateVersionsRequest);
134         } catch (ReleaseExecutionException e) {
135             throw new MojoExecutionException(e.getMessage(), e);
136         } catch (ReleaseFailureException e) {
137             throw new MojoFailureException(e.getMessage(), e);
138         }
139     }
140 }