diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplication.java index 10b4edaf6c..9805906fbb 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplication.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 SAP SE and others. + * Copyright (c) 2010, 2023 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,13 +13,11 @@ package org.eclipse.tycho.p2tools; import java.net.URI; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; import java.util.stream.Stream; import org.eclipse.core.runtime.IProgressMonitor; @@ -31,12 +29,7 @@ import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; import org.eclipse.equinox.p2.internal.repository.tools.SlicingOptions; import org.eclipse.equinox.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.p2.metadata.IProvidedCapability; import org.eclipse.equinox.p2.metadata.IRequirement; -import org.eclipse.equinox.p2.metadata.MetadataFactory; -import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription; -import org.eclipse.equinox.p2.metadata.Version; -import org.eclipse.equinox.p2.metadata.VersionRange; import org.eclipse.equinox.p2.metadata.expression.IMatchExpression; import org.eclipse.equinox.p2.query.CollectionResult; import org.eclipse.equinox.p2.query.IQueryable; @@ -50,7 +43,7 @@ import org.eclipse.tycho.TargetPlatform; import org.eclipse.tycho.p2.tools.RepositoryReference; -public class MirrorApplication extends org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication { +public class MirrorApplication extends org.eclipse.tycho.p2tools.copiedfromp2.MirrorApplication { private static final String SOURCE_SUFFIX = ".source"; private final Map extraArtifactRepositoryProperties; @@ -62,8 +55,7 @@ public class MirrorApplication extends org.eclipse.equinox.p2.internal.repositor public MirrorApplication(IProvisioningAgent agent, Map extraArtifactRepositoryProperties, List repositoryReferences) { - super(); - this.agent = agent; + super(agent); this.extraArtifactRepositoryProperties = extraArtifactRepositoryProperties; this.repositoryReferences = repositoryReferences; this.removeAddedRepositories = false; diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/AbstractApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/AbstractApplication.java index 2b050f011d..c30544d512 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/AbstractApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/AbstractApplication.java @@ -22,11 +22,9 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; -import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; import org.eclipse.equinox.p2.core.IProvisioningAgent; -import org.eclipse.equinox.p2.core.IProvisioningAgentProvider; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.internal.repository.tools.Messages; import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; @@ -39,8 +37,6 @@ import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.osgi.util.NLS; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; public abstract class AbstractApplication { protected boolean removeAddedRepositories = true; @@ -59,45 +55,10 @@ public abstract class AbstractApplication { protected IProvisioningAgent agent; - public AbstractApplication() { - super(); - try { - setupAgent(); - } catch (ProvisionException e) { - LogHelper.log(e); - } - } - public AbstractApplication(IProvisioningAgent agent) { this.agent = agent; } - private void setupAgent() throws ProvisionException { - // note if we ever wanted these applications to act on a different agent than - // the currently running system we would need to set it here - BundleContext bundleContext = Activator.getBundleContext(); - if (bundleContext == null) { - return; - } - ServiceReference agentRef = bundleContext.getServiceReference(IProvisioningAgent.class); - if (agentRef != null) { - agent = bundleContext.getService(agentRef); - if (agent != null) - return; - } - // there is no agent around so we need to create one - ServiceReference providerRef = bundleContext - .getServiceReference(IProvisioningAgentProvider.class); - if (providerRef == null) - throw new RuntimeException("No provisioning agent provider is available"); //$NON-NLS-1$ - IProvisioningAgentProvider provider = bundleContext.getService(providerRef); - if (provider == null) - throw new RuntimeException("No provisioning agent provider is available"); //$NON-NLS-1$ - // obtain agent for currently running system - agent = provider.createAgent(null); - bundleContext.ungetService(providerRef); - } - public void setSourceIUs(List ius) { sourceIUs = ius; } 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 dd4d0e89bd..d7a896576c 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 @@ -77,10 +77,6 @@ public class MirrorApplication extends AbstractApplication implements IApplicati private IArtifactMirrorLog mirrorLog; private IArtifactMirrorLog comparatorLog; - public MirrorApplication() { - super(); - } - public MirrorApplication(IProvisioningAgent agent) { super(agent); } @@ -369,10 +365,10 @@ private IArtifactMirrorLog getLog(File location, String root) { } private IQueryable performResolution(IProgressMonitor monitor) throws ProvisionException { - IProfileRegistry registry = Activator.getProfileRegistry(); + IProfileRegistry registry = getProfileRegistry(); String profileId = "MirrorApplication-" + System.currentTimeMillis(); //$NON-NLS-1$ IProfile profile = registry.addProfile(profileId, slicingOptions.getFilter()); - IPlanner planner = Activator.getAgent().getService(IPlanner.class); + IPlanner planner = agent.getService(IPlanner.class); if (planner == null) throw new IllegalStateException(); IProfileChangeRequest pcr = planner.createChangeRequest(profile); @@ -387,6 +383,13 @@ private IQueryable performResolution(IProgressMonitor monitor) return new CompoundQueryable<>(arr); } + private IProfileRegistry getProfileRegistry() throws ProvisionException { + IProfileRegistry registry = agent.getService(IProfileRegistry.class); + if (registry == null) + throw new ProvisionException(Messages.no_profile_registry); + return registry; + } + private IQueryable slice(IProgressMonitor monitor) throws ProvisionException { if (slicingOptions == null) slicingOptions = new SlicingOptions();