From a3ff2d32a67a5d05eb6f9215b0ad442537a86275 Mon Sep 17 00:00:00 2001 From: Inaki Villar Date: Sun, 27 Oct 2024 19:44:00 -0700 Subject: [PATCH] avoid duplication descriptors in PlatformImportsImpl --- .../bootstrap/model/PlatformImportsImpl.java | 39 +++++++++++-------- .../bootstrap/model/PlatformImportsTest.java | 8 ++++ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/PlatformImportsImpl.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/PlatformImportsImpl.java index 1b747cb158390..b332eb3e72bff 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/PlatformImportsImpl.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/PlatformImportsImpl.java @@ -81,8 +81,10 @@ public void addPlatformDescriptor(String groupId, String artifactId, String clas artifactId.substring(0, artifactId.length() - BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX.length()), version); - platformImports.computeIfAbsent(bomCoords, c -> new PlatformImport()).descriptorFound = true; - platformBoms.add(bomCoords); + platformImports.computeIfAbsent(bomCoords, c -> { + platformBoms.add(bomCoords); + return new PlatformImport(); + }).descriptorFound = true; } public void addPlatformProperties(String groupId, String artifactId, String classifier, String type, String version, @@ -92,21 +94,24 @@ public void addPlatformProperties(String groupId, String artifactId, String clas artifactId.length() - BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX.length()), version); platformImports.computeIfAbsent(bomCoords, c -> new PlatformImport()); - importedPlatformBoms.computeIfAbsent(groupId, g -> new ArrayList<>()).add(bomCoords); - - final Properties props = new Properties(); - try (InputStream is = Files.newInputStream(propsPath)) { - props.load(is); - } catch (IOException e) { - throw new AppModelResolverException("Failed to read properties from " + propsPath, e); - } - for (Map.Entry prop : props.entrySet()) { - final String name = String.valueOf(prop.getKey()); - if (name.startsWith(BootstrapConstants.PLATFORM_PROPERTY_PREFIX)) { - if (isPlatformReleaseInfo(name)) { - addPlatformRelease(name, String.valueOf(prop.getValue())); - } else { - collectedProps.putIfAbsent(name, String.valueOf(prop.getValue().toString())); + importedPlatformBoms.computeIfAbsent(groupId, g -> new ArrayList<>()); + if (!importedPlatformBoms.get(groupId).contains(bomCoords)) { + importedPlatformBoms.get(groupId).add(bomCoords); + + final Properties props = new Properties(); + try (InputStream is = Files.newInputStream(propsPath)) { + props.load(is); + } catch (IOException e) { + throw new AppModelResolverException("Failed to read properties from " + propsPath, e); + } + for (Map.Entry prop : props.entrySet()) { + final String name = String.valueOf(prop.getKey()); + if (name.startsWith(BootstrapConstants.PLATFORM_PROPERTY_PREFIX)) { + if (isPlatformReleaseInfo(name)) { + addPlatformRelease(name, String.valueOf(prop.getValue())); + } else { + collectedProps.putIfAbsent(name, String.valueOf(prop.getValue().toString())); + } } } } diff --git a/independent-projects/bootstrap/app-model/src/test/java/io/quarkus/bootstrap/model/PlatformImportsTest.java b/independent-projects/bootstrap/app-model/src/test/java/io/quarkus/bootstrap/model/PlatformImportsTest.java index 56106751314b2..1a0e70abcbe7d 100644 --- a/independent-projects/bootstrap/app-model/src/test/java/io/quarkus/bootstrap/model/PlatformImportsTest.java +++ b/independent-projects/bootstrap/app-model/src/test/java/io/quarkus/bootstrap/model/PlatformImportsTest.java @@ -114,6 +114,14 @@ public void multiplePlatformReleaseInTheSameStream() throws Exception { GACTV.fromString("io.playground:acme-bom::pom:2.2.2"))))); } + @Test + public void duplicatePlatformDescriptorsAreIgnored() { + final PlatformImportsImpl pi = new PlatformImportsImpl(); + pi.addPlatformDescriptor("io.playground", "acme-bom-quarkus-platform-descriptor", "", "", "1.1"); + pi.addPlatformDescriptor("io.playground", "acme-bom-quarkus-platform-descriptor", "", "", "1.1"); + assertEquals(1, pi.getImportedPlatformBoms().size()); + } + private PlatformProps newPlatformProps() throws IOException { final PlatformProps p = new PlatformProps(); platformProps.add(p);