Skip to content

Commit

Permalink
fix (model): Just move toPkgURL() closer to parsePkgURL() in GAVR
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Feb 8, 2025
1 parent 2133bbc commit ddfb42e
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions java/dev/enola/model/enola/maven/connect/mima/GAVR.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
* <p>The GroupID, ArtifactID & Version are mandatory and cannot be empty. The Extension, Classifier
* & Repository can be empty, but never null.
*
* <p>The Maven default extension "jar" is hidden in the String and Package URL syntax (but is
* returned by {@link #extension()}).
* <p>The Maven default extension "jar" are hidden in the GAV coordinates and Package URL syntax
* (but is returned by {@link #extension()} API). This is different from Maven core, which always
* shows "jar".
*
* <p>This class itself does NOT imply any other "defaults" for Classifier & Repository. Callers of
* this class may resolve a GAVR without repot to one with a repo using {@link
* this class may resolve a GAVR without repo to one with a repo using {@link
* Mima#origin(ModelResponse)}.
*/
public record GAVR(
Expand Down Expand Up @@ -74,6 +75,29 @@ public static GAVR parseGAV(String gav) {
"");
}

/** Return a String in the same format that {@link #parsePkgURL(String)} uses. */
public String toPkgURL() {
var builder = PackageURLBuilder.aPackageURL();
builder.withType("maven");
builder.withNamespace(groupId);
builder.withName(artifactId);
builder.withVersion(version);
if (!extension.isEmpty() && !"jar".equals(extension)) {
builder.withQualifier("type", extension);
}
if (!classifier.isEmpty()) {
builder.withQualifier("classifier", classifier);
}
if (!repo.isEmpty()) {
builder.withQualifier("repository_url", repo);
}
try {
return builder.build().canonicalize();
} catch (MalformedPackageURLException e) {
throw new IllegalStateException(toGAV(), e);
}
}

/**
* Parse a Maven Package URL. For example,
* "pkg:maven/ch.vorburger.mariaDB4j/mariaDB4j-core@3.1.0?classifier=javadoc". See <a
Expand Down Expand Up @@ -214,29 +238,6 @@ public String toGAV() {
return sb.toString();
}

/** Return a String in the same format that {@link #parsePkgURL(String)} uses. */
public String toPkgURL() {
var builder = PackageURLBuilder.aPackageURL();
builder.withType("maven");
builder.withNamespace(groupId);
builder.withName(artifactId);
builder.withVersion(version);
if (!extension.isEmpty() && !"jar".equals(extension)) {
builder.withQualifier("type", extension);
}
if (!classifier.isEmpty()) {
builder.withQualifier("classifier", classifier);
}
if (!repo.isEmpty()) {
builder.withQualifier("repository_url", repo);
}
try {
return builder.build().canonicalize();
} catch (MalformedPackageURLException e) {
throw new IllegalStateException(toGAV(), e);
}
}

public Builder toBuilder() {
return new Builder()
.groupId(groupId)
Expand Down

0 comments on commit ddfb42e

Please sign in to comment.