使用p2更新Eclipse E4应用程序 [英] Update Eclipse E4 application using p2

查看:204
本文介绍了使用p2更新Eclipse E4应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm adding an update feature in my Eclipse E4 application. Herefor I used the source code and tutorial from Lars Vogel. When I test my application the provisioningJob is always null. It should only be null when it run into Eclipse. But when I try to update my exported application the provisioningJob is still null. What I'm doing wrong?

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

}

推荐答案

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

P2 uses internally a lot of services and those are not explicitly referenced as bundle dependencies. So you might miss those additional required services. Adding them via the "Add required ..." inside PDE launches is not working. Make sure that your Launch or Product is really including all requirements.I would start with the content of org.eclipse.equinox.p2.sdk. This should definitely work. Afterwards you can try to strip the requirements down to org.eclipse.equinox.p2.core.feature or even less.

这篇关于使用p2更新Eclipse E4应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆