【问题标题】:Update Eclipse E4 application using p2使用 p2 更新 Eclipse E4 应用程序
【发布时间】:2017-04-15 20:15:28
【问题描述】:

我正在我的 Eclipse E4 应用程序中添加更新功能。为此,我使用了来自 Lars Vogel 的源代码和 tutorial。当我测试我的应用程序时,provisioningJob 始终为空。仅当它运行到 Eclipse 时才应为 null。但是当我尝试更新我导出的应用程序时,provisioningJob 仍然为空。我做错了什么?

public class UpdateHandler {

private static final String REPOSITORY_LOC = System.getProperty("UpdateHandler.Repo",
        "file:////updateServer/repository");

@Execute
public void execute(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
        final IWorkbench workbench) {
    Job updateJob = new Job("Update Job") {
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            return checkForUpdates(agent, shell, sync, workbench, monitor);
        }
    };
    updateJob.schedule();
}

private IStatus checkForUpdates(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
        final IWorkbench workbench, IProgressMonitor monitor) {

    // configure update operation
    final ProvisioningSession session = new ProvisioningSession(agent);
    final UpdateOperation operation = new UpdateOperation(session);
    configureUpdate(operation);

    // check for updates, this causes I/O
    final IStatus status = operation.resolveModal(monitor);

    // failed to find updates (inform user and exit)
    if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
        LogModule.log(LogLevel.INFO, "No updated has been found");
        showMessage(shell, sync);
        return Status.CANCEL_STATUS;
    }
    else
    {
        LogModule.log(LogLevel.INFO, "Updates are found");
    }

    // run installation
    final ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);

    // updates cannot run from within Eclipse IDE!!!
    if (provisioningJob == null) {
        System.err.println("Trying to update from the Eclipse IDE? This won't work!");
        LogModule.log(LogLevel.WARNING, "Trying to update from the Eclipse IDE? This won't work!");
        return Status.CANCEL_STATUS;
    }
    configureProvisioningJob(provisioningJob, shell, sync, workbench);

    //provisioningJob.schedule();
    provisioningJob.run(monitor);
    return Status.OK_STATUS;

}

private void configureProvisioningJob(ProvisioningJob provisioningJob, final Shell shell, final UISynchronize sync,
        final IWorkbench workbench) {

    // register a job change listener to track
    // installation progress and notify user upon success
    provisioningJob.addJobChangeListener(new JobChangeAdapter() {
        @Override
        public void done(IJobChangeEvent event) {
            //if (event.getResult().isOK()) {
                sync.syncExec(new Runnable() {

                    @Override
                    public void run() {

                        LogModule.log(LogLevel.INFO, "Update ready to install");

                        boolean restart = MessageDialog.openQuestion(shell, "Updates installed, restart?",
                                "Updates have been installed. Do you want to restart?");
                        if (restart) {
                            workbench.restart();
                        }
                    }
                });

        //  }
            super.done(event);
        }
    });

}

private void showMessage(final Shell parent, final UISynchronize sync) {
    sync.syncExec(new Runnable() {

        @Override
        public void run() {
            MessageDialog.openWarning(parent, "No update",
                    "No updates for the current installation have been found.");
        }
    });
}

private UpdateOperation configureUpdate(final UpdateOperation operation) {
    // create uri and check for validity
    URI uri = null;
    try {
        uri = new URI(REPOSITORY_LOC);
    } catch (final URISyntaxException e) {
        System.err.println(e.getMessage());
        LogModule.log(LogLevel.ERROR, e.getMessage());
        return null;
    }

    // set location of artifact and metadata repo
    operation.getProvisioningContext().setArtifactRepositories(new URI[] { uri });
    operation.getProvisioningContext().setMetadataRepositories(new URI[] { uri });
    return operation;
}

}

【问题讨论】:

  • 你的问题呢?我遇到了同样的问题。代码跑到这个分支: if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
  • 我不再看那个了。完成这项工作的努力太高了。我们正在为在 Inno 设置中创建的应用程序使用外部更新程序。

标签: java eclipse-rcp updates e4 p2


【解决方案1】:

P2 在内部使用了很多服务,而这些服务并未明确引用为捆绑依赖项。因此,您可能会错过那些额外的必需服务。通过 PDE 启动中的“添加所需...”添加它们不起作用。 确保您的 Launch 或 Product 确实包含所有要求。我将从 org.eclipse.equinox.p2.sdk 的内容开始。这绝对应该有效。之后,您可以尝试将要求降低到 org.eclipse.equinox.p2.core.feature 甚至更少。

【讨论】:

  • 我没有 org.eclipse.equinox.p2.sdk。我只能找到org.eclipse.equinox.p2.ui.sdk。
  • 你使用Eclipse Target吗?如果是这样,那么您应该可以从更新站点http://download.eclipse.org/releases/neon/ 中选择 IU 功能 org.eclipse.equinox.p2.sdk(.feature.group) 或名称“Equinox p2, SDK” 确保取消选择“按类别分组项目”以查看 IU 名称和不仅是 p2 类别。
猜你喜欢
  • 2018-06-17
  • 1970-01-01
  • 2012-01-11
  • 1970-01-01
  • 2011-04-24
  • 2014-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多