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.execution.MavenSession;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29 import org.apache.maven.shared.release.ReleaseExecutionException;
30 import org.apache.maven.shared.release.ReleaseFailureException;
31 import org.apache.maven.shared.release.config.ReleaseDescriptor;
32 import org.apache.maven.shared.release.config.ReleaseUtils;
33
34 /**
35 * Update the POM versions for a project.
36 * For more info see <a href="/plugins/maven-release-plugin/examples/update-versions.html">this example</a>.
37 *
38 * @author Paul Gier
39 * @version $Id: UpdateVersionsMojo.html 816525 2012-05-08 11:35:10Z hboutemy $
40 * @aggregator
41 * @goal update-versions
42 * @since 2.0
43 */
44 public class UpdateVersionsMojo
45 extends AbstractReleaseMojo
46 {
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 * @parameter expression="${autoVersionSubmodules}" default-value="false"
53 * @since 2.0
54 */
55 private boolean autoVersionSubmodules;
56
57 /**
58 * Whether to add a schema to the POM if it was previously missing on release.
59 *
60 * @parameter expression="${addSchema}" default-value="true"
61 * @since 2.0
62 */
63 private boolean addSchema;
64
65 /**
66 * Default version to use for new local working copy.
67 *
68 * @parameter expression="${developmentVersion}"
69 * @since 2.0
70 */
71 private String developmentVersion;
72
73 /**
74 * @parameter expression="${session}"
75 * @readonly
76 * @required
77 * @since 2.0
78 */
79 protected MavenSession session;
80
81 /**
82 * {@inheritDoc}
83 */
84 public void execute()
85 throws MojoExecutionException, MojoFailureException
86 {
87 super.execute();
88
89 ReleaseDescriptor config = createReleaseDescriptor();
90 config.setAddSchema( addSchema );
91 config.setAutoVersionSubmodules( autoVersionSubmodules );
92 config.setDefaultDevelopmentVersion( developmentVersion );
93
94 Map originalScmInfo = new HashMap();
95 originalScmInfo.put( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ), project.getScm() );
96 config.setOriginalScmInfo( originalScmInfo );
97
98 // Create a config containing values from the session properties (ie command line properties with cli).
99 ReleaseDescriptor sysPropertiesConfig
100 = ReleaseUtils.copyPropertiesToReleaseDescriptor( session.getExecutionProperties() );
101 mergeCommandLineConfig( config, sysPropertiesConfig );
102
103 try
104 {
105 releaseManager.updateVersions( config, getReleaseEnvironment(), reactorProjects );
106 }
107 catch ( ReleaseExecutionException e )
108 {
109 throw new MojoExecutionException( e.getMessage(), e );
110 }
111 catch ( ReleaseFailureException e )
112 {
113 throw new MojoFailureException( e.getMessage(), e );
114 }
115 }
116
117 /**
118 * This method takes some of the release configuration picked up from the command line system properties and copies
119 * it into the release config object.
120 *
121 * @param config The release configuration to merge the system properties into, must not be <code>null</code>.
122 * @param sysPropertiesConfig The configuration from the system properties to merge in, must not be
123 * <code>null</code>.
124 */
125 private void mergeCommandLineConfig( ReleaseDescriptor config, ReleaseDescriptor sysPropertiesConfig )
126 {
127 // If the user specifies versions, these should override the existing versions
128 if ( sysPropertiesConfig.getReleaseVersions() != null )
129 {
130 config.getReleaseVersions().putAll( sysPropertiesConfig.getReleaseVersions() );
131 }
132 if ( sysPropertiesConfig.getDevelopmentVersions() != null )
133 {
134 config.getDevelopmentVersions().putAll( sysPropertiesConfig.getDevelopmentVersions() );
135 }
136 }
137
138 }