Skip to content

Commit

Permalink
Merge pull request #8 from ruromero/purl
Browse files Browse the repository at this point in the history
feat: include qualifiers in serialized purl
  • Loading branch information
zvigrinberg authored Dec 7, 2023
2 parents 528c747 + 7925b55 commit 4d4ddd9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/redhat/exhort/api/PackageRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public PackageURL purl() {
}

public String ref() {
return purl.getCoordinates();
return purl.toString();
}

public String name() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public PackageURLSerializer(Class<PackageURL> c) {
@Override
public void serialize(PackageURL value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
gen.writeString(value.getCoordinates());
gen.writeString(value.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.redhat.exhort.api.serialization;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.exhort.api.PackageRef;

public class PackageURLSerializerTest {

private ObjectMapper mapper = new ObjectMapper();

@Test
void testSerialize() throws JsonProcessingException {
var expected = "pkg:maven/io.quarkus/quarkus-resteasy-multipart@2.13.8.Final-redhat-00005?repository_url=https%3A%2F%2Fmaven.repository.redhat.com%2Fga%2F&type=jar";
var pkgRef = new PackageRef(expected);
assertEquals("jar", pkgRef.purl().getQualifiers().get("type"));
assertEquals("https://maven.repository.redhat.com/ga/", pkgRef.purl().getQualifiers().get("repository_url"));
assertEquals("\"" + expected + "\"", mapper.writeValueAsString(pkgRef));

var rpmPkg = "pkg:rpm/opensuse/curl@7.56.1-1.1.?arch=i386&distro=opensuse-tumbleweed";
pkgRef = new PackageRef(rpmPkg);
assertEquals("opensuse-tumbleweed", pkgRef.purl().getQualifiers().get("distro"));
assertEquals("i386", pkgRef.purl().getQualifiers().get("arch"));
assertEquals("\"" + rpmPkg + "\"", mapper.writeValueAsString(pkgRef));
}
}

0 comments on commit 4d4ddd9

Please sign in to comment.