Search in sources :

Example 1 with IProvisioningAgent

use of org.eclipse.equinox.p2.core.IProvisioningAgent in project translationstudio8 by heartsome.

the class PreloadingRepositoryHandler method execute.

/**
	 * Execute the command.
	 */
public Object execute(ExecutionEvent event) {
    // Look for a profile. We may not immediately need it in the
    // handler, but if we don't have one, whatever we are trying to do
    // will ultimately fail in a more subtle/low-level way. So determine
    // up front if the system is configured properly.
    String profileId = getProvisioningUI().getProfileId();
    IProvisioningAgent agent = getProvisioningUI().getSession().getProvisioningAgent();
    IProfile profile = null;
    if (agent != null) {
        IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
        if (registry != null) {
            profile = registry.getProfile(profileId);
        }
    }
    if (profile == null) {
        // Inform the user nicely
        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_CHECK);
        return null;
    } else {
        BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

            public void run() {
                doExecuteAndLoad();
            }
        });
    }
    return null;
}
Also used : IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IProfile(org.eclipse.equinox.p2.engine.IProfile)

Example 2 with IProvisioningAgent

use of org.eclipse.equinox.p2.core.IProvisioningAgent in project translationstudio8 by heartsome.

the class Activator method loadUpdateSite.

private void loadUpdateSite() throws InvocationTargetException {
    // get the agent
    final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(Activator.bundleContext, IProvisioningAgent.SERVICE_NAME);
    // get the repository managers and define our repositories
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
        logger.error("When load repository,Metadata manager was null");
        return;
    }
    // Load artifact manager
    IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
    if (artifactManager == null) {
        logger.error("When load repository,Artifact manager was null");
        return;
    }
    // Load repository
    try {
        String url = getUrlString();
        if (url == null) {
            return;
        }
        URI repoLocation = new URI(url);
        URI[] ex = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
        for (URI e : ex) {
            manager.removeRepository(e);
            artifactManager.removeRepository(e);
        }
        manager.addRepository(repoLocation);
        artifactManager.addRepository(repoLocation);
    } catch (URISyntaxException e) {
        logger.error("Caught URI syntax exception " + e.getMessage(), e);
        throw new InvocationTargetException(e);
    }
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IArtifactRepositoryManager(org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with IProvisioningAgent

use of org.eclipse.equinox.p2.core.IProvisioningAgent in project translationstudio8 by heartsome.

the class AutomaticUpdate method checkForUpdates.

public void checkForUpdates() throws OperationCanceledException {
    // 检查 propfile
    String profileId = getProvisioningUI().getProfileId();
    IProvisioningAgent agent = getProvisioningUI().getSession().getProvisioningAgent();
    IProfile profile = null;
    if (agent != null) {
        IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
        if (registry != null) {
            profile = registry.getProfile(profileId);
        }
    }
    if (profile == null) {
        // Inform the user nicely
        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
        return;
    }
    // 开始检查前先确定是否有repository
    RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
    if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
        return;
    }
    final IStatus[] checkStatus = new IStatus[1];
    Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
    final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI()) {

        public IStatus runModal(IProgressMonitor monitor) {
            SubMonitor sub = SubMonitor.convert(monitor, P2UpdateUtil.CHECK_UPDATE_TASK_NAME, 1000);
            // load repository
            IStatus status = super.runModal(sub.newChild(500));
            if (status.getSeverity() == IStatus.CANCEL) {
                return status;
            }
            if (status.getSeverity() != Status.OK) {
                // load repository error
                checkStatus[0] = status;
            }
            operation = getProvisioningUI().getUpdateOperation(null, null);
            // check for updates
            IStatus resolveStatus = operation.resolveModal(sub.newChild(500));
            if (resolveStatus.getSeverity() == IStatus.CANCEL) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    loadJob.setName(P2UpdateUtil.ATUO_CHECK_UPDATE_JOB_NAME);
    loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
    loadJob.addJobChangeListener(new JobChangeAdapter() {

        public void done(IJobChangeEvent event) {
            if (PlatformUI.isWorkbenchRunning())
                if (event.getResult().isOK()) {
                    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                        public void run() {
                            if (checkStatus[0] != null) {
                                // 提示连接异常
                                P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
                                return;
                            }
                            doUpdate();
                        }
                    });
                }
        }
    });
    loadJob.setUser(true);
    loadJob.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) SubMonitor(org.eclipse.core.runtime.SubMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IProfile(org.eclipse.equinox.p2.engine.IProfile) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Aggregations

IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)3 IProfile (org.eclipse.equinox.p2.engine.IProfile)2 IProfileRegistry (org.eclipse.equinox.p2.engine.IProfileRegistry)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 RepositoryTracker (org.eclipse.equinox.p2.operations.RepositoryTracker)1 IArtifactRepositoryManager (org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager)1 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)1 LoadMetadataRepositoryJob (org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)1