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.Arrays; 23 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.plugins.annotations.ResolutionScope; 29 import org.apache.maven.shared.release.DefaultReleaseManagerListener; 30 import org.apache.maven.shared.release.ReleaseExecutionException; 31 import org.apache.maven.shared.release.ReleaseFailureException; 32 import org.apache.maven.shared.release.ReleasePrepareRequest; 33 import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder; 34 35 /** 36 * Prepare for a release in SCM. Steps through several phases to ensure the POM is ready to be released and then 37 * prepares SCM to eventually contain a tagged version of the release and a record in the local copy of the parameters 38 * used. This can be followed by a call to <code>release:perform</code>. For more info see <a 39 * href="https://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html" 40 * >https://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html</a>. 41 * 42 * @author <a href="mailto:jdcasey@apache.org">John Casey</a> 43 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 44 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 45 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 46 */ 47 // TODO [!] check how this works with version ranges 48 @Mojo( name = "prepare", aggregator = true, requiresDependencyCollection = ResolutionScope.TEST ) 49 public class PrepareReleaseMojo 50 extends AbstractScmReleaseMojo 51 { 52 53 /** 54 * Resume a previous release attempt from the point where it was stopped. 55 */ 56 @Parameter( defaultValue = "true", property = "resume" ) 57 private boolean resume; 58 59 /** 60 * @deprecated Please use release:prepare-with-pom instead. 61 */ 62 @Deprecated 63 @Parameter( defaultValue = "false", property = "generateReleasePoms" ) 64 private boolean generateReleasePoms; 65 66 /** 67 * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations. 68 */ 69 @Parameter( defaultValue = "false", property = "useEditMode" ) 70 private boolean useEditMode; 71 72 /** 73 * Whether to update dependencies version to the next development version. 74 * 75 * @since 2.0-beta-5 76 */ 77 @Parameter( defaultValue = "true", property = "updateDependencies" ) 78 private boolean updateDependencies; 79 80 /** 81 * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the 82 * version of each submodules. 83 * 84 * @since 2.0-beta-5 85 */ 86 @Parameter( defaultValue = "false", property = "autoVersionSubmodules" ) 87 private boolean autoVersionSubmodules; 88 89 /** 90 * Dry run: don't checkin or tag anything in the scm repository, or modify the checkout. Running 91 * <code>mvn -DdryRun=true release:prepare</code> is useful in order to check that modifications to poms and scm 92 * operations (only listed on the console) are working as expected. Modified POMs are written alongside the 93 * originals without modifying them. 94 */ 95 @Parameter( defaultValue = "false", property = "dryRun" ) 96 private boolean dryRun; 97 98 /** 99 * Whether to add a schema to the POM if it was previously missing on release. 100 */ 101 @Parameter( defaultValue = "true", property = "addSchema" ) 102 private boolean addSchema; 103 104 /** 105 * Goals to run as part of the preparation step, after transformation but before committing. Space delimited. 106 */ 107 @Parameter( defaultValue = "clean verify", property = "preparationGoals" ) 108 private String preparationGoals; 109 110 /** 111 * Goals to run on completion of the preparation step, after transformation back to the next development version but 112 * before committing. Space delimited. 113 * 114 * @since 2.2 115 */ 116 @Parameter( defaultValue = "", property = "completionGoals" ) 117 private String completionGoals; 118 119 /** 120 * Commits to do are atomic or by project. 121 * 122 * @since 2.0-beta-5 123 */ 124 @Parameter( defaultValue = "false", property = "commitByProject" ) 125 private boolean commitByProject; 126 127 /** 128 * Whether to allow timestamped SNAPSHOT dependencies. Default is to fail when finding any SNAPSHOT. 129 * 130 * @since 2.0-beta-7 131 */ 132 @Parameter( defaultValue = "false", property = "ignoreSnapshots" ) 133 private boolean allowTimestampedSnapshots; 134 135 /** 136 * Whether to allow usage of a SNAPSHOT version of the Release Plugin. This in an internal property used to support 137 * testing of the plugin itself in batch mode. 138 * 139 * @since 2.0-beta-9 140 */ 141 @Parameter( defaultValue = "false", property = "allowReleasePluginSnapshot", readonly = true ) 142 private boolean allowReleasePluginSnapshot; 143 144 /** 145 * A list of additional exclude filters that will be skipped when checking for modifications on the working copy. Is 146 * ignored, when checkModificationExcludes is set. 147 * 148 * @since 2.1 149 */ 150 @Parameter 151 private String[] checkModificationExcludes; 152 153 /** 154 * Command-line version of checkModificationExcludes. 155 * 156 * @since 2.1 157 */ 158 @Parameter( property = "checkModificationExcludeList" ) 159 private String checkModificationExcludeList; 160 161 /** 162 * Default version to use when preparing a release or a branch. 163 * 164 * @since 2.0-beta-8 165 */ 166 @Parameter( property = "releaseVersion" ) 167 private String releaseVersion; 168 169 /** 170 * Default version to use for new local working copy. 171 * 172 * @since 2.0-beta-8 173 */ 174 @Parameter( property = "developmentVersion" ) 175 private String developmentVersion; 176 177 /** 178 * Currently only implemented with svn scm. 179 * <ul> 180 * <li>Enables a workaround to prevent issue due to svn client > 1.5.0 (fixed in 1.6.5) 181 * (https://issues.apache.org/jira/browse/SCM-406)</li> 182 * <li>You may not want to use this in conjunction with <code>suppressCommitBeforeTag</code>, such that no poms with 183 * released versions are committed to the working copy ever.</li> 184 * </ul> 185 * 186 * @since 2.0-beta-9 187 */ 188 @Parameter( defaultValue = "true", property = "remoteTagging" ) 189 private boolean remoteTagging; 190 191 /** 192 * Signs SCM tag when possible, for example when using the git-exe the '--sign' argument is used. 193 * 194 * @since 3.0.0-M5 195 */ 196 @Parameter( property = "signTag" ) 197 private boolean signTag = false; 198 199 /** 200 * Whether to bump the working copy versions to <code>developmentVersion</code>. 201 * 202 * @since 2.1 203 */ 204 @Parameter( defaultValue = "true", property = "updateWorkingCopyVersions" ) 205 private boolean updateWorkingCopyVersions; 206 207 /** 208 * Whether to suppress a commit of changes to the working copy before the tag is created. <br/> 209 * <br/> 210 * This requires <code>remoteTagging</code> to be set to false. <br/> 211 * <br/> 212 * <code>suppressCommitBeforeTag</code> is useful when you want to avoid poms with released versions in all 213 * revisions of your trunk or development branch. 214 * 215 * @since 2.1 216 */ 217 @Parameter( defaultValue = "false", property = "suppressCommitBeforeTag" ) 218 private boolean suppressCommitBeforeTag; 219 220 /** 221 * Wait the specified number of seconds before creating the tag. <br/> 222 * <code>waitBeforeTagging</code> is useful when your source repository is synced between several instances and 223 * access to it is determined by geographical location, like the SVN repository at the Apache Software Foundation. 224 * 225 * @since 2.2 226 */ 227 @Parameter( defaultValue = "0", property = "waitBeforeTagging" ) 228 private int waitBeforeTagging; 229 230 /** 231 * The role-hint for the {@link org.apache.maven.shared.release.policy.version.VersionPolicy} 232 * implementation used to calculate the project versions. 233 * 234 * @since 2.5.1 235 * @see org.apache.maven.shared.release.policies.DefaultVersionPolicy 236 */ 237 @Parameter( defaultValue = "default", property = "projectVersionPolicyId" ) 238 private String projectVersionPolicyId; 239 240 /** 241 * The role-hint for the {@link org.apache.maven.shared.release.policy.naming.NamingPolicy} 242 * implementation used to calculate the project branch and tag names. 243 * 244 * @since 3.0.0-M5 245 * @see org.apache.maven.shared.release.policies.DefaultNamingPolicy 246 */ 247 @Parameter( property = "projectNamingPolicyId" ) 248 private String projectTagNamingPolicyId; 249 250 /** 251 * The SCM commit comment when setting pom.xml to release. 252 * Defaults to "@{prefix} prepare release @{releaseLabel}". 253 * <p> 254 * Property interpolation is performed on the value, but in order to ensure that the interpolation occurs 255 * during release, you must use <code>@{...}</code> to reference the properties rather than <code>${...}</code>. 256 * The following properties are available: 257 * <ul> 258 * <li><code>prefix</code> - The comment prefix. 259 * <li><code>groupId</code> - The groupId of the root project. 260 * <li><code>artifactId</code> - The artifactId of the root project. 261 * <li><code>releaseLabel</code> - The release version of the root project. 262 * </ul> 263 * 264 * @since 3.0.0-M5 265 */ 266 @Parameter( defaultValue = "@{prefix} prepare release @{releaseLabel}", property = "scmReleaseCommitComment" ) 267 private String scmReleaseCommitComment = "@{prefix} prepare release @{releaseLabel}"; 268 269 /** 270 * The SCM commit comment when setting pom.xml back to development. 271 * Defaults to "@{prefix} prepare for next development iteration". 272 * <p> 273 * Property interpolation is performed on the value, but in order to ensure that the interpolation occurs 274 * during release, you must use <code>@{...}</code> to reference the properties rather than <code>${...}</code>. 275 * The following properties are available: 276 * <ul> 277 * <li><code>prefix</code> - The comment prefix. 278 * <li><code>groupId</code> - The groupId of the root project. 279 * <li><code>artifactId</code> - The artifactId of the root project. 280 * <li><code>releaseLabel</code> - The release version of the root project. 281 * </ul> 282 * 283 * @since 3.0.0-M5 284 */ 285 @Parameter( 286 defaultValue = "@{prefix} prepare for next development iteration", 287 property = "scmDevelopmentCommitComment" ) 288 private String scmDevelopmentCommitComment = "@{prefix} prepare for next development iteration"; 289 290 /** 291 * Specifies whether unresolved SNAPSHOT dependencies should automatically be resolved. 292 * If this is set, then this specifies the default answer to be used when unresolved SNAPSHOT 293 * dependencies should automatically be resolved ( 0:All 1:Project Dependencies 2:Plugins 294 * 3:Reports 4:Extensions ). Possible values are: 295 * <ul> 296 * <li>"all" or "0": resolve all kinds of snapshots, ie. project, plugin, report and extension dependencies </li> 297 * <li>"dependencies" or "1": resolve project dependencies</li> 298 * <li>"plugins" or "2": resolve plugin dependencis</li> 299 * <li>"reports" or "3": resolve report dependencies</li> 300 * <li>"extensions" or "4": resolve extension dependencies</li> 301 * </ul> 302 * 303 * @since 3.0.0-M5 304 */ 305 @Parameter( property = "autoResolveSnapshots" ) 306 private String autoResolveSnapshots; 307 308 /** 309 * Currently only implemented with svn scm. Enable the {@code --pin-externals} option in 310 * {@code svn copy} command which is new in Subversion 1.9. 311 * 312 * @since 3.0.0-M5 313 */ 314 @Parameter( defaultValue = "false", property = "pinExternals" ) 315 private boolean pinExternals; 316 317 @Override 318 public void execute() 319 throws MojoExecutionException, MojoFailureException 320 { 321 if ( generateReleasePoms ) 322 { 323 throw new MojoFailureException( "Generating release POMs is no longer supported in release:prepare. " 324 + "Please run release:prepare-with-pom instead." ); 325 } 326 327 prepareRelease( generateReleasePoms ); 328 } 329 330 /** 331 * <p>prepareRelease.</p> 332 * 333 * @param generateReleasePoms a boolean 334 * @throws org.apache.maven.plugin.MojoExecutionException if any. 335 * @throws org.apache.maven.plugin.MojoFailureException if any. 336 */ 337 protected void prepareRelease( boolean generateReleasePoms ) 338 throws MojoExecutionException, MojoFailureException 339 { 340 // this is here so the subclass can call it without getting the extra generateReleasePoms check in execute() 341 // above 342 super.execute(); 343 344 final ReleaseDescriptorBuilder config = createReleaseDescriptor(); 345 config.setAddSchema( addSchema ); 346 config.setGenerateReleasePoms( generateReleasePoms ); 347 config.setScmUseEditMode( useEditMode ); 348 config.setPreparationGoals( preparationGoals ); 349 config.setCompletionGoals( completionGoals ); 350 config.setCommitByProject( commitByProject ); 351 config.setUpdateDependencies( updateDependencies ); 352 config.setAutoVersionSubmodules( autoVersionSubmodules ); 353 config.setAllowTimestampedSnapshots( allowTimestampedSnapshots ); 354 config.setSnapshotReleasePluginAllowed( allowReleasePluginSnapshot ); 355 config.setDefaultReleaseVersion( releaseVersion ); 356 config.setDefaultDevelopmentVersion( developmentVersion ); 357 config.setRemoteTagging( remoteTagging ); 358 config.setScmSignTags( signTag ); 359 config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions ); 360 config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTag ); 361 config.setWaitBeforeTagging( waitBeforeTagging ); 362 config.setProjectVersionPolicyId( projectVersionPolicyId ); 363 config.setProjectNamingPolicyId( projectTagNamingPolicyId ); 364 config.setScmDevelopmentCommitComment( scmDevelopmentCommitComment ); 365 config.setScmReleaseCommitComment( scmReleaseCommitComment ); 366 config.setAutoResolveSnapshots( autoResolveSnapshots ); 367 config.setPinExternals( pinExternals ); 368 369 if ( checkModificationExcludeList != null ) 370 { 371 checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," ); 372 } 373 374 if ( checkModificationExcludes != null ) 375 { 376 config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) ); 377 } 378 379 ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); 380 prepareRequest.setReleaseDescriptorBuilder( config ); 381 prepareRequest.setReleaseEnvironment( getReleaseEnvironment() ); 382 prepareRequest.setReactorProjects( getReactorProjects() ); 383 prepareRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog(), dryRun ) ); 384 prepareRequest.setResume( resume ); 385 prepareRequest.setDryRun( dryRun ); 386 prepareRequest.setUserProperties( session.getUserProperties() ); 387 388 try 389 { 390 releaseManager.prepare( prepareRequest ); 391 } 392 catch ( ReleaseExecutionException e ) 393 { 394 throw new MojoExecutionException( e.getMessage(), e ); 395 } 396 catch ( ReleaseFailureException e ) 397 { 398 throw new MojoFailureException( e.getMessage(), e ); 399 } 400 } 401 402 }