-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix (model): Just move toPkgURL() closer to parsePkgURL() in GAVR
- Loading branch information
Showing
1 changed file
with
27 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
|
@@ -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/[email protected]?classifier=javadoc". See <a | ||
|
@@ -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) | ||
|