First, we had to obtain the P2 provisioning agent:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private IProvisioningAgent getProvisioingAgent() { | |
final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(FraudPlugin.bundleContext, | |
IProvisioningAgent.SERVICE_NAME); | |
if (agent == null) { | |
LogHelper.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, | |
"No provisioning agent found. This application is not set up for updates.")); | |
} | |
return agent; | |
} |
Once we have the provisioning agent, we can use it to get the metadata manager and artifact manager. You need both managers because the equinox provisioning systems allows for separate locations for each. Once we have the managers, we can simply add the URIs that we retrieved at run time via some external property file, database, preference store, etc.:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void addRuntimeP2Repository(IProgressMonitor monitor, ProvisioningSession session, URI runtimeRepoURI) throws ProvisionException, OperationCanceledException { | |
//Create Metadata repository manager and add the new repository location | |
IMetadataRepositoryManager metaDataRepoManager = ProvUI.getMetadataRepositoryManager(session); | |
metaDataRepoManager.loadRepository(runtimeRepoURI, monitor); | |
//Create artifact repository manager and add the new repository location | |
IArtifactRepositoryManager artifactDataRepoManager = ProvUI.getArtifactRepositoryManager(session); | |
artifactDataRepoManager.loadRepository(runtimeRepoURI, monitor); | |
} |
You'll need to be sure and add the following imports:
- import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
- import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
- import org.eclipse.equinox.internal.p2.ui.ProvUI;
- import org.eclipse.equinox.p2.core.IProvisioningAgent;
- import org.eclipse.equinox.p2.core.ProvisionException;
- import org.eclipse.equinox.p2.operations.ProvisioningJob;
- import org.eclipse.equinox.p2.operations.ProvisioningSession;
- import org.eclipse.equinox.p2.operations.UpdateOperation;
- import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
- import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
and you'll also need to make sure your plugin has the following dependencies:
- org.eclipse.equinox.p2.core
- org.eclipse.equinox.p2.operations
- org.eclipse.equinox.p2.metadata
- org.eclipse.equinox.p2.engine
- org.eclipse.equinox.p2.ui
- org.eclipse.equinox.p2.metadata.repository
- org.eclipse.equinox.p2.repository