From 48801871ea73d7e89805f238e7b42304830e6aa7 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Thu, 11 Mar 2021 09:04:41 +0100 Subject: [PATCH] Helper class to translate platform BOM coordinates to the corresponding JSON catalog coordinates --- .../registry/util/PlatformArtifacts.java | 29 +++++++++++++ .../registry/util/PlatformArtifactsTest.java | 43 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java create mode 100644 independent-projects/tools/registry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java new file mode 100644 index 0000000000000..8a74dc99a288e --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java @@ -0,0 +1,29 @@ +package io.quarkus.registry.util; + +import io.quarkus.maven.ArtifactCoords; +import io.quarkus.registry.Constants; + +public class PlatformArtifacts { + + public static ArtifactCoords getCatalogArtifactForBom(ArtifactCoords bom) { + return getCatalogArtifactForBom(bom.getGroupId(), bom.getArtifactId(), bom.getVersion()); + } + + public static ArtifactCoords getCatalogArtifactForBom(String bomGroupId, String bomArtifactId, String bomVersion) { + return new ArtifactCoords(bomGroupId, bomArtifactId + Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX, bomVersion, + "json", bomVersion); + } + + public static ArtifactCoords ensureCatalogArtifact(ArtifactCoords coords) { + return isCatalogArtifact(coords) ? coords + : getCatalogArtifactForBom(coords.getGroupId(), coords.getArtifactId(), coords.getVersion()); + } + + public static boolean isCatalogArtifactId(String artifactId) { + return artifactId != null && artifactId.endsWith(Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX); + } + + public static boolean isCatalogArtifact(ArtifactCoords coords) { + return isCatalogArtifactId(coords.getArtifactId()); + } +} diff --git a/independent-projects/tools/registry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java b/independent-projects/tools/registry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java new file mode 100644 index 0000000000000..1dab2be6aec76 --- /dev/null +++ b/independent-projects/tools/registry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java @@ -0,0 +1,43 @@ +package io.quarkus.devtools.registry.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import io.quarkus.maven.ArtifactCoords; +import io.quarkus.registry.util.PlatformArtifacts; +import org.junit.jupiter.api.Test; + +public class PlatformArtifactsTest { + + @Test + public void getCatalogArtifactForBom() { + final ArtifactCoords catalog = new ArtifactCoords("org.acme", "acme-bom-quarkus-platform-descriptor", "1.0", "json", + "1.0"); + assertEquals(catalog, + PlatformArtifacts.getCatalogArtifactForBom(new ArtifactCoords("org.acme", "acme-bom", null, "pom", "1.0"))); + assertEquals(catalog, PlatformArtifacts.getCatalogArtifactForBom("org.acme", "acme-bom", "1.0")); + } + + @Test + public void ensureCatalogArtifact() { + final ArtifactCoords catalog = new ArtifactCoords("org.acme", "acme-bom-quarkus-platform-descriptor", "1.0", "json", + "1.0"); + assertEquals(catalog, PlatformArtifacts.ensureCatalogArtifact(catalog)); + assertEquals(catalog, + PlatformArtifacts.ensureCatalogArtifact(new ArtifactCoords("org.acme", "acme-bom", null, "pom", "1.0"))); + } + + @Test + public void isCatalogArtifactId() { + assertTrue(PlatformArtifacts.isCatalogArtifactId("acme-bom-quarkus-platform-descriptor")); + assertFalse(PlatformArtifacts.isCatalogArtifactId("acme-bom")); + } + + @Test + public void isCatalogArtifact() { + assertTrue(PlatformArtifacts.isCatalogArtifact( + new ArtifactCoords("org.acme", "acme-bom-quarkus-platform-descriptor", "1.0", "json", "1.0"))); + assertFalse(PlatformArtifacts.isCatalogArtifact(new ArtifactCoords("org.acme", "acme-bom", null, "pom", "1.0"))); + } +}