Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

feat(purl): add a purl to ArtifactCoordinates parser #292

Merged
merged 1 commit into from
Sep 19, 2019
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 @@ -10,6 +10,8 @@
*/
package org.eclipse.sw360.antenna.model.util;

import com.github.packageurl.MalformedPackageURLException;
import com.github.packageurl.PackageURL;
import org.eclipse.sw360.antenna.model.artifact.Artifact;
import org.eclipse.sw360.antenna.model.artifact.ArtifactFact;
import org.eclipse.sw360.antenna.model.artifact.facts.ArtifactCoordinates;
Expand Down Expand Up @@ -76,4 +78,29 @@ public static Optional<ArtifactCoordinates> getMostDominantArtifactCoordinates(
.map(fn -> new GenericArtifactCoordinates(fn, "-")),
artifact);
}

public static ArtifactCoordinates createArtifactCoordinates(PackageURL packageURL) {
String type = packageURL.getType();

switch (type) {
case "maven":
return new MavenCoordinates(packageURL.getName(), packageURL.getNamespace(), packageURL.getVersion());
case "npm":
return new JavaScriptCoordinates(packageURL.getName(), packageURL.getNamespace(), packageURL.getVersion());
blaumeiser-at-bosch marked this conversation as resolved.
Show resolved Hide resolved
case "nuget":
return new DotNetCoordinates(packageURL.getName(), packageURL.getVersion());
case "p2":
return new BundleCoordinates(packageURL.getName(), packageURL.getVersion());
default:
return new GenericArtifactCoordinates(packageURL.getName(), packageURL.getVersion());
}
}

public static ArtifactCoordinates createArtifactCoordinatesFromPurl(String packageUrl) {
try {
return createArtifactCoordinates(new PackageURL(packageUrl));
} catch (MalformedPackageURLException e) {
throw new IllegalArgumentException("Could not build PURL", e);
}
}
}