diff --git a/identities/src/main/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfo.java b/identities/src/main/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfo.java index 704c6c1b..f7c99a4c 100644 --- a/identities/src/main/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfo.java +++ b/identities/src/main/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfo.java @@ -50,7 +50,9 @@ public class ArtifactPathInfo implements PathInfo private static final int VERSION_GROUP = 8; - private static final Set SPECIAL_TYPES = new HashSet<>( Arrays.asList( "tar.gz", "tar.bz2" ) ); + private static final Set SPECIAL_TYPES = new HashSet<>( Arrays.asList( "tar.gz", "tar.bz2", "xml.gz" ) ); + + private static final Set CHECKSUM_TYPES = new HashSet<>( Arrays.asList( ".md5", ".sha1", ".sha128", ".sha256", ".sha384", ".sha512" ) ); public static ArtifactPathInfo parse( final String path ) { @@ -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; @@ -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 ) @@ -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 ); } @@ -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() diff --git a/identities/src/test/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfoTest.java b/identities/src/test/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfoTest.java index 99db4691..339092ad 100644 --- a/identities/src/test/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfoTest.java +++ b/identities/src/test/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfoTest.java @@ -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() { @@ -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" ) ); + } }