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

Fix checksum paths parsing issue #104

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public class ArtifactPathInfo implements PathInfo

private static final int VERSION_GROUP = 8;

private static final Set<String> SPECIAL_TYPES = new HashSet<>( Arrays.asList( "tar.gz", "tar.bz2" ) );
private static final Set<String> SPECIAL_TYPES = new HashSet<>( Arrays.asList( "tar.gz", "tar.bz2", "xml.gz" ) );

private static final Set<String> CHECKSUM_TYPES = new HashSet<>( Arrays.asList( ".md5", ".sha1", ".sha128", ".sha256", ".sha384", ".sha512" ) );

public static ArtifactPathInfo parse( final String path )
{
Expand All @@ -76,11 +78,24 @@ public static ArtifactPathInfo parse( final String path )
String t = null;

String left = matcher.group( groupCount );


// If the path is a checksum path, we should abandon the checksum type and analyze its real artifact.
String checksumType = null;
for ( String type : CHECKSUM_TYPES )
{
if ( left.endsWith( type ) )
{
left = left.substring( 0, left.length() - type.length() );
checksumType = type;
break;
}
}

// The classifier can contain dots or hyphens, it is hard to separate it from type. e.g,
// wildfly8.1.3.jar, project-sources.tar.gz, etc. We don't have a very solid pattern to match the classifier.
// Here we use the best guess.
for ( String type : SPECIAL_TYPES ){
for ( String type : SPECIAL_TYPES )
{
if ( left.endsWith( type ) )
{
t = type;
Expand All @@ -92,6 +107,7 @@ public static ArtifactPathInfo parse( final String path )
t = left.substring( left.lastIndexOf( "." ) + 1 ); // Otherwise, use the simple file ext as type
}


int extLen = t.length() + 1; // plus len of "."
int leftLen = left.length();
if ( leftLen > extLen )
Expand All @@ -101,6 +117,11 @@ public static ArtifactPathInfo parse( final String path )

final String f = matcher.group( FILE_GROUP );

if ( checksumType != null && CHECKSUM_TYPES.contains( checksumType ) )
{
t = t + checksumType;
}

return new ArtifactPathInfo( g, a, v, c, t, f, path );
}

Expand Down Expand Up @@ -274,16 +295,10 @@ else if ( !groupId.equals( other.groupId ) )
}
if ( version == null )
{
if ( other.version != null )
{
return false;
}
}
else if ( !version.equals( other.version ) )
{
return false;
return other.version == null;
}
return true;
else
return version.equals( other.version );
}

public ProjectVersionRef getProjectId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,6 @@ public void matchNormalClassifier2()
assertThat( pathInfo.getType(), equalTo( "tar.gz" ) );
}

@Test
public void matchNormalClassifier3()
{
String path =
"/com/github/jomrazek/jomrazek-empty/1.0.1.redhat-00010/jomrazek-empty-1.0.1.redhat-00010-src.tar.bz2";
ArtifactPathInfo info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "1.0.1.redhat-00010" ) );
assertThat( info.getClassifier(), equalTo( "src" ) );
assertThat( info.getType(), equalTo( "tar.bz2" ) );

path =
"/io/quarkus/platform/quarkus-google-cloud-services-bom-quarkus-platform-descriptor/2.13.7.Final-redhat-00001/quarkus-google-cloud-services-bom-quarkus-platform-descriptor-2.13.7.Final-redhat-00001-2.13.7.Final-redhat-00001.json";
info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "2.13.7.Final-redhat-00001" ) );
assertThat( info.getClassifier(), equalTo( "2.13.7.Final-redhat-00001" ) );
assertThat( info.getType(), equalTo( "json" ) );
}

@Test
public void matchGAWithClassifier()
{
Expand Down Expand Up @@ -149,6 +131,69 @@ public void testSnapshotPath()
assertEquals( "20160229", new SimpleDateFormat( "yyyyMMdd" ).format( snap.getTimestamp() ) );
}

@Test
public void matchSpecialTypes()
{
String path =
"/com/github/jomrazek/jomrazek-empty/1.0.1.redhat-00010/jomrazek-empty-1.0.1.redhat-00010-src.tar.bz2";
ArtifactPathInfo info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "1.0.1.redhat-00010" ) );
assertThat( info.getClassifier(), equalTo( "src" ) );
assertThat( info.getType(), equalTo( "tar.bz2" ) );

path =
"/io/quarkus/platform/quarkus-google-cloud-services-bom-quarkus-platform-descriptor/2.13.7.Final-redhat-00001/quarkus-google-cloud-services-bom-quarkus-platform-descriptor-2.13.7.Final-redhat-00001-2.13.7.Final-redhat-00001.json";
info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "2.13.7.Final-redhat-00001" ) );
assertThat( info.getClassifier(), equalTo( "2.13.7.Final-redhat-00001" ) );
assertThat( info.getType(), equalTo( "json" ) );

path =
"/org/apache/cxf/cxf-repository/3.2.7.fuse-750011-redhat-00001/cxf-repository-3.2.7.fuse-750011-redhat-00001.xml.gz";
info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "3.2.7.fuse-750011-redhat-00001" ) );
assertThat( info.getClassifier(), equalTo( "" ) );
assertThat( info.getType(), equalTo( "xml.gz" ) );
}

@Test
public void testChecksumTypes()
{
String path =
"/com/webauthn4j/webauthn4j-test/0.12.0.RELEASE-redhat-00002/webauthn4j-test-0.12.0.RELEASE-redhat-00002-sources.jar.md5";
ArtifactPathInfo info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "0.12.0.RELEASE-redhat-00002" ) );
assertThat( info.getClassifier(), equalTo( "sources" ) );
assertThat( info.getType(), equalTo( "jar.md5" ) );

path =
"com/github/jomrazek/jomrazek-empty/1.0.1.redhat-00010/jomrazek-empty-1.0.1.redhat-00010-src.tar.bz2.sha1";
info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "1.0.1.redhat-00010" ) );
assertThat( info.getClassifier(), equalTo( "src" ) );
assertThat( info.getType(), equalTo( "tar.bz2.sha1" ) );

path = "/org/apache/commons/commons-lang3/3.0.0.GA/commons-lang3-3.0.0.GA-test.tar.gz.sha128";
info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "3.0.0.GA" ) );
assertThat( info.getClassifier(), equalTo( "test" ) );
assertThat( info.getType(), equalTo( "tar.gz.sha128" ) );

path =
"/org/jboss/modules/jboss-modules/1.5.0.Final-temporary-redhat-00033/jboss-modules-1.5.0.Final-temporary-redhat-00033-project-sources.tar.gz.sha256";
ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
assertThat( pathInfo.getVersion(), equalTo( "1.5.0.Final-temporary-redhat-00033" ) );
assertThat( pathInfo.getClassifier(), equalTo( "project-sources" ) );
assertThat( pathInfo.getType(), equalTo( "tar.gz.sha256" ) );

path =
"/com/webauthn4j/webauthn4j-test/0.12.0.RELEASE-redhat-00002/webauthn4j-test-0.12.0.RELEASE-redhat-00002-sources.jar.sha512";
pathInfo = ArtifactPathInfo.parse( path );
assertThat( pathInfo.getGroupId(), equalTo( "com.webauthn4j" ) );
assertThat( pathInfo.getArtifactId(), equalTo( "webauthn4j-test" ) );
assertThat( pathInfo.getVersion(), equalTo( "0.12.0.RELEASE-redhat-00002" ) );
assertThat( pathInfo.getClassifier(), equalTo( "sources" ) );
assertThat( pathInfo.getType(), equalTo( "jar.sha512" ) );
}

}
Loading