gpt4 book ai didi

eclipse - P2 从网络存储库自动更新

转载 作者:行者123 更新时间:2023-12-01 09:24:30 30 4
gpt4 key购买 nike

我在 P2 的自动更新方面遇到了一些问题,当我在本地从本地存储库更新时,一切正常,我可以在重新启动时进行自动更新,但是当我尝试从网络存储库更新时,我遇到了这些错误:

An internal error occurred during: "Install download0".
org.eclipse.swt.SWTException: Invalid thread access

真的,我不明白有什么区别。在我的 ApplicationWindowWorkbenchAdvisor 中,我有这个后窗口打开方法:

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) {
}

}

在我的 P2Util 中:

    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;
}

在我的 PreferenceInitializer 中:

node.putBoolean(PreferenceConstants.PREF_AUTO_UPDATE_ENABLED, true);
node.putBoolean(PreferenceConstants.PREF_AUTO_UPDATE_SCHEDULE, true);
node.putBoolean(PreferenceConstants.PREF_DOWNLOAD_ONLY, true);

我再说一遍:我可以从本地存储库执行自动更新,但不能从网络存储库执行。感谢阅读。

最佳答案

有问题的代码是

new ProgressMonitorDialog(null).run(true, true, runnable);

这是在 ui-thread 之外调用的,它会抛出错误...您还必须将其包装在 asyncExec 调用中

关于eclipse - P2 从网络存储库自动更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9599471/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com