From 94499e6c787fb885e14803e218cba9921f4d53d2 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sun, 24 Sep 2023 00:08:26 +0200 Subject: [PATCH] Assemble repository for all environments at once --- .../p2tools/MirrorApplicationServiceImpl.java | 41 ++++++++--------- .../tycho/p2tools/TychoMirrorApplication.java | 28 +++++++++--- .../copiedfromp2/MirrorApplication.java | 44 +++++++++++++------ 3 files changed, 71 insertions(+), 42 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java index cc249ffaf9..f54ca5fae2 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java @@ -51,7 +51,6 @@ import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.tycho.ArtifactType; import org.eclipse.tycho.BuildDirectory; -import org.eclipse.tycho.TargetEnvironment; import org.eclipse.tycho.core.resolver.shared.DependencySeed; import org.eclipse.tycho.core.shared.StatusTool; import org.eclipse.tycho.p2.repository.GAV; @@ -164,28 +163,24 @@ public void mirrorReactor(RepositoryReferences sources, DestinationRepositoryDes mirrorApp.setIncludeRequiredFeatures(includeRequiredFeatures); mirrorApp.setIncludePacked(false); // no way, Tycho do no longer support packed artifacts anyways mirrorApp.setFilterProvided(filterProvided); - // TODO the p2 mirror tool should support mirroring multiple environments at once - for (TargetEnvironment environment : context.getEnvironments()) { - SlicingOptions options = new SlicingOptions(); - options.considerStrictDependencyOnly(!includeAllDependencies); - Map filter = options.getFilter(); - addFilterForFeatureJARs(filter); - if (filterProperties != null) { - filter.putAll(filterProperties); - } - filter.putAll(environment.toFilterProperties()); - mirrorApp.setSlicingOptions(options); - - try { - LogListener logListener = new LogListener(logger); - mirrorApp.setLog(logListener); - - IStatus returnStatus = mirrorApp.run(null); - checkStatus(returnStatus, false); - logListener.showHelpForLoggedMessages(); - } catch (ProvisionException e) { - throw new FacadeException(MIRROR_FAILURE_MESSAGE + ": " + StatusTool.collectProblems(e.getStatus()), e); - } + mirrorApp.setEnvironments(context.getEnvironments()); + SlicingOptions options = new SlicingOptions(); + options.considerStrictDependencyOnly(!includeAllDependencies); + Map filter = options.getFilter(); + addFilterForFeatureJARs(filter); + if (filterProperties != null) { + filter.putAll(filterProperties); + } + mirrorApp.setSlicingOptions(options); + try { + LogListener logListener = new LogListener(logger); + mirrorApp.setLog(logListener); + + IStatus returnStatus = mirrorApp.run(null); + checkStatus(returnStatus, false); + logListener.showHelpForLoggedMessages(); + } catch (ProvisionException e) { + throw new FacadeException(MIRROR_FAILURE_MESSAGE + ": " + StatusTool.collectProblems(e.getStatus()), e); } recreateArtifactRepository(destination); } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java index 78e8d2a996..de5b861d8b 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java @@ -18,6 +18,7 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -29,6 +30,7 @@ import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; import org.eclipse.equinox.internal.p2.director.Slicer; import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability; +import org.eclipse.equinox.internal.p2.metadata.InstallableUnit; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; @@ -82,13 +84,19 @@ protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, @Override protected Slicer createSlicer(SlicingOptions options) { - Map context = options.getFilter(); boolean includeOptionalDependencies = options.includeOptionalDependencies(); boolean onlyFilteredRequirements = options.followOnlyFilteredRequirements(); - boolean considerFilter = context != null && context.size() > 1; + List selectionContexts = environments.stream().map(env -> { + Map context = new HashMap<>(options.getFilter()); + context.putAll(env.toFilterProperties()); + return context; + }).map(InstallableUnit::contextIU).toList(); + boolean considerFilter = selectionContexts.stream().anyMatch(c -> c.getProperties().size() > 1); + boolean evalFilterTo = options.forceFilterTo(); + IMetadataRepository repository = getCompositeMetadataRepository(); - return new PermissiveSlicer(repository, context, includeOptionalDependencies, options.isEverythingGreedy(), - options.forceFilterTo(), options.considerStrictDependencyOnly(), onlyFilteredRequirements) { + return new PermissiveSlicer(repository, Map.of(), includeOptionalDependencies, options.isEverythingGreedy(), + evalFilterTo, options.considerStrictDependencyOnly(), onlyFilteredRequirements) { @Override protected boolean isApplicable(IInstallableUnit iu, IRequirement req) { if ((includeRequiredBundles || includeRequiredFeatures) && QueryUtil.isGroup(iu) @@ -103,12 +111,22 @@ protected boolean isApplicable(IInstallableUnit iu, IRequirement req) { if (onlyFilteredRequirements && filter == null) { return false; } - return !considerFilter || filter == null || filter.isMatch(selectionContext); + return !considerFilter || filter == null + || selectionContexts.stream().anyMatch(filter::isMatch); } } return super.isApplicable(req); } + @Override + protected boolean isApplicable(IInstallableUnit iu) { + if (considerFilter) { + IMatchExpression filter = iu.getFilter(); + return filter == null || selectionContexts.stream().anyMatch(filter::isMatch); + } + return iu.getFilter() == null || evalFilterTo; + } + @Override protected boolean isApplicable(IRequirement req) { throw new UnsupportedOperationException("should never be called!"); diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java index 25a7e45579..8e8cd613eb 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java @@ -5,6 +5,7 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -52,6 +53,7 @@ import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.osgi.util.NLS; +import org.eclipse.tycho.TargetEnvironment; public class MirrorApplication extends AbstractApplication implements IApplication, IExecutableExtension { private static final String DEFAULT_COMPARATOR = ArtifactChecksumComparator.COMPARATOR_ID + ".sha-256"; //$NON-NLS-1$ @@ -59,6 +61,7 @@ public class MirrorApplication extends AbstractApplication implements IApplicati private static final String MIRROR_MODE = "metadataOrArtifacts"; //$NON-NLS-1$ protected SlicingOptions slicingOptions = new SlicingOptions(); + protected List environments = new ArrayList<>(); private URI baseline; private String comparatorID; @@ -396,23 +399,32 @@ private IArtifactMirrorLog getLog(File location, String root) { return new FileMirrorLog(absolutePath, 0, root); } + @SuppressWarnings("unchecked") + private static final IQueryable[] EMPTY = new IQueryable[0]; + private IQueryable performResolution(IProgressMonitor monitor) throws ProvisionException { IProfileRegistry registry = getProfileRegistry(); String profileId = "MirrorApplication-" + System.currentTimeMillis(); //$NON-NLS-1$ - IProfile profile = registry.addProfile(profileId, slicingOptions.getFilter()); - IPlanner planner = agent.getService(IPlanner.class); - if (planner == null) - throw new IllegalStateException(); - IProfileChangeRequest pcr = planner.createChangeRequest(profile); - pcr.addAll(sourceIUs); - IProvisioningPlan plan = planner.getProvisioningPlan(pcr, null, monitor); - registry.removeProfile(profileId); - @SuppressWarnings("unchecked") - IQueryable[] arr = new IQueryable[plan.getInstallerPlan() == null ? 1 : 2]; - arr[0] = plan.getAdditions(); - if (plan.getInstallerPlan() != null) - arr[1] = plan.getInstallerPlan().getAdditions(); - return new CompoundQueryable<>(arr); + List> queryables = new ArrayList<>(); + for (TargetEnvironment environment : environments) { + Map filter = new HashMap<>(slicingOptions.getFilter()); + filter.putAll(environment.toFilterProperties()); + IProfile profile = registry.addProfile(profileId, filter); + IPlanner planner = agent.getService(IPlanner.class); + if (planner == null) { + throw new IllegalStateException(); + } + IProfileChangeRequest pcr = planner.createChangeRequest(profile); + pcr.addAll(sourceIUs); + IProvisioningPlan plan = planner.getProvisioningPlan(pcr, null, monitor); + registry.removeProfile(profileId); + queryables.add(plan.getAdditions()); + IProvisioningPlan installerPlan = plan.getInstallerPlan(); + if (installerPlan != null) { + queryables.add(installerPlan.getAdditions()); + } + } + return new CompoundQueryable<>(queryables.toArray(EMPTY)); } private IProfileRegistry getProfileRegistry() throws ProvisionException { @@ -452,6 +464,10 @@ protected Slicer createSlicer(SlicingOptions options) { return slicer; } + public void setEnvironments(List environments) { + this.environments = environments; + } + public void setSlicingOptions(SlicingOptions options) { slicingOptions = options; }