diff options
author | Susan Franklin | 2010-01-28 18:32:42 +0000 |
---|---|---|
committer | Susan Franklin | 2010-01-28 18:32:42 +0000 |
commit | afccd658b377db3b7fd69b44c0063ebd1e8e01bc (patch) | |
tree | 0d8581b5096878f9c7f6e2610be1ecd5de53c6e0 /examples | |
parent | 43dab0f1fca2349e8598c7732399a8cb35554a90 (diff) | |
download | rt.equinox.p2-afccd658b377db3b7fd69b44c0063ebd1e8e01bc.tar.gz rt.equinox.p2-afccd658b377db3b7fd69b44c0063ebd1e8e01bc.tar.xz rt.equinox.p2-afccd658b377db3b7fd69b44c0063ebd1e8e01bc.zip |
move service acquisition outside of P2Util
Diffstat (limited to 'examples')
2 files changed, 39 insertions, 18 deletions
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 2ebb4ff39..7fcbdac50 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 @@ -3,6 +3,14 @@ package org.eclipse.equinox.p2.examples.rcp.prestartupdate; import java.lang.reflect.InvocationTargetException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.operations.ProvisioningSession; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.ui.PlatformUI; @@ -27,14 +35,31 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { * @see org.eclipse.ui.application.WorkbenchAdvisor#preStartup() */ public void preStartup() { + final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper + .getService(Activator.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.")); + } + // XXX check for updates before starting up. - // If an update is performed, restart. - + // If an update is performed, restart. Otherwise log + // the status. IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - if (P2Util.checkForUpdates(monitor)) + IStatus updateStatus = P2Util.checkForUpdates(agent, monitor); + if (updateStatus.getCode() == ProvisioningSession.STATUS_NOTHING_TO_UPDATE) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + MessageDialog.openInformation(null, "Updates", "No updates were found"); + } + }); + } + if (updateStatus.getSeverity() != IStatus.ERROR) PlatformUI.getWorkbench().restart(); + else + LogHelper.log(updateStatus); } }; try { @@ -42,7 +67,7 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { - } + } } public String getInitialWindowPerspectiveId() { 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 index 404e33eb8..17aa000c6 100644 --- 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 @@ -15,42 +15,38 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.operations.ProvisioningJob; import org.eclipse.equinox.p2.operations.ProvisioningSession; import org.eclipse.equinox.p2.operations.UpdateOperation; public class P2Util { - // XXX Check for updates to this application and return true if - // we have installed updates and need a restart. - static boolean checkForUpdates(IProgressMonitor monitor) { - IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper - .getService(Activator.bundleContext, - IProvisioningAgent.SERVICE_NAME); - if (agent == null) - return false; + // XXX Check for updates to this application and return a status. + static IStatus checkForUpdates(IProvisioningAgent agent, IProgressMonitor monitor) throws OperationCanceledException { ProvisioningSession session = new ProvisioningSession(agent); // the default update operation looks for updates to the currently // running profile, using the default profile root marker. To change // which installable units are being updated, use the more detailed // constructors. UpdateOperation operation = new UpdateOperation(session); - SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200); IStatus status = operation.resolveModal(sub.newChild(100)); + if (status.getCode() == ProvisioningSession.STATUS_NOTHING_TO_UPDATE) { + return status; + } if (status.getSeverity() == IStatus.CANCEL) throw new OperationCanceledException(); + if (status.getSeverity() != IStatus.ERROR) { + // More complex status handling might include showing the user what updates + // are available if there are multiples, differentiating patches vs. updates, etc. + // In this example, we simply update as suggested by the operation. ProvisioningJob job = operation.getProvisioningJob(null); status = job.runModal(sub.newChild(100)); if (status.getSeverity() == IStatus.CANCEL) throw new OperationCanceledException(); - if (status.getSeverity() != IStatus.ERROR) { - return true; - } } - return false; + return status; } } |