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 org.apache.maven.artifact.ArtifactUtils;
22  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugin.MojoFailureException;
24  import org.apache.maven.plugins.annotations.Mojo;
25  import org.apache.maven.plugins.annotations.Parameter;
26  import org.apache.maven.shared.release.DefaultReleaseManagerListener;
27  import org.apache.maven.shared.release.ReleaseExecutionException;
28  import org.apache.maven.shared.release.ReleaseFailureException;
29  import org.apache.maven.shared.release.ReleaseUpdateVersionsRequest;
30  import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
31  import org.codehaus.plexus.configuration.PlexusConfiguration;
32  
33  /**
34   * Update the POM versions for a project. This performs the normal version updates of the <code>release:prepare</code>
35   * goal without making other modifications to the SCM such as tagging. For more info see <a
36   * href="https://maven.apache.org/plugins/maven-release-plugin/usage/update-versions.html"
37   * >https://maven.apache.org/plugins/maven-release-plugin/usage/update-versions.html</a>.
38   *
39   * @author Paul Gier
40   * @since 2.0
41   */
42  @Mojo(name = "update-versions", aggregator = true)
43  public class UpdateVersionsMojo extends AbstractReleaseMojo {
44  
45      /**
46       * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the
47       * version of each submodules.
48       *
49       * @since 2.0
50       */
51      @Parameter(defaultValue = "false", property = "autoVersionSubmodules")
52      private boolean autoVersionSubmodules;
53  
54      /**
55       * Whether to add a schema to the POM if it was previously missing on release.
56       *
57       * @since 2.0
58       */
59      @Parameter(defaultValue = "true", property = "addSchema")
60      private boolean addSchema;
61  
62      /**
63       * Default version to use for new local working copy.
64       *
65       * @since 2.0
66       */
67      @Parameter(property = "developmentVersion")
68      private String developmentVersion;
69  
70      /**
71       * Whether to update dependencies version to the next development version.
72       *
73       * @since 2.5.2
74       */
75      @Parameter(defaultValue = "true", property = "updateDependencies")
76      private boolean updateDependencies;
77  
78      /**
79       * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations.
80       *
81       * @since 2.5.2
82       */
83      @Parameter(defaultValue = "false", property = "useEditMode")
84      private boolean useEditMode;
85  
86      /**
87       * The role-hint for the VersionPolicy implementation used to calculate the project versions.
88       *
89       * @since 3.0.0-M5
90       */
91      @Parameter(defaultValue = "default", property = "projectVersionPolicyId")
92      private String projectVersionPolicyId;
93  
94      /**
95       * Optional config for the VersionPolicy implementation used to calculate the project versions.
96       *
97       * @since 3.0.0
98       */
99      @Parameter(property = "projectVersionPolicyConfig")
100     private PlexusConfiguration projectVersionPolicyConfig;
101 
102     @Override
103     public void execute() throws MojoExecutionException, MojoFailureException {
104         final ReleaseDescriptorBuilder config = createReleaseDescriptor();
105         config.setAddSchema(addSchema);
106         config.setAutoVersionSubmodules(autoVersionSubmodules);
107         config.setDefaultDevelopmentVersion(developmentVersion);
108         config.setScmUseEditMode(useEditMode);
109         config.setUpdateDependencies(updateDependencies);
110         config.setProjectVersionPolicyId(projectVersionPolicyId);
111         if (projectVersionPolicyConfig != null) {
112             config.setProjectVersionPolicyConfig(projectVersionPolicyConfig.toString());
113         }
114         config.addOriginalScmInfo(
115                 ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()), project.getScm());
116 
117         try {
118             ReleaseUpdateVersionsRequest updateVersionsRequest = new ReleaseUpdateVersionsRequest();
119             updateVersionsRequest.setReleaseDescriptorBuilder(config);
120             updateVersionsRequest.setReleaseEnvironment(getReleaseEnvironment());
121             updateVersionsRequest.setReactorProjects(getReactorProjects());
122             updateVersionsRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog()));
123             updateVersionsRequest.setUserProperties(session.getUserProperties());
124 
125             releaseManager.updateVersions(updateVersionsRequest);
126         } catch (ReleaseExecutionException e) {
127             throw new MojoExecutionException(e.getMessage(), e);
128         } catch (ReleaseFailureException e) {
129             throw new MojoFailureException(e.getMessage(), e);
130         }
131     }
132 }