Skip to content

Commit

Permalink
[MNG-6705] Speep up Artifact version check and Parent interpolation
Browse files Browse the repository at this point in the history
This closes apache#260
  • Loading branch information
gnodet authored and michael-o committed Jul 10, 2019
1 parent 9b8ae7d commit 53f04f0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,22 @@ else if ( Artifact.VERSION_FILE_PATTERN.matcher( version ).matches() )

public static String toSnapshotVersion( String version )
{
Validate.notBlank( version, "version can neither be null, empty nor blank" );
notBlank( version, "version can neither be null, empty nor blank" );

Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( version );
if ( m.matches() )
int lastHyphen = version.lastIndexOf( '-' );
if ( lastHyphen > 0 )
{
return m.group( 1 ) + "-" + Artifact.SNAPSHOT_VERSION;
}
else
{
return version;
int prevHyphen = version.lastIndexOf( '-', lastHyphen - 1 );
if ( prevHyphen > 0 )
{
Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( version );
if ( m.matches() )
{
return m.group( 1 ) + "-" + Artifact.SNAPSHOT_VERSION;
}
}
}
return version;
}

public static String versionlessKey( Artifact artifact )
Expand All @@ -74,8 +79,8 @@ public static String versionlessKey( Artifact artifact )

public static String versionlessKey( String groupId, String artifactId )
{
Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
notBlank( groupId, "groupId can neither be null, empty nor blank" );
notBlank( artifactId, "artifactId can neither be null, empty nor blank" );

return groupId + ":" + artifactId;
}
Expand All @@ -87,13 +92,22 @@ public static String key( Artifact artifact )

public static String key( String groupId, String artifactId, String version )
{
Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
Validate.notBlank( version, "version can neither be null, empty nor blank" );
notBlank( groupId, "groupId can neither be null, empty nor blank" );
notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
notBlank( version, "version can neither be null, empty nor blank" );

return groupId + ":" + artifactId + ":" + version;
}

private static void notBlank( String str, String message )
{
int c = str != null && str.length() > 0 ? str.charAt( 0 ) : 0;
if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) )
{
Validate.notBlank( str, message );
}
}

public static Map<String, Artifact> artifactMapByVersionlessId( Collection<Artifact> artifacts )
{
Map<String, Artifact> artifactMap = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
Expand Down Expand Up @@ -387,16 +386,7 @@ public void setBaseVersion( String baseVersion )

protected void setBaseVersionInternal( String baseVersion )
{
Matcher m = VERSION_FILE_PATTERN.matcher( baseVersion );

if ( m.matches() )
{
this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION;
}
else
{
this.baseVersion = baseVersion;
}
this.baseVersion = ArtifactUtils.toSnapshotVersion( baseVersion );
}

public int compareTo( Artifact a )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,12 @@ else if ( !parentIds.add( parentData.getId() ) )
if ( resultModel.getParent() != null )
{
final ModelData parentData = lineage.get( 1 );
final Model interpolatedParent = interpolateModel( parentData.getModel(), request, problems );
// parentData.setModel( interpolatedParent );
parentData.setVersion( interpolatedParent.getVersion() );
if ( parentData.getVersion() == null || parentData.getVersion().contains( "${" ) )
{
final Model interpolatedParent = interpolateModel( parentData.getModel(), request, problems );
// parentData.setModel( interpolatedParent );
parentData.setVersion( interpolatedParent.getVersion() );
}
}

// url normalization
Expand Down

0 comments on commit 53f04f0

Please sign in to comment.