diff options
author | Susan Franklin | 2009-03-17 21:43:42 +0000 |
---|---|---|
committer | Susan Franklin | 2009-03-17 21:43:42 +0000 |
commit | a18fbddb9e1c32dcd4784bf19219df1d3c20430d (patch) | |
tree | 82bc436315a84bb11cfff9ef095409da03fc32a9 /examples | |
parent | 49f64c70a65f9f62f1880e2f5f3d814d1729b601 (diff) | |
download | rt.equinox.p2-a18fbddb9e1c32dcd4784bf19219df1d3c20430d.tar.gz rt.equinox.p2-a18fbddb9e1c32dcd4784bf19219df1d3c20430d.tar.xz rt.equinox.p2-a18fbddb9e1c32dcd4784bf19219df1d3c20430d.zip |
tutorial version
Diffstat (limited to 'examples')
7 files changed, 248 insertions, 198 deletions
diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.cloud/src/org/eclipse/equinox/p2/examples/rcp/cloud/Activator.java b/examples/org.eclipse.equinox.p2.examples.rcp.cloud/src/org/eclipse/equinox/p2/examples/rcp/cloud/Activator.java index 4d754b772..0d8532c29 100644 --- a/examples/org.eclipse.equinox.p2.examples.rcp.cloud/src/org/eclipse/equinox/p2/examples/rcp/cloud/Activator.java +++ b/examples/org.eclipse.equinox.p2.examples.rcp.cloud/src/org/eclipse/equinox/p2/examples/rcp/cloud/Activator.java @@ -1,20 +1,8 @@ package org.eclipse.equinox.p2.examples.rcp.cloud; -import java.net.URI; -import java.net.URISyntaxException; - -import org.eclipse.core.runtime.URIUtil; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; -import org.eclipse.equinox.internal.provisional.p2.ui.ProfileFactory; -import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; -import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningUtil; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.IProfileChooser; import org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.ui.statushandlers.StatusManager; import org.osgi.framework.BundleContext; /** @@ -76,12 +64,7 @@ public class Activator extends AbstractUIPlugin { private void initializeP2Policies() { Policy policy = Policy.getDefault(); - // XXX Where a profile must be chosen, use the running profile - policy.setProfileChooser(new IProfileChooser() { - public String getProfileId(Shell shell) { - return ProfileFactory.makeProfile("Canned").getProfileId(); - } - }); + // XXX User has no access to manipulate repositories policy.setRepositoryManipulator(null); } diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.cloud/src/org/eclipse/equinox/p2/examples/rcp/cloud/ApplicationActionBarAdvisor.java b/examples/org.eclipse.equinox.p2.examples.rcp.cloud/src/org/eclipse/equinox/p2/examples/rcp/cloud/ApplicationActionBarAdvisor.java index 91a0fdb00..8064f403c 100644 --- a/examples/org.eclipse.equinox.p2.examples.rcp.cloud/src/org/eclipse/equinox/p2/examples/rcp/cloud/ApplicationActionBarAdvisor.java +++ b/examples/org.eclipse.equinox.p2.examples.rcp.cloud/src/org/eclipse/equinox/p2/examples/rcp/cloud/ApplicationActionBarAdvisor.java @@ -91,6 +91,7 @@ public class ApplicationActionBarAdvisor extends ActionBarAdvisor { // XXX add preferences to tools toolsMenu.add(preferencesAction); + // XXX add a group for new other tools contributions toolsMenu.add(new Separator()); toolsMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Activator.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Activator.java index 1a8dd9585..c08b4d7aa 100644 --- a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Activator.java +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Activator.java @@ -2,7 +2,10 @@ package org.eclipse.equinox.p2.examples.rcp.prestartupdate; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.PackageAdmin; /** * The activator class controls the plug-in life cycle @@ -18,6 +21,10 @@ public class Activator extends AbstractUIPlugin { // XXX Shared instance of bundle context static BundleContext bundleContext; + // XXX services for starting bundles + private static PackageAdmin packageAdmin = null; + private static ServiceReference packageAdminRef = null; + /** * The constructor */ @@ -32,6 +39,31 @@ public class Activator extends AbstractUIPlugin { super.start(context); plugin = this; bundleContext = context; + + packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName()); + packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef); + + // XXX start up the p2 infrastructure. Normally the p2 UI does + // this, but we are running without UI. + getBundle("org.eclipse.equinox.p2.exemplarysetup").start(Bundle.START_TRANSIENT); //$NON-NLS-1$ + getBundle("org.eclipse.equinox.frameworkadmin.equinox").start(Bundle.START_TRANSIENT); //$NON-NLS-1$ + getBundle("org.eclipse.equinox.simpleconfigurator.manipulator").start(Bundle.START_TRANSIENT); //$NON-NLS-1$ + + } + + private static Bundle getBundle(String symbolicName) { + if (packageAdmin == null) + return null; + Bundle[] bundles = packageAdmin.getBundles(symbolicName, null); + if (bundles == null) + return null; + // Return the first bundle that is not installed or uninstalled + for (int i = 0; i < bundles.length; i++) { + if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) { + return bundles[i]; + } + } + return null; } /* diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Application.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Application.java index 9eb2e7283..0f180eee9 100644 --- a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Application.java +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/Application.java @@ -1,68 +1,31 @@ package org.eclipse.equinox.p2.examples.rcp.prestartupdate; -import java.lang.reflect.InvocationTargetException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SubMonitor; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.director.IPlanner; -import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest; -import org.eclipse.equinox.internal.provisional.p2.director.ProvisioningPlan; -import org.eclipse.equinox.internal.provisional.p2.engine.DefaultPhaseSet; -import org.eclipse.equinox.internal.provisional.p2.engine.IEngine; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; -import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningContext; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.query.Collector; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.statushandlers.StatusManager; /** * This class controls all aspects of the application's execution */ public class Application implements IApplication { - - /* - * (non-Javadoc) - * - * @seeorg.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app. - * IApplicationContext) + + /* (non-Javadoc) + * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) */ public Object start(IApplicationContext context) { Display display = PlatformUI.createDisplay(); try { - // XXX check for updates before ever running a workbench - if (checkForUpdates(display)) - // An update was done, we need to restart + int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); + if (returnCode == PlatformUI.RETURN_RESTART) { return IApplication.EXIT_RESTART; - else { - int returnCode = PlatformUI.createAndRunWorkbench(display, - new ApplicationWorkbenchAdvisor()); - if (returnCode == PlatformUI.RETURN_RESTART) { - return IApplication.EXIT_RESTART; - } } return IApplication.EXIT_OK; } finally { display.dispose(); } } - /* * (non-Javadoc) * @@ -81,132 +44,5 @@ public class Application implements IApplication { }); } - // XXX Check for updates to this application and return true if - // we have installed updates and need a restart. - // This method is intentionally long and ugly in order to provide - // "one-stop-shopping" for how to check for and perform an update. - private boolean checkForUpdates(Display display) { - // Before we show a progress dialog, at least find out that we have - // installed content and repos to check. - final IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper - .getService(Activator.bundleContext, IProfileRegistry.class - .getName()); - if (profileRegistry == null) - return false; - final IProfile profile = profileRegistry - .getProfile(IProfileRegistry.SELF); - if (profile == null) - return false; - - // We are going to look for updates to all IU's in the profile. A - // different query could be used if we are looking for updates to - // a subset. For example, the p2 UI only looks for updates to those - // IU's marked with a special property. - final Collector collector = profile.query(InstallableUnitQuery.ANY, - new Collector(), null); - if (collector.isEmpty()) - return false; - final IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper - .getService(Activator.bundleContext, - IMetadataRepositoryManager.class.getName()); - if (manager == null) - return false; - final URI[] reposToSearch = manager - .getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); - if (reposToSearch.length == 0) - return false; - final IPlanner planner = (IPlanner) ServiceHelper.getService( - Activator.bundleContext, IPlanner.class.getName()); - if (planner == null) - return false; - // Looking in all known repositories for updates for each IU in the profile - final boolean[] didWeUpdate = new boolean[1]; - didWeUpdate[0] = false; - IRunnableWithProgress runnable = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - SubMonitor sub = SubMonitor.convert(monitor, - "Checking for application updates...", 200 + (collector - .size() * 100)); - // First we look for replacement IU's for each IU - ArrayList iusWithUpdates = new ArrayList(); - ArrayList replacementIUs = new ArrayList(); - Iterator iter = collector.iterator(); - ProvisioningContext pc = new ProvisioningContext(reposToSearch); - while (iter.hasNext()) { - if (sub.isCanceled()) - throw new InterruptedException(); - IInstallableUnit iu = (IInstallableUnit) iter.next(); - IInstallableUnit[] replacements = planner.updatesFor(iu, - pc, sub.newChild(100)); - if (replacements.length > 0) { - iusWithUpdates.add(iu); - if (replacements.length == 1) - replacementIUs.add(replacements[0]); - else { - IInstallableUnit repl = replacements[0]; - for (int i = 1; i < replacements.length; i++) - if (replacements[i].getVersion().compareTo( - repl.getVersion()) > 0) - repl = replacements[i]; - replacementIUs.add(repl); - } - } - } - // Did we find any updates? - if (iusWithUpdates.size() == 0) { - sub.done(); - } else { - if (sub.isCanceled()) - throw new InterruptedException(); - // Build a profile change request - ProfileChangeRequest changeRequest = new ProfileChangeRequest( - profile); - changeRequest - .removeInstallableUnits((IInstallableUnit[]) iusWithUpdates - .toArray(new IInstallableUnit[iusWithUpdates - .size()])); - changeRequest - .addInstallableUnits((IInstallableUnit[]) iusWithUpdates - .toArray(new IInstallableUnit[iusWithUpdates - .size()])); - ProvisioningPlan plan = planner.getProvisioningPlan( - changeRequest, pc, sub.newChild(100)); - if (plan.getStatus().getSeverity() == IStatus.CANCEL) - throw new InterruptedException(); - if (plan.getStatus().getSeverity() != IStatus.ERROR) { - IEngine engine = (IEngine) ServiceHelper.getService( - Activator.bundleContext, IEngine.class - .getName()); - IArtifactRepositoryManager artifactMgr = (IArtifactRepositoryManager) ServiceHelper - .getService(Activator.bundleContext, - IArtifactRepositoryManager.class - .getName()); - if (engine != null && artifactMgr != null) { - pc - .setArtifactRepositories(artifactMgr - .getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)); - IStatus status = engine.perform(profile, - new DefaultPhaseSet(), plan.getOperands(), - pc, sub.newChild(100)); - if (status.getSeverity() == IStatus.CANCEL) - throw new InterruptedException(); - if (status.getSeverity() != IStatus.ERROR) { - didWeUpdate[0] = true; - } - } - } - } - } - }; - try { - new ProgressMonitorDialog(null).run(true, true, runnable); - } catch (InvocationTargetException e) { - e.printStackTrace(); - return false; - } catch (InterruptedException e) { - return false; - } - return didWeUpdate[0]; - } + } diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java index d27729b67..a3e5d6b05 100644 --- a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java @@ -1,5 +1,6 @@ package org.eclipse.equinox.p2.examples.rcp.prestartupdate; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.application.WorkbenchWindowAdvisor; @@ -9,11 +10,20 @@ import org.eclipse.ui.application.WorkbenchWindowAdvisor; * the perspective id for the initial window. */ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { - + public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { return new ApplicationWorkbenchWindowAdvisor(configurer); } - + + /* + * (non-Javadoc) + * @see org.eclipse.ui.application.WorkbenchAdvisor#preStartup() + */ + public void preStartup() { + if (P2Util.checkForUpdates()) + PlatformUI.getWorkbench().restart(); + } + public String getInitialWindowPerspectiveId() { return Perspective.ID; } diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/P2Util.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/P2Util.java new file mode 100644 index 000000000..d5df937b2 --- /dev/null +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/P2Util.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.equinox.p2.examples.rcp.prestartupdate; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Iterator; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; +import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.director.IPlanner; +import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest; +import org.eclipse.equinox.internal.provisional.p2.director.ProvisioningPlan; +import org.eclipse.equinox.internal.provisional.p2.engine.DefaultPhaseSet; +import org.eclipse.equinox.internal.provisional.p2.engine.IEngine; +import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; +import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; +import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningContext; +import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.query.Collector; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; + +public class P2Util { + // XXX Check for updates to this application and return true if + // we have installed updates and need a restart. + // This method is intentionally long and ugly in order to provide + // "one-stop-shopping" for how to check for and perform an update. + static boolean checkForUpdates() { + // Before we show a progress dialog, at least find out that we have + // installed content and repos to check. + final IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper + .getService(Activator.bundleContext, IProfileRegistry.class + .getName()); + if (profileRegistry == null) + return false; + final IProfile profile = profileRegistry + .getProfile(IProfileRegistry.SELF); + if (profile == null) + return false; + + // We are going to look for updates to all IU's in the profile. A + // different query could be used if we are looking for updates to + // a subset. For example, the p2 UI only looks for updates to those + // IU's marked with a special property. + final Collector collector = profile.query(InstallableUnitQuery.ANY, + new Collector(), null); + if (collector.isEmpty()) + return false; + final IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper + .getService(Activator.bundleContext, + IMetadataRepositoryManager.class.getName()); + if (manager == null) + return false; + final URI[] reposToSearch = manager + .getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL); + if (reposToSearch.length == 0) + return false; + final IPlanner planner = (IPlanner) ServiceHelper.getService( + Activator.bundleContext, IPlanner.class.getName()); + if (planner == null) + return false; + // Looking in all known repositories for updates for each IU in the profile + final boolean[] didWeUpdate = new boolean[1]; + didWeUpdate[0] = false; + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + // We'll break progress up into 4 steps. + // 1. Load repos - it is not strictly necessary to do this. + // The planner will do it for us. However, burying this + // in the planner's progress reporting will not + // show enough progress initially, so we do it manually. + // 2. Get update list + // 3. Build a profile change request and get a provisioning plan + // 4. Perform the provisioning plan. + SubMonitor sub = SubMonitor.convert(monitor, + "Checking for application updates...", 400); + // 1. Load repos + SubMonitor loadMonitor = sub.newChild(100); + for (int i=0; i<reposToSearch.length; i++) + try { + if (loadMonitor.isCanceled()) + throw new InterruptedException(); + manager.loadRepository(reposToSearch[i], loadMonitor.newChild(100/reposToSearch.length)); + } catch (ProvisionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + loadMonitor.done(); + + // 2. Get update list. + // First we look for replacement IU's for each IU + ArrayList iusWithUpdates = new ArrayList(); + ArrayList replacementIUs = new ArrayList(); + Iterator iter = collector.iterator(); + ProvisioningContext pc = new ProvisioningContext(reposToSearch); + SubMonitor updateSearchMonitor = sub.newChild(100); + while (iter.hasNext()) { + if (updateSearchMonitor.isCanceled()) + throw new InterruptedException(); + IInstallableUnit iu = (IInstallableUnit) iter.next(); + IInstallableUnit[] replacements = planner.updatesFor(iu, + pc, updateSearchMonitor.newChild(100/collector.size())); + if (replacements.length > 0) { + iusWithUpdates.add(iu); + if (replacements.length == 1) + replacementIUs.add(replacements[0]); + else { + IInstallableUnit repl = replacements[0]; + for (int i = 1; i < replacements.length; i++) + if (replacements[i].getVersion().compareTo( + repl.getVersion()) > 0) + repl = replacements[i]; + replacementIUs.add(repl); + } + } + } + // Did we find any updates? + if (iusWithUpdates.size() == 0) { + sub.done(); + } else { + if (sub.isCanceled()) + throw new InterruptedException(); + // 3. Build a profile change request and get a provisioning plan + ProfileChangeRequest changeRequest = new ProfileChangeRequest( + profile); + changeRequest + .removeInstallableUnits((IInstallableUnit[]) iusWithUpdates + .toArray(new IInstallableUnit[iusWithUpdates + .size()])); + changeRequest + .addInstallableUnits((IInstallableUnit[]) iusWithUpdates + .toArray(new IInstallableUnit[iusWithUpdates + .size()])); + ProvisioningPlan plan = planner.getProvisioningPlan( + changeRequest, pc, sub.newChild(100)); + if (plan.getStatus().getSeverity() == IStatus.CANCEL) + throw new InterruptedException(); + if (plan.getStatus().getSeverity() != IStatus.ERROR) { + IEngine engine = (IEngine) ServiceHelper.getService( + Activator.bundleContext, IEngine.class + .getName()); + IArtifactRepositoryManager artifactMgr = (IArtifactRepositoryManager) ServiceHelper + .getService(Activator.bundleContext, + IArtifactRepositoryManager.class + .getName()); + if (engine != null && artifactMgr != null) { + // 4. Perform the provisioning plan + pc + .setArtifactRepositories(artifactMgr + .getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)); + IStatus status = engine.perform(profile, + new DefaultPhaseSet(), plan.getOperands(), + pc, sub.newChild(100)); + if (status.getSeverity() == IStatus.CANCEL) + throw new InterruptedException(); + if (status.getSeverity() != IStatus.ERROR) { + didWeUpdate[0] = true; + } + } + } + } + } + }; + try { + new ProgressMonitorDialog(null).run(true, true, runnable); + } catch (InvocationTargetException e) { + e.printStackTrace(); + return false; + } catch (InterruptedException e) { + return false; + } + return didWeUpdate[0]; + } +} diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.sdkbundlevisibility/src/org/eclipse/equinox/p2/examples/rcp/sdkbundlevisibility/Activator.java b/examples/org.eclipse.equinox.p2.examples.rcp.sdkbundlevisibility/src/org/eclipse/equinox/p2/examples/rcp/sdkbundlevisibility/Activator.java index b1325f9c2..9d400e3ef 100644 --- a/examples/org.eclipse.equinox.p2.examples.rcp.sdkbundlevisibility/src/org/eclipse/equinox/p2/examples/rcp/sdkbundlevisibility/Activator.java +++ b/examples/org.eclipse.equinox.p2.examples.rcp.sdkbundlevisibility/src/org/eclipse/equinox/p2/examples/rcp/sdkbundlevisibility/Activator.java @@ -40,20 +40,15 @@ public class Activator extends AbstractUIPlugin { private void initializeP2Policies() { Policy policy = Policy.getDefault(); - // XXX Where a profile must be chosen, use the running profile - policy.setProfileChooser(new IProfileChooser() { - public String getProfileId(Shell shell) { - return ProfileFactory.makeProfile("Canned").getProfileId(); - } - }); // XXX Use the pref-based repository manipulator policy.setRepositoryManipulator(new ColocatedRepositoryManipulator(policy, PreferenceConstants.PREF_PAGE_SITES)); - // XXX Change the visibility of the IUs shown in the UI + // XXX Change the visibility of the IUs shown in the UI. + // Using a null property for visibility means everything will be shown, not just + // groups (features). IUViewQueryContext context = policy.getQueryContext(); context.setVisibleAvailableIUProperty(null); context.setVisibleInstalledIUProperty(null); - } /* |