Reputation: 113
I have some problems with P2's autoupdate, when I do locally, from a local repository all work fine and I can do my autoupdates at restart but when I try to update from a web repo I have these errors:
An internal error occurred during: "Install download0".
org.eclipse.swt.SWTException: Invalid thread access
Really, I don't understand what the difference is. In my ApplicationWindowWorkbenchAdvisor I have this post window open method:
private static final String JUSTUPDATED = "justUpdated";
public void postWindowOpen() {
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."));
}
final IPreferenceStore prefStore = Activator.getDefault()
.getPreferenceStore();
if (prefStore.getBoolean(JUSTUPDATED)) {
prefStore.setValue(JUSTUPDATED, false);
return;
}
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
IStatus updateStatus = P2Util.checkForUpdates(agent, monitor);
if (updateStatus.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
PlatformUI.getWorkbench().getDisplay()
.asyncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(null,
"Updates", "No updates were found");
}
});
} else if (updateStatus.getSeverity() != IStatus.ERROR) {
prefStore.setValue(JUSTUPDATED, true);
PlatformUI.getWorkbench().restart();
} else {
LogHelper.log(updateStatus);
}
}
};
try {
new ProgressMonitorDialog(null).run(true, true, runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
}
}
And in my P2Util this:
public static IStatus checkForUpdates(IProvisioningAgent agent,
IProgressMonitor monitor) {
ProvisioningSession session = new ProvisioningSession(agent);
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() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
return status;
}
if (status.getSeverity() == IStatus.CANCEL)
throw new OperationCanceledException();
if (status.getSeverity() != IStatus.ERROR) {
ProvisioningJob job = operation.getProvisioningJob(null);
status = job.runModal(sub.newChild(100));
if (status.getSeverity() == IStatus.CANCEL)
throw new OperationCanceledException();
}
return status;
}
In my PreferenceInitializer this:
node.putBoolean(PreferenceConstants.PREF_AUTO_UPDATE_ENABLED, true);
node.putBoolean(PreferenceConstants.PREF_AUTO_UPDATE_SCHEDULE, true);
node.putBoolean(PreferenceConstants.PREF_DOWNLOAD_ONLY, true);
I repeat myself: from local repo I can perform autoupdates but from web repo I can't. Thank for reading.
Upvotes: 3
Views: 723
Reputation: 9535
the problematic code is
new ProgressMonitorDialog(null).run(true, true, runnable);
this is called outside the ui-thread which throws the error...you have to wrap this also in a asyncExec Call
Upvotes: 4