From 4fd669c30cfdb5df06c0446af440d47c4356b923 Mon Sep 17 00:00:00 2001 From: Akilan Irudayaraja Date: Thu, 8 Jul 2021 18:17:58 +0800 Subject: [PATCH] 363:Force update parent version with real version (#364) Fix #363 :Force update parent version with real version. if parent version is RELEASE or LATEST --- .../versions/AbstractVersionsUpdaterMojo.java | 25 +++++++++++++++++++ .../mojo/versions/UpdateParentMojo.java | 12 +++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java b/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java index 3b11ece89..75027618a 100644 --- a/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java @@ -400,6 +400,10 @@ protected abstract void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException; /** + * @deprecated + * This method no longer supported. + * use shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion, Boolean forceUpdate ) + * * Returns true if the update should be applied. * * @param artifact The artifact. @@ -408,10 +412,31 @@ protected abstract void update( ModifiedPomXMLEventReader pom ) * @return true if the update should be applied. * @since 1.0-alpha-1 */ + @Deprecated protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion ) + { + return shouldApplyUpdate(artifact,currentVersion,updateVersion,false); + } + + /** + * Returns true if the update should be applied. + * + * @param artifact The artifact. + * @param currentVersion The current version of the artifact. + * @param updateVersion The proposed new version of the artifact. + * @return true if the update should be applied to the pom. + * @since 2.9 + */ + protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion, boolean forceUpdate ) { getLog().debug( "Proposal is to update from " + currentVersion + " to " + updateVersion ); + if ( forceUpdate ) + { + getLog().info( "Force update enabled. LATEST or RELEASE versions will be overwritten with real version" ); + return true; + } + if ( updateVersion == null ) { getLog().warn( "Not updating version: could not resolve any versions" ); diff --git a/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java b/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java index 14020a3e8..7d3137950 100644 --- a/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java @@ -54,6 +54,14 @@ public class UpdateParentMojo @Parameter( property = "parentVersion", defaultValue = "null" ) protected String parentVersion = null; + /** + * to update parent version by force when it is RELEASE or LATEST + * + * @since 2.9 + */ + @Parameter( property = "forceUpdate", defaultValue = "false" ) + protected boolean forceUpdate = false; + // -------------------------- OTHER METHODS -------------------------- /** @@ -111,7 +119,7 @@ protected void update( ModifiedPomXMLEventReader pom ) throw new MojoExecutionException( e.getMessage(), e ); } - if ( !shouldApplyUpdate( artifact, currentVersion, artifactVersion ) ) + if ( !shouldApplyUpdate( artifact, currentVersion, artifactVersion, forceUpdate ) ) { return; } @@ -124,4 +132,4 @@ protected void update( ModifiedPomXMLEventReader pom ) } } -} \ No newline at end of file +}