Skip to content

Commit 4e0daa5

Browse files
committed
Fix ArtifactPathInfo parse issue for project-sources.tar.gz
1 parent 01081f6 commit 4e0daa5

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

identities/src/main/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfo.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,12 @@ public class ArtifactPathInfo implements PathInfo
3232

3333
private static final String VERSION_RAW_REGEX = "(([^/]+)(-SNAPSHOT)?)"; // group 4~6
3434

35-
// For classifier, if it contains dot, that means we cannot use a simple pattern which just defined by dot/non-dot way to
36-
// tell, so we must define this strict way like: 1. Starts with several alphabet. 2. Following with several or non dot plus digits
37-
// Here is one example: wildfly8.1.3
38-
private static final String CLASSIFIER_REGEX = "(-([a-zA-Z]+\\d*(\\.\\d*)*))?"; // group 13~15
39-
40-
private static final String TYPE_REGEX = "(\\.(.+))"; // group 16~17
35+
private static final String CLASSIFIER_AND_TYPE = "-?(.+)";
4136

4237
// regex developed at: http://fiddle.re/tvk5
4338
private static final String ARTIFACT_PATH_REGEX =
4439
"/?" + GROUP_REGEX + "/" + ARTIFACT_REGEX + "/" + VERSION_RAW_REGEX + "/(\\3-((\\4)|(\\5-"
45-
+ SnapshotUtils.RAW_REMOTE_SNAPSHOT_PART_PATTERN + "))" + CLASSIFIER_REGEX + TYPE_REGEX + ")";
46-
// RAW_REMOTE_SNAPSHOT_PART_PATTERN contains group 11 & 12
40+
+ SnapshotUtils.RAW_REMOTE_SNAPSHOT_PART_PATTERN + "))" + CLASSIFIER_AND_TYPE + ")";
4741

4842
private static final int GROUP_ID_GROUP = 1;
4943

@@ -55,15 +49,7 @@ public class ArtifactPathInfo implements PathInfo
5549

5650
private static final int VERSION_GROUP = 8;
5751

58-
private static final int NON_REMOTE_SNAP_CLASSIFIER_GROUP = 12;
59-
60-
private static final int REMOTE_SNAP_CLASSIFIER_GROUP = 14;
61-
62-
private static final int NON_REMOTE_SNAP_TYPE_GROUP = 14;
63-
64-
private static final int REMOTE_SNAP_TYPE_GROUP = 17;
65-
66-
private static final int REMOTE_SNAPSHOT_GROUP_COUNT = 17;
52+
private static final String TAR_GZ = "tar.gz";
6753

6854
public static ArtifactPathInfo parse( final String path )
6955
{
@@ -80,23 +66,32 @@ public static ArtifactPathInfo parse( final String path )
8066
}
8167

8268
final int groupCount = matcher.groupCount();
83-
8469
final String g = matcher.group( GROUP_ID_GROUP )
8570
.replace( '/', '.' );
8671
final String a = matcher.group( ARTIFACT_ID_GROUP );
8772
final String v = matcher.group( VERSION_GROUP );
8873

89-
final String c;
90-
final String t;
91-
if ( groupCount == REMOTE_SNAPSHOT_GROUP_COUNT )
74+
String c = "";
75+
String t;
76+
77+
String left = matcher.group( groupCount );
78+
79+
// The classifier can contain dots or hyphens, it is hard to separate it from type. e.g,
80+
// wildfly8.1.3.jar, project-sources.tar.gz, etc. We don't have a very solid pattern to match the classifier.
81+
// Here we use the best guess.
82+
if ( left.endsWith( TAR_GZ ) )
9283
{
93-
c = matcher.group( REMOTE_SNAP_CLASSIFIER_GROUP );
94-
t = matcher.group( REMOTE_SNAP_TYPE_GROUP );
84+
t = TAR_GZ;
9585
}
9686
else
9787
{
98-
c = matcher.group( NON_REMOTE_SNAP_CLASSIFIER_GROUP );
99-
t = matcher.group( NON_REMOTE_SNAP_TYPE_GROUP );
88+
t = left.substring( left.lastIndexOf( "." ) + 1 ); // Otherwise, use the simple file ext as type
89+
}
90+
int extLen = t.length() + 1; // plus len of "."
91+
int leftLen = left.length();
92+
if ( leftLen > extLen )
93+
{
94+
c = left.substring( 0, leftLen - extLen );
10095
}
10196

10297
final String f = matcher.group( FILE_GROUP );

identities/src/test/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfoTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public void matchNormalClassifier()
6868
assertThat( pathInfo.getType(), equalTo( "tar.gz" ) );
6969
}
7070

71+
@Test
72+
public void matchNormalClassifier2()
73+
{
74+
String 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";
75+
ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
76+
assertThat( pathInfo.getVersion(), equalTo( "1.5.0.Final-temporary-redhat-00033" ) );
77+
assertThat( pathInfo.getClassifier(), equalTo( "project-sources" ) );
78+
assertThat( pathInfo.getType(), equalTo( "tar.gz" ) );
79+
}
80+
7181
@Test
7282
public void matchGAWithClassifier()
7383
{

0 commit comments

Comments
 (0)