Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

363:Force update parent version with real version #364

Merged
merged 8 commits into from Jul 8, 2021
Expand Up @@ -409,6 +409,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 @@ -417,10 +421,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 )
akilantech marked this conversation as resolved.
Show resolved Hide resolved
{
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 1.0-alpha-1
olamy marked this conversation as resolved.
Show resolved Hide resolved
*/
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 )
}
}

}
}