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 maven2 path has double hash extension or .asc mix with hash extension parse error #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -124,6 +124,14 @@ private Coordinates maven2LayoutedPathToCoordinates(final String pathString, fin
}
}

for (HashType hashType : HashType.values()) {
if (str.endsWith("." + hashType.getExt())) {
extSuffix.insert(0, "." + hashType.getExt());
str = str.substring(0, str.length() - (hashType.getExt().length() + 1));
break;
}
}

if (str.endsWith(Constants.METADATA_FILENAME)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Maven2MavenPathParserMxTest
public static String[] CLASSIFIERS = {null, "single", "with-dash", "with.dot"};

public static String[] EXTENSIONS = {
"jar", "jar.sha1", "jar.asc", "jar.asc.md5", "tar.gz",
"jar", "jar.sha1", "jar.asc", "jar.asc.md5", "pom.md5.asc", "jar.md5.sha1", "jar.sha1.md5", "tar.gz",
"tar.anyext.sha1", "tar.anyext.md5", "tar.anyext.asc", "tar.anyext.asc.md5",
"cpio.anyext.sha1", "cpio.anyext.md5", "cpio.anyext.asc", "cpio.anyext.asc.md5",
"nk.os.sha1", "nk.os.md5", "nk.os.asc", "nk.os.asc.md5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,34 @@ public void artifact() throws Exception
assertThat(mavenPath.getCoordinates().getClassifier(), equalTo("some.strange.classifier"));
assertThat(mavenPath.getCoordinates().getExtension(), equalTo("pom.asc.sha1"));
assertThat(mavenPath.getCoordinates().getSignatureType(), equalTo(SignatureType.GPG));

mavenPath = pathParser.parsePath("/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.pom.md5.sha1");
assertThat(mavenPath, notNullValue());
assertThat(mavenPath.getFileName(), equalTo("jsr305-1.3.9.pom.md5.sha1"));
assertThat(mavenPath.getPath(), equalTo("com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.pom.md5.sha1"));
assertThat(mavenPath.getHashType(), equalTo(HashType.SHA1));
assertThat(mavenPath.getCoordinates(), notNullValue());
assertThat(mavenPath.getCoordinates().getGroupId(), equalTo("com.google.code.findbugs"));
assertThat(mavenPath.getCoordinates().getArtifactId(), equalTo("jsr305"));
assertThat(mavenPath.getCoordinates().getVersion(), equalTo("1.3.9"));
assertThat(mavenPath.getCoordinates().getBaseVersion(), equalTo("1.3.9"));
assertThat(mavenPath.getCoordinates().getClassifier(), nullValue());
assertThat(mavenPath.getCoordinates().getExtension(), equalTo("pom.md5.sha1"));
assertThat(mavenPath.getCoordinates().getSignatureType(), nullValue());

mavenPath = pathParser.parsePath("/com/netflix/spectator/spectator-ext-ipc/0.103.0/spectator-ext-ipc-0.103.0.pom.md5.asc");
assertThat(mavenPath, notNullValue());
assertThat(mavenPath.getFileName(), equalTo("spectator-ext-ipc-0.103.0.pom.md5.asc"));
assertThat(mavenPath.getPath(), equalTo("com/netflix/spectator/spectator-ext-ipc/0.103.0/spectator-ext-ipc-0.103.0.pom.md5.asc"));
assertThat(mavenPath.getHashType(), nullValue());
assertThat(mavenPath.getCoordinates(), notNullValue());
assertThat(mavenPath.getCoordinates().getGroupId(), equalTo("com.netflix.spectator"));
assertThat(mavenPath.getCoordinates().getArtifactId(), equalTo("spectator-ext-ipc"));
assertThat(mavenPath.getCoordinates().getVersion(), equalTo("0.103.0"));
assertThat(mavenPath.getCoordinates().getBaseVersion(), equalTo("0.103.0"));
assertThat(mavenPath.getCoordinates().getClassifier(), nullValue());
assertThat(mavenPath.getCoordinates().getExtension(), equalTo("pom.md5.asc"));
assertThat(mavenPath.getCoordinates().getSignatureType(), equalTo(SignatureType.GPG));
}

@Test
Expand Down