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

Make TerminalOutput.pathToMaven() more robust to avoid #929 #930

Merged
merged 1 commit into from
Apr 25, 2024
Merged
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 @@ -714,37 +714,45 @@ private AttributedString formatTransfers(String projectId) {

public static String pathToMaven(String location) {
String[] p = location.split("/");
if (p.length >= 4 && p[p.length - 1].startsWith(p[p.length - 3] + "-" + p[p.length - 2])) {
String artifactId = p[p.length - 3];
String version = p[p.length - 2];
String classifier;
String type;
String artifactIdVersion = artifactId + "-" + version;
StringBuilder sb = new StringBuilder();
if (p[p.length - 1].charAt(artifactIdVersion.length()) == '-') {
classifier =
p[p.length - 1].substring(artifactIdVersion.length() + 1, p[p.length - 1].lastIndexOf('.'));
} else {
classifier = null;
}
type = p[p.length - 1].substring(p[p.length - 1].lastIndexOf('.') + 1);
for (int j = 0; j < p.length - 3; j++) {
if (j > 0) {
sb.append('.');
}
sb.append(p[j]);
}
sb.append(':').append(artifactId).append(':').append(version);
if (!"jar".equals(type) || classifier != null) {
sb.append(':');
if (!"jar".equals(type)) {
sb.append(type);
}
if (classifier != null) {
sb.append(':').append(classifier);
if (p.length >= 4) {
final String artifactId = p[p.length - 3];
final String version = p[p.length - 2];
final String fileName = p[p.length - 1];
final int artifactIdVersionLength = artifactId.length() + 1 /* the dash */ + version.length();
if (fileName.length() > artifactIdVersionLength) {
/* We use fileName.length() > to avoid https://github.com/apache/maven-mvnd/issues/929
* In the code below, we assume that the fileName ends either with `.<extension>`
* or `-<classifier>.<extension>` */
final int lastPeriodPos = fileName.lastIndexOf('.');
if (lastPeriodPos >= 0) {
final String classifier;
final String type;
final StringBuilder sb = new StringBuilder();
if (fileName.charAt(artifactIdVersionLength) == '-') {
classifier = fileName.substring(artifactIdVersionLength + 1, lastPeriodPos);
} else {
classifier = null;
}
type = fileName.substring(lastPeriodPos + 1);
for (int j = 0; j < p.length - 3; j++) {
if (j > 0) {
sb.append('.');
}
sb.append(p[j]);
}
sb.append(':').append(artifactId).append(':').append(version);
if (!"jar".equals(type) || classifier != null) {
sb.append(':');
if (!"jar".equals(type)) {
sb.append(type);
}
if (classifier != null) {
sb.append(':').append(classifier);
}
}
return sb.toString();
}
}
return sb.toString();
}
return location;
}
Expand Down
Loading