Skip to content

Commit

Permalink
Fixed mojohaus#461
Browse files Browse the repository at this point in the history
 o Updated use-dep-version to process parent version
  • Loading branch information
RM033832 committed Aug 18, 2021
1 parent 30f0d36 commit 8ae7c94
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Expand Up @@ -273,28 +273,37 @@ protected String toString( MavenProject project )

protected String toString( Dependency d )
{
return getString(d.getGroupId(), d.getArtifactId(), d.getType(), d.getClassifier(), d.getVersion());
}

protected String toString( Artifact a )
{
return getString(a.getGroupId(), a.getArtifactId(), a.getType(), a.getClassifier(), a.getVersion());
}

private String getString(String groupId, String artifactId, String type, String classifier, String version) {
StringBuilder buf = new StringBuilder();
buf.append( d.getGroupId() );
buf.append(groupId);
buf.append( ':' );
buf.append( d.getArtifactId() );
if ( d.getType() != null && d.getType().length() > 0 )
buf.append(artifactId);
if ( type != null && type.length() > 0 )
{
buf.append( ':' );
buf.append( d.getType() );
buf.append(type);
}
else
{
buf.append( ":jar" );
}
if ( d.getClassifier() != null && d.getClassifier().length() > 0 )
if ( classifier != null && classifier.length() > 0 )
{
buf.append( ':' );
buf.append( d.getClassifier() );
buf.append(classifier);
}
if ( d.getVersion() != null && d.getVersion().length() > 0 )
if ( version != null && version.length() > 0 )
{
buf.append( ":" );
buf.append( d.getVersion() );
buf.append(version);
}
return buf.toString();
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java
Expand Up @@ -83,6 +83,11 @@ protected void update( ModifiedPomXMLEventReader pom )
{
useDepVersion( pom, getProject().getDependencies() );
}

if(getProject().getParentArtifact() != null && isProcessingParent() )
{
useParentVersion( pom, getProject().getParentArtifact());
}
}
catch ( ArtifactMetadataRetrievalException e )
{
Expand Down Expand Up @@ -133,4 +138,28 @@ private void useDepVersion( ModifiedPomXMLEventReader pom, Collection<Dependency
}
}
}

private void useParentVersion( ModifiedPomXMLEventReader pom, Artifact artifact )
throws MojoExecutionException, XMLStreamException, ArtifactMetadataRetrievalException
{
if ( isIncluded( artifact ) )
{
if ( !forceVersion )
{
ArtifactVersions versions = getHelper().lookupArtifactVersions( artifact, false );

if ( !versions.containsVersion( depVersion ) )
{
throw new MojoExecutionException( String.format( "Version %s is not available for artifact %s:%s",
depVersion, artifact.getGroupId(),
artifact.getArtifactId() ) );
}
}

if ( PomHelper.setProjectParentVersion(pom, depVersion) )
{
getLog().info( "Updated " + toString( artifact ) + " to version " + depVersion );
}
}
}
}
Expand Up @@ -335,7 +335,7 @@ public static String getProjectVersion( final ModifiedPomXMLEventReader pom )
* @param pom The pom to modify.
* @param value The new value of the property.
* @return <code>true</code> if a replacement was made.
* @throws XMLStreamException if somethinh went wrong.
* @throws XMLStreamException if something went wrong.
*/
public static boolean setProjectParentVersion( final ModifiedPomXMLEventReader pom, final String value )
throws XMLStreamException
Expand Down

0 comments on commit 8ae7c94

Please sign in to comment.