-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15622 from aloubyansky/platform-artifacts-util
Helper class to translate platform BOM coordinates to the corresponding JSON catalog coordinates
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...jects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...egistry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); | ||
} | ||
} |