Skip to content

Commit

Permalink
Extend the copied MirrorApplication and apply some patches
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 26, 2023
1 parent 00e9fa4 commit 0710ad2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<String, String> extraArtifactRepositoryProperties;
Expand All @@ -62,8 +55,7 @@ public class MirrorApplication extends org.eclipse.equinox.p2.internal.repositor

public MirrorApplication(IProvisioningAgent agent, Map<String, String> extraArtifactRepositoryProperties,
List<RepositoryReference> repositoryReferences) {
super();
this.agent = agent;
super(agent);
this.extraArtifactRepositoryProperties = extraArtifactRepositoryProperties;
this.repositoryReferences = repositoryReferences;
this.removeAddedRepositories = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<IProvisioningAgent> 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<IProvisioningAgentProvider> 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<IInstallableUnit> ius) {
sourceIUs = ius;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -369,10 +365,10 @@ private IArtifactMirrorLog getLog(File location, String root) {
}

private IQueryable<IInstallableUnit> 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);
Expand All @@ -387,6 +383,13 @@ private IQueryable<IInstallableUnit> 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<IInstallableUnit> slice(IProgressMonitor monitor) throws ProvisionException {
if (slicingOptions == null)
slicingOptions = new SlicingOptions();
Expand Down

0 comments on commit 0710ad2

Please sign in to comment.