Skip to content

Commit

Permalink
Add system prop to store compound extesntions types
Browse files Browse the repository at this point in the history
  Because of maven classifier does not forbid dots, which makes it hard
  to decide the exact file types, so here add a temporary workaround to
  let user defines the exact file types for compound extensions to
  ditinguish the compound extensions types from classifier with dots.
  • Loading branch information
ligangty committed Sep 2, 2024
1 parent 988e04f commit 27ecb71
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.commonjava.atlas.maven.ident.util;

import org.apache.commons.lang3.StringUtils;
import org.commonjava.atlas.maven.ident.ref.ArtifactRef;
import org.commonjava.atlas.maven.ident.ref.ProjectVersionRef;
import org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef;
Expand Down Expand Up @@ -50,7 +51,11 @@ 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", "xml.gz" ) );
// Note: this looks a little ugly, but it's also caused by the "classifier with dots" problem in maven artifacts.
// So for the file types with more than one extension separated by dots, we should treat them as special types
// here and extract them before extract the classifier.
private static final Set<String> COMPOUND_EXTENSIONS_TYPES =
new HashSet<>( Arrays.asList( "tar.gz", "tar.bz2", "xml.gz", "spdx.rdf.xml" ) );

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

Expand Down Expand Up @@ -94,7 +99,15 @@ public static ArtifactPathInfo parse( final String path )
// 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 )
final String typesFromSys = System.getProperty( "atlas.compoext.types" );
if ( StringUtils.isNotBlank( typesFromSys ) )
{
for ( final String type : typesFromSys.split( "," ) )
{
COMPOUND_EXTENSIONS_TYPES.add( type.trim() );
}
}
for ( String type : COMPOUND_EXTENSIONS_TYPES )
{
if ( left.endsWith( type ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void testSnapshotPath()
}

@Test
public void matchSpecialTypes()
public void matchCompoundExtTypes1()
{
String path =
"/com/github/jomrazek/jomrazek-empty/1.0.1.redhat-00010/jomrazek-empty-1.0.1.redhat-00010-src.tar.bz2";
Expand All @@ -154,6 +154,41 @@ public void matchSpecialTypes()
assertThat( info.getVersion(), equalTo( "3.2.7.fuse-750011-redhat-00001" ) );
assertThat( info.getClassifier(), equalTo( "" ) );
assertThat( info.getType(), equalTo( "xml.gz" ) );

path =
"/org/apache/commons/commons-compress/1.26.0.temporary-redhat-00002/commons-compress-1.26.0.temporary-redhat-00002.spdx.rdf.xml";
info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "1.26.0.temporary-redhat-00002" ) );
assertThat( info.getClassifier(), equalTo( "" ) );
assertThat( info.getType(), equalTo( "spdx.rdf.xml" ) );


}

@Test
public void matchCompoundExtTypes2(){
System.setProperty("atlas.compoext.types", "a.b.c, x.y.z");

String path =
"/com/example/example-artifact/1.0.0.redhat-00001/example-artifact-1.0.0.redhat-00001-x.y.z.tar";
ArtifactPathInfo info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "1.0.0.redhat-00001" ) );
assertThat( info.getClassifier(), equalTo( "x.y.z" ) );
assertThat( info.getType(), equalTo( "tar" ) );

path =
"/com/example/example-artifact/1.0.0.redhat-00001/example-artifact-1.0.0.redhat-00001.a.b.c";
info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "1.0.0.redhat-00001" ) );
assertThat( info.getClassifier(), equalTo( "" ) );
assertThat( info.getType(), equalTo( "a.b.c" ) );

path =
"/com/example/example-artifact/1.0.0.redhat-00001/example-artifact-1.0.0.redhat-00001-sources.a.b.c";
info = ArtifactPathInfo.parse( path );
assertThat( info.getVersion(), equalTo( "1.0.0.redhat-00001" ) );
assertThat( info.getClassifier(), equalTo( "sources" ) );
assertThat( info.getType(), equalTo( "a.b.c" ) );
}

@Test
Expand Down

0 comments on commit 27ecb71

Please sign in to comment.