From dfdd112e5c6c012dc32917ef692364a940c9fe3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 1 Jun 2024 09:42:06 +0200 Subject: [PATCH] Use initial metadata in P2DependencyTreeGenerator Currently P2DependencyTreeGenerator computes the "inital" units using the InstallableUnitGenerator, but that data is actually already available from the INITAL dependency metadata. (cherry picked from commit 5d13ab073c0017a7712f4401758e87c248114794) --- .../p2/tools/P2DependencyTreeGenerator.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/P2DependencyTreeGenerator.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/P2DependencyTreeGenerator.java index 0693ca4a18..3968d6f527 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/P2DependencyTreeGenerator.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/P2DependencyTreeGenerator.java @@ -14,6 +14,7 @@ package org.eclipse.tycho.p2.tools; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -36,10 +37,11 @@ import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.IRequirement; import org.eclipse.tycho.ArtifactDescriptor; +import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType; +import org.eclipse.tycho.ReactorProject; import org.eclipse.tycho.core.TychoProject; import org.eclipse.tycho.core.TychoProjectManager; import org.eclipse.tycho.core.osgitools.DefaultReactorProject; -import org.eclipse.tycho.p2maven.InstallableUnitGenerator; /** * Utility class for converting a flat dependency into a dependency tree. The tree is structured in @@ -52,14 +54,11 @@ */ @Component(role = P2DependencyTreeGenerator.class) public final class P2DependencyTreeGenerator { - private final InstallableUnitGenerator generator; private final TychoProjectManager projectManager; private final LegacySupport legacySupport; @Inject - public P2DependencyTreeGenerator(InstallableUnitGenerator generator, TychoProjectManager projectManager, - LegacySupport legacySupport) { - this.generator = generator; + public P2DependencyTreeGenerator(TychoProjectManager projectManager, LegacySupport legacySupport) { this.projectManager = projectManager; this.legacySupport = legacySupport; } @@ -73,7 +72,7 @@ public P2DependencyTreeGenerator(InstallableUnitGenerator generator, TychoProjec * One of the Maven projects of the current reactor build. If this project is not a * Tycho project (e.g. the parent pom), an empty list is returned. * @param unmapped - * A set containing all IUs which could not be added to the dependency tree.Meaning + * A set containing all IUs which could not be added to the dependency tree. Meaning * that those units are required by the project but not by any of its IUs. Must be * mutable. * @return as described. @@ -88,14 +87,14 @@ public List buildDependencyTree(MavenProject project, Set artifacts = tychoProject.get() // - .getDependencyArtifacts(DefaultReactorProject.adapt(project)) // + .getDependencyArtifacts(reactorProject) // .getArtifacts(); Set units = artifacts.stream() // .flatMap(d -> d.getInstallableUnits().stream()) // .collect(Collectors.toCollection(HashSet::new)); - List initial = List - .copyOf(generator.getInstallableUnits(project, legacySupport.getSession(), false)); + Set initial = reactorProject.getDependencyMetadata(DependencyMetadataType.INITIAL); units.removeAll(initial); return Collections.unmodifiableList(DependencyTreeNode.create(initial, units, unmapped)); @@ -156,14 +155,14 @@ public String toString() { * @return A list of dependency tree models. Each model in this list matches an IU of * {@code initial}. */ - private static List create(List initial, Set units, - Set unmapped) { + private static List create(Collection initial, + Set units, Set unmapped) { List rootNodes = new ArrayList<>(); - for (int i = 0; i < initial.size(); ++i) { - DependencyTreeNode rootNode = new DependencyTreeNode(initial.get(i), null); + initial.stream().sorted(COMPARATOR).forEach(iu -> { + DependencyTreeNode rootNode = new DependencyTreeNode(iu, null); create(rootNode, units); rootNodes.add(rootNode); - } + }); unmapped.addAll(units); return rootNodes; }