Skip to content

Commit

Permalink
363:Force update parent version with real version (#364)
Browse files Browse the repository at this point in the history
Fix #363  :Force update parent version with real version. if parent version is RELEASE or LATEST
  • Loading branch information
akilantech committed Jul 8, 2021
1 parent 833f847 commit 4fd669c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Expand Up @@ -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 <code>true</code> if the update should be applied.
*
* @param artifact The artifact.
Expand All @@ -408,10 +412,31 @@ protected abstract void update( ModifiedPomXMLEventReader pom )
* @return <code>true</code> 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 <code>true</code> 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 <code>true</code> 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" );
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
Expand Up @@ -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 --------------------------

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -124,4 +132,4 @@ protected void update( ModifiedPomXMLEventReader pom )
}
}

}
}

0 comments on commit 4fd669c

Please sign in to comment.