簡體   English   中英

NullPointerException在創建ProvisioningJob以進行無頭更新Eclipse RCP應用程序時

[英]NullPointerException in creating ProvisioningJob for headless update of eclipse rcp application

我正在實施eclipse應用程序的無用力更新。 我已經從https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fp2_startup.htm使用P2Util類,但是我的代碼在以下位置返回了空指針異常ProvisioningJob job = operation.getProvisioningJob(null); 作業對象即將null 有誰知道這個空對象的可能原因。

public class P2Util {
    // 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() == UpdateOperation.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));//null pointer here
            if (status.getSeverity() == IStatus.CANCEL)
                throw new OperationCanceledException();
        }
        return status;
    }
}

我稱這種方法如下。

private Integer checkUpdate(final String updateServerURL, final IProvisioningAgent provisioningAgent, ProgressMonitorSplash monitor) {
    returnValue = IApplication.EXIT_OK;

    final IRunnableWithProgress runnable = new IRunnableWithProgress() {
        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            P2Util.addRepository(provisioningAgent, updateServerURL);
            final IStatus updateStatus = P2Util.checkForUpdates(provisioningAgent, monitor);
            if (updateStatus.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
                logger.debug("No Updates");
            } else if (updateStatus.getSeverity() != IStatus.ERROR) {
                logger.debug("Updates applied, attempting restart");
                returnValue = IApplication.EXIT_RESTART;
            } else {
                logger.error(updateStatus.getMessage());
            }
        }
    };
    try {
        monitor.run(true, runnable);
    } catch (final InvocationTargetException e) {
        e.printStackTrace();
    } catch (final InterruptedException e) {
        logger.error("interrupted: " + e.getMessage());
    }
    return returnValue;
}

我在哪里使用EclipseContext創建ProvisingAgent

            final IEclipseContext localContext = EclipseContextFactory.getServiceContext(Activator.getContext());
            final IProvisioningAgent provisioningAgent = getService(localContext, IProvisioningAgent.class);
            String env = System.getProperty("env").toLowerCase();
            String repo = System.getProperty("validUrl." + env);
            if ( repo == null ){
                repo = System.getProperty("validUrl");
            }
            if ( repo != null ){
                ret = checkUpdate(repo, provisioningAgent, sp);
                if ( ret == IApplication.EXIT_RESTART ){
                    logger.info("Update successful, restarting...");
                    return ret;
                }
            }

UpdateOperation#getProvisioningJob(IProgressMonitor)上的Javadoc說:

 * @return a job that can be used to perform the provisioning operation.  This may be <code>null</code> 
 * if the operation has not been resolved, or if a plan could not be obtained when attempting to
 * resolve.  If the job is null and the operation has been resolved, then the resolution result 
 * will explain the problem.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM