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

Calculate BOM representation for each IU only once #3914

Merged
merged 1 commit into from
Jun 2, 2024

Conversation

ptziegler
Copy link
Contributor

The BOM representation is currently calculated twice for each artifact. Within a reactor build, such IUs should always produce the same BOM representation and should therefore be cached.

Resolves #3911

Copy link

github-actions bot commented Jun 1, 2024

Test Results

  594 files  ±0    594 suites  ±0   3h 52m 51s ⏱️ - 11m 56s
  424 tests ±0    417 ✅ ±0   7 💤 ±0  0 ❌ ±0 
1 272 runs  ±0  1 250 ✅ ±0  22 💤 ±0  0 ❌ ±0 

Results for commit 75105f5. ± Comparison against base commit a20b8bb.

♻️ This comment has been updated with latest results.

@@ -57,6 +58,8 @@ public class TychoProjectDependenciesConverter extends DefaultProjectDependencie
@Inject
private MavenProjectDependencyProcessor dependencyProcessor;

private final Map<IInstallableUnit, List<String>> bomRepresentations = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use a ConcurentHashMap to support parallel builds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fair point. I just double-checked and the map is indeed shared across the entire build.

bomRefs.add(bomRef);
}
return bomRefs; // mutable!
return bomRefs; // mutable!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The APi says the returned list is mutable, so either drop the mutability (and use a read-only list) or return a copy of the cached value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a few months, but I believe mutability was required in an earlier implementation because CycloneDX would add element to this list. But now it's only used within loops, so I think dropping this property is the best way to go.

@ptziegler ptziegler closed this Jun 1, 2024
@ptziegler ptziegler deleted the issue3911 branch June 1, 2024 13:17
@ptziegler ptziegler restored the issue3911 branch June 1, 2024 13:18
@ptziegler ptziegler reopened this Jun 1, 2024
@ptziegler
Copy link
Contributor Author

Apologies, I missclicked and deleted the branch by accident...

@laeubi
Copy link
Member

laeubi commented Jun 2, 2024

@ptziegler can you rebase / resolve conflict?

String bomRef = modelConverter.generatePackageUrl(project.getArtifact());
if (bomRef == null) {
LOG.error("Unable to calculate BOM for: " + project);
return List.copyOf(bomRefs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return List.copyOf(bomRefs);
return List.of();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never really liked List.copyOf() and instead I use Collections.emptyList() to make it clear that this is an empty list.

return List.copyOf(bomRefs);
}
bomRefs.add(bomRef);
return List.copyOf(bomRefs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return List.copyOf(bomRefs);
return List.of(bomRef);

Copy link
Contributor Author

@ptziegler ptziegler Jun 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't compile as bomRefs is already a list. But to avoid copying the array, I now use Collections.unmodifiableList(...)
It's just a single element, nevermind.

LOG.error("Unable to calculate BOM for: " + project);
return List.copyOf(bomRefs);
}
bomRefs.add(bomRef);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bomRefs.add(bomRef);

return bomRepresentations.computeIfAbsent(iu, ignore -> {
final MavenSession mavenSession = legacySupport.getSession();
final List<MavenProject> reactorProjects = mavenSession.getAllProjects();
final List<String> bomRefs = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final List<String> bomRefs = new ArrayList<>();

The BOM representation is currently calculated twice for each artifact.
Within a reactor build, such IUs should always produce the same BOM
representation and should therefore be cached.

Resolves eclipse-tycho#3911
@laeubi laeubi added the backport-to-tycho-4.0.x Can be added to a PR to trigger an automatic backport of the change label Jun 2, 2024
@laeubi laeubi merged commit 065819f into eclipse-tycho:main Jun 2, 2024
12 checks passed
@eclipse-tycho-bot
Copy link

💚 All backports created successfully

Status Branch Result
tycho-4.0.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-tycho-4.0.x Can be added to a PR to trigger an automatic backport of the change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[sbom] BOM is calculated multiple times for the same unit
3 participants