Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplication descriptors in PlatformImportsImpl #44147

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
aloubyansky marked this conversation as resolved.
Show resolved Hide resolved

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
Loading