Package com.github.packageurl
Class PackageURL
java.lang.Object
com.github.packageurl.PackageURL
- All Implemented Interfaces:
Serializable
Package-URL (aka purl) is a "mostly universal" URL to describe a package. A purl is a URL composed of seven components:
scheme:type/namespace/name@version?qualifiers#subpath
Components are separated by a specific character for unambiguous parsing. A purl must NOT contain a URL Authority i.e. there is no support for username, password, host and port components. A namespace segment may sometimes look like a host but its interpretation is specific to a type.
- Since:
- 1.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConvenience constants that defines common Package-URL 'type's. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe name of the package.private StringThe name prefix such as a Maven groupid, a Docker image owner, a GitHub user or organization.private static final PatternExtra qualifying data for a package such as an OS, architecture, a distro, etc.private StringThe PackageURL scheme constantprivate static final longprivate StringExtra subpath within a package, relative to the package root.private StringThe package "type" or package "protocol" such as maven, npm, nuget, gem, pypi, etc.private StringThe version of the package. -
Constructor Summary
ConstructorsConstructorDescriptionPackageURL(String purl) Constructs a new PackageURL object by parsing the specified string.PackageURL(String type, String name) Constructs a new PackageURL object by specifying only the required parameters necessary to create a valid PackageURL.PackageURL(String type, String namespace, String name, String version, TreeMap<String, String> qualifiers, String subpath) Constructs a new PackageURL object. -
Method Summary
Modifier and TypeMethodDescriptionReturns the canonicalized representation of the purl.private Stringcanonicalize(boolean coordinatesOnly) Returns the canonicalized representation of the purl.private StringencodePath(String path) booleanReturns only the canonicalized coordinates of the Package URL which includes the type, namespace, name, and version, and which omits the qualifier and subpath.getName()Returns the name of the package.Returns the name prefix such as a Maven groupid, a Docker image owner, a GitHub user or organization.Returns extra qualifying data for a package such as an OS, architecture, a distro, etc.Returns the package url scheme.Returns extra subpath within a package, relative to the package root.getType()Returns the package "type" or package "protocol" such as maven, npm, nuget, gem, pypi, etc.Returns the version of the package.inthashCode()private static booleanisAlpha(int c) booleanisBaseEquals(PackageURL purl) Deprecated.This method is no longer recommended and will be removed from a future release.booleanisCanonicalEquals(PackageURL purl) Evaluates if the specified Package URL has the same canonical value.booleanEvaluates if the specified Package URL has the same values up to, but excluding the qualifier (querystring).private static booleanisDigit(int c) private static booleanisUnreserved(int c) private voidGiven a specified PackageURL, this method will parse the purl and populate this classes instance fields so that the corresponding getters may be called to retrieve the individual pieces of the purl.private String[]parseQualifiers(String encodedString) private StringpercentDecode(String input) Optionally decodes a String, if it's encoded.private StringpercentEncode(String input) Encodes the input in conformance with RFC 3986.toString()Returns the canonicalized representation of the purl.static Stringprivate static Stringprivate StringvalidateKey(String value) private StringvalidateName(String value) private StringvalidateNamespace(String value) private StringvalidateNamespace(String[] values) private StringvalidatePath(String[] segments, boolean isSubpath) private StringvalidatePath(String value, boolean isSubpath) validateQualifiers(Map<String, String> values) private StringvalidateScheme(String value) private StringvalidateType(String value) private StringvalidateVersion(String value) private voidverifyTypeConstraints(String type, String namespace, String name) Some purl types may have specific constraints.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
PATH_SPLITTER
-
scheme
The PackageURL scheme constant -
type
The package "type" or package "protocol" such as maven, npm, nuget, gem, pypi, etc. Required. -
namespace
The name prefix such as a Maven groupid, a Docker image owner, a GitHub user or organization. Optional and type-specific. -
name
The name of the package. Required. -
version
The version of the package. Optional. -
qualifiers
Extra qualifying data for a package such as an OS, architecture, a distro, etc. Optional and type-specific. -
subpath
Extra subpath within a package, relative to the package root. Optional.
-
-
Constructor Details
-
PackageURL
Constructs a new PackageURL object by parsing the specified string.- Parameters:
purl- a valid package URL string to parse- Throws:
MalformedPackageURLException- if parsing fails- Since:
- 1.0.0
-
PackageURL
Constructs a new PackageURL object by specifying only the required parameters necessary to create a valid PackageURL.- Parameters:
type- the type of package (i.e. maven, npm, gem, etc)name- the name of the package- Throws:
MalformedPackageURLException- if parsing fails- Since:
- 1.0.0
-
PackageURL
public PackageURL(String type, String namespace, String name, String version, TreeMap<String, String> qualifiers, String subpath) throws MalformedPackageURLExceptionConstructs a new PackageURL object.- Parameters:
type- the type of package (i.e. maven, npm, gem, etc)namespace- the name prefix (i.e. group, owner, organization)name- the name of the packageversion- the version of the packagequalifiers- an array of key/value pair qualifierssubpath- the subpath string- Throws:
MalformedPackageURLException- if parsing fails- Since:
- 1.0.0
-
-
Method Details
-
toBuilder
-
getScheme
Returns the package url scheme.- Returns:
- the scheme
- Since:
- 1.0.0
-
getType
Returns the package "type" or package "protocol" such as maven, npm, nuget, gem, pypi, etc.- Returns:
- the type
- Since:
- 1.0.0
-
getNamespace
Returns the name prefix such as a Maven groupid, a Docker image owner, a GitHub user or organization.- Returns:
- the namespace
- Since:
- 1.0.0
-
getName
Returns the name of the package.- Returns:
- the name of the package
- Since:
- 1.0.0
-
getVersion
Returns the version of the package.- Returns:
- the version of the package
- Since:
- 1.0.0
-
getQualifiers
Returns extra qualifying data for a package such as an OS, architecture, a distro, etc. This method returns an UnmodifiableMap.- Returns:
- qualifiers
- Since:
- 1.0.0
-
getSubpath
Returns extra subpath within a package, relative to the package root.- Returns:
- the subpath
- Since:
- 1.0.0
-
validateScheme
- Throws:
MalformedPackageURLException
-
validateType
- Throws:
MalformedPackageURLException
-
validateNamespace
- Throws:
MalformedPackageURLException
-
validateNamespace
- Throws:
MalformedPackageURLException
-
validateName
- Throws:
MalformedPackageURLException
-
validateVersion
-
validateQualifiers
private Map<String,String> validateQualifiers(Map<String, String> values) throws MalformedPackageURLException- Throws:
MalformedPackageURLException
-
validateKey
- Throws:
MalformedPackageURLException
-
validatePath
- Throws:
MalformedPackageURLException
-
validatePath
private String validatePath(String[] segments, boolean isSubpath) throws MalformedPackageURLException - Throws:
MalformedPackageURLException
-
toString
Returns the canonicalized representation of the purl. -
canonicalize
Returns the canonicalized representation of the purl.- Returns:
- the canonicalized representation of the purl
- Since:
- 1.0.0
-
canonicalize
Returns the canonicalized representation of the purl.- Returns:
- the canonicalized representation of the purl
- Since:
- 1.3.2
-
percentEncode
Encodes the input in conformance with RFC 3986.- Parameters:
input- the String to encode- Returns:
- an encoded String
-
uriEncode
-
isUnreserved
private static boolean isUnreserved(int c) -
isAlpha
private static boolean isAlpha(int c) -
isDigit
private static boolean isDigit(int c) -
percentDecode
Optionally decodes a String, if it's encoded. If String is not encoded, method will return the original input value.- Parameters:
input- the value String to decode- Returns:
- a decoded String
-
uriDecode
-
parse
Given a specified PackageURL, this method will parse the purl and populate this classes instance fields so that the corresponding getters may be called to retrieve the individual pieces of the purl.- Parameters:
purl- the purl string to parse- Throws:
MalformedPackageURLException- if an exception occurs when parsing
-
verifyTypeConstraints
private void verifyTypeConstraints(String type, String namespace, String name) throws MalformedPackageURLException Some purl types may have specific constraints. This method attempts to verify them.- Parameters:
type- the purl typenamespace- the purl namespacename- the purl name- Throws:
MalformedPackageURLException- if constraints are not met
-
parseQualifiers
private Map<String,String> parseQualifiers(String encodedString) throws MalformedPackageURLException - Throws:
MalformedPackageURLException
-
parsePath
- Throws:
MalformedPackageURLException
-
encodePath
-
isBaseEquals
Deprecated.This method is no longer recommended and will be removed from a future release.Use
isCoordinatesEquals(com.github.packageurl.PackageURL)instead.Evaluates if the specified Package URL has the same values up to, but excluding the qualifier (querystring). This includes equivalence of: scheme, type, namespace, name, and version, but excludes qualifier and subpath from evaluation.- Parameters:
purl- the Package URL to evaluate- Returns:
- true if equivalence passes, false if not
- Since:
- 1.2.0
-
isCoordinatesEquals
Evaluates if the specified Package URL has the same values up to, but excluding the qualifier (querystring). This includes equivalence of: scheme, type, namespace, name, and version, but excludes qualifier and subpath from evaluation.- Parameters:
purl- the Package URL to evaluate- Returns:
- true if equivalence passes, false if not
- Since:
- 1.4.0
-
getCoordinates
Returns only the canonicalized coordinates of the Package URL which includes the type, namespace, name, and version, and which omits the qualifier and subpath.- Returns:
- A canonicalized PackageURL String excluding the qualifier and subpath.
- Since:
- 1.4.0
-
isCanonicalEquals
Evaluates if the specified Package URL has the same canonical value. This method canonicalizes the Package URLs being evaluated and performs an equivalence on the canonical values. Canonical equivalence is especially useful for qualifiers, which can be in any order, but have a predictable order in canonicalized form.- Parameters:
purl- the Package URL to evaluate- Returns:
- true if equivalence passes, false if not
- Since:
- 1.2.0
-
equals
-
hashCode
public int hashCode()
-