Skip to content
Merged
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
20 changes: 19 additions & 1 deletion src/main/java/com/github/packageurl/PackageURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,25 @@ public PackageURL(final String type, final String namespace, final String name,
}

/**
* The PackageURL scheme constant.
* Constructs a new PackageURL object.
*
* @param type the type of package (i.e. maven, npm, gem, etc)
* @param namespace the name prefix (i.e. group, owner, organization)
* @param name the name of the package
* @param version the version of the package
* @param qualifiers an array of key/value pair qualifiers
* @param subpath the subpath string
* @throws MalformedPackageURLException if parsing fails
* @since 1.6.0
*/
public PackageURL(final String type, final String namespace, final String name, final String version,
final Map<String, String> qualifiers, final String subpath)
throws MalformedPackageURLException {
this(type, namespace, name, version, (qualifiers != null) ? new TreeMap<>(qualifiers) : null, subpath);
}

/**
* The PackageURL scheme constant
*/
public static final String SCHEME = "pkg";

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/github/packageurl/PackageURLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Locale;
import java.util.TreeMap;

Expand Down Expand Up @@ -138,14 +140,18 @@ public void testConstructorParameters() throws MalformedPackageURLException {
final String subpath = testDefinition.optString("subpath", null);

TreeMap<String, String> map = null;
Map<String, String> hashMap = null;
if (qualifiers != null) {
map = qualifiers.toMap().entrySet().stream().collect(
TreeMap<String, String>::new,
(qmap, entry) -> qmap.put(entry.getKey(), (String) entry.getValue()),
TreeMap<String, String>::putAll
);
hashMap = new HashMap<>(map);
}



if (invalid) {
try {
PackageURL purl = new PackageURL(type, namespace, name, version, map, subpath);
Expand Down Expand Up @@ -173,6 +179,8 @@ public void testConstructorParameters() throws MalformedPackageURLException {
Assert.assertTrue(purl.getQualifiers().containsKey(key));
Assert.assertEquals(value, purl.getQualifiers().get(key));
});
PackageURL purl2 = new PackageURL(type, namespace, name, version, hashMap, subpath);
Assert.assertEquals(purl.getQualifiers(), purl2.getQualifiers());
}
}
}
Expand Down