Skip to content

Commit

Permalink
Calculate BOM representation for each IU only once
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptziegler committed Jun 1, 2024
1 parent f4e7ede commit df5fb19
Showing 1 changed file with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class TychoProjectDependenciesConverter extends DefaultProjectDependencie
@Inject
private MavenProjectDependencyProcessor dependencyProcessor;

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

@Override
public void cleanupBomDependencies(Metadata metadata, Map<String, Component> components,
Map<String, Dependency> dependencies) {
Expand Down Expand Up @@ -117,35 +120,37 @@ private void convertToDependency(DependencyTreeNode node, Set<Dependency> depend
private List<String> getBomRepresentation(IInstallableUnit iu) {
final MavenSession mavenSession = legacySupport.getSession();
final List<MavenProject> reactorProjects = mavenSession.getAllProjects();
// mutable!
List<String> bomRefs = new ArrayList<>();
// (I) IU describes local reactor project
try {
ProjectDependencyClosure dependencyClosure = dependencyProcessor
.computeProjectDependencyClosure(reactorProjects, mavenSession);
MavenProject iuProject = dependencyClosure.getProject(iu).orElse(null);
if (iuProject != null) {
String bomRef = modelConverter.generatePackageUrl(iuProject.getArtifact());
if (bomRef == null) {
LOG.error("Unable to calculate BOM for: " + iuProject);
return bomRepresentations.computeIfAbsent(iu, ignore -> {
// mutable!
List<String> bomRefs = new ArrayList<>();
// (I) IU describes local reactor project
try {
ProjectDependencyClosure dependencyClosure = dependencyProcessor
.computeProjectDependencyClosure(reactorProjects, mavenSession);
MavenProject iuProject = dependencyClosure.getProject(iu).orElse(null);
if (iuProject != null) {
String bomRef = modelConverter.generatePackageUrl(iuProject.getArtifact());
if (bomRef == null) {
LOG.error("Unable to calculate BOM for: " + iuProject);
return bomRefs;
}
bomRefs.add(bomRef);
return bomRefs;
}
bomRefs.add(bomRef);
return bomRefs;
} catch (CoreException e) {
LOG.error(e.getMessage(), e);
return Collections.emptyList();
}
} catch (CoreException e) {
LOG.error(e.getMessage(), e);
return Collections.emptyList();
}
// (II) IU describes external artifact
for (IArtifactKey p2artifactKey : iu.getArtifacts()) {
String bomRef = modelConverter.generateP2PackageUrl(p2artifactKey, true, true, false);
if (bomRef == null) {
LOG.error("Unable to calculate BOM for: " + p2artifactKey);
continue;
// (II) IU describes external artifact
for (IArtifactKey p2artifactKey : iu.getArtifacts()) {
String bomRef = modelConverter.generateP2PackageUrl(p2artifactKey, true, true, false);
if (bomRef == null) {
LOG.error("Unable to calculate BOM for: " + p2artifactKey);
continue;
}
bomRefs.add(bomRef);
}
bomRefs.add(bomRef);
}
return bomRefs; // mutable!
return bomRefs; // mutable!
});
}
}

0 comments on commit df5fb19

Please sign in to comment.