diff --git a/tycho-sbom/src/main/java/org/eclipse/tycho/sbom/TychoProjectDependenciesConverter.java b/tycho-sbom/src/main/java/org/eclipse/tycho/sbom/TychoProjectDependenciesConverter.java index 28cd2c73ca..5b30ae970d 100644 --- a/tycho-sbom/src/main/java/org/eclipse/tycho/sbom/TychoProjectDependenciesConverter.java +++ b/tycho-sbom/src/main/java/org/eclipse/tycho/sbom/TychoProjectDependenciesConverter.java @@ -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; @@ -57,6 +58,8 @@ public class TychoProjectDependenciesConverter extends DefaultProjectDependencie @Inject private MavenProjectDependencyProcessor dependencyProcessor; + private final Map> bomRepresentations = new HashMap<>(); + @Override public void cleanupBomDependencies(Metadata metadata, Map components, Map dependencies) { @@ -117,35 +120,37 @@ private void convertToDependency(DependencyTreeNode node, Set depend private List getBomRepresentation(IInstallableUnit iu) { final MavenSession mavenSession = legacySupport.getSession(); final List reactorProjects = mavenSession.getAllProjects(); - // mutable! - List 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 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! + }); } }