Skip to content

Commit

Permalink
Merge pull request #15622 from aloubyansky/platform-artifacts-util
Browse files Browse the repository at this point in the history
Helper class to translate platform BOM coordinates to the corresponding JSON catalog coordinates
  • Loading branch information
aloubyansky authored Mar 11, 2021
2 parents a8b2ddb + 4880187 commit 4e63ab1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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")));
}
}

0 comments on commit 4e63ab1

Please sign in to comment.