Skip to content

Commit

Permalink
avoid duplication descriptors in PlatformImportsImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
cdsap committed Nov 6, 2024
1 parent fcc7889 commit a3ff2d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a3ff2d3

Please sign in to comment.