Search in sources :

Example 1 with RepositoryTracker

use of org.eclipse.equinox.p2.operations.RepositoryTracker in project cubrid-manager by CUBRID.

the class UpdateHandler method preloadRepositories.

/**
	 * Return whether to preload repositories
	 *
	 * @return boolean
	 */
protected boolean preloadRepositories() {
    isNoRepos = false;
    RepositoryTracker repoTracker = getProvisioningUI().getRepositoryTracker();
    if (repoTracker.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
        isNoRepos = true;
        return false;
    }
    return true;
}
Also used : RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Example 2 with RepositoryTracker

use of org.eclipse.equinox.p2.operations.RepositoryTracker in project knime-core by knime.

the class BugfixMessageInjector method checkNewMinorVersion.

private List<String> checkNewMinorVersion() throws IOException, URISyntaxException {
    final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
    RepositoryTracker tracker = provUI.getRepositoryTracker();
    if (tracker == null) {
        // if run from the IDE there will be no tracker
        return Collections.emptyList();
    }
    UpdateOperation op = new UpdateOperation(provUI.getSession());
    op.resolveModal(new NullProgressMonitor());
    return Stream.of(op.getPossibleUpdates()).map(u -> u.toUpdate.getProperty("org.eclipse.equinox.p2.name")).sorted().distinct().collect(Collectors.toList());
}
Also used : RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) TransformerException(javax.xml.transform.TransformerException) XPath(javax.xml.xpath.XPath) XPathConstants(javax.xml.xpath.XPathConstants) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) Collectors(java.util.stream.Collectors) File(java.io.File) XPathFactory(javax.xml.xpath.XPathFactory) List(java.util.List) Stream(java.util.stream.Stream) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Document(org.w3c.dom.Document) UpdateOperation(org.eclipse.equinox.p2.operations.UpdateOperation) SAXException(org.xml.sax.SAXException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Collections(java.util.Collections) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) UpdateOperation(org.eclipse.equinox.p2.operations.UpdateOperation) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Example 3 with RepositoryTracker

use of org.eclipse.equinox.p2.operations.RepositoryTracker in project epp.mpc by eclipse.

the class ProfileChangeOperationComputer method resolve.

private ProfileChangeOperation resolve(IProgressMonitor monitor, ProfileChangeOperationFactory operationFactory, IInstallableUnit[] ius, URI[] repositories) throws CoreException {
    List<IInstallableUnit> installableUnits = Arrays.asList(ius);
    List<ResolutionStrategy> strategies = new ArrayList<ProfileChangeOperationComputer.ResolutionStrategy>(2);
    switch(resolutionStrategy) {
        case FALLBACK_STRATEGY:
            strategies.add(ResolutionStrategy.SELECTED_REPOSITORIES);
            strategies.add(ResolutionStrategy.ALL_REPOSITORIES);
            break;
        default:
            strategies.add(resolutionStrategy);
    }
    ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
    RepositoryTracker repositoryTracker = ProvisioningUI.getDefaultUI().getRepositoryTracker();
    URI[] knownRepositories = repositoryTracker.getKnownRepositories(session);
    ProfileChangeOperation operation = null;
    final int workPerStrategy = 1000;
    SubMonitor subMonitor = SubMonitor.convert(monitor, strategies.size() * workPerStrategy + workPerStrategy);
    Set<URI> previousRepositoryLocations = null;
    for (ResolutionStrategy strategy : strategies) {
        Set<URI> repositoryLocations = new HashSet<URI>(Arrays.asList(repositories));
        if (strategy == ResolutionStrategy.SELECTED_REPOSITORIES) {
            repositoryLocations.addAll(Arrays.asList(repositories));
        }
        if (dependenciesRepository != null) {
            repositoryLocations.add(dependenciesRepository);
        }
        if (strategy == ResolutionStrategy.ALL_REPOSITORIES && !repositoryLocations.isEmpty()) {
            repositoryLocations.addAll(Arrays.asList(knownRepositories));
        }
        if (repositoryLocations.equals(previousRepositoryLocations)) {
            continue;
        }
        operation = operationFactory.create(installableUnits);
        if (!repositoryLocations.isEmpty()) {
            URI[] locations = repositoryLocations.toArray(new URI[repositoryLocations.size()]);
            operation.getProvisioningContext().setMetadataRepositories(locations);
            operation.getProvisioningContext().setArtifactRepositories(locations);
        }
        resolveModal(subMonitor.newChild(workPerStrategy), operation);
        if (operation.getResolutionResult() != null && operation.getResolutionResult().getSeverity() != IStatus.ERROR) {
            break;
        }
        previousRepositoryLocations = repositoryLocations;
    }
    return operation;
}
Also used : ProfileChangeOperation(org.eclipse.equinox.p2.operations.ProfileChangeOperation) ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) URI(java.net.URI) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker) HashSet(java.util.HashSet)

Example 4 with RepositoryTracker

use of org.eclipse.equinox.p2.operations.RepositoryTracker 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)

Example 5 with RepositoryTracker

use of org.eclipse.equinox.p2.operations.RepositoryTracker in project translationstudio8 by heartsome.

the class CheckUpdateHandler method preloadRepositories.

@Override
protected boolean preloadRepositories() {
    hasNoRepos = false;
    RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
    if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
        hasNoRepos = true;
        return false;
    }
    return super.preloadRepositories();
}
Also used : RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Aggregations

RepositoryTracker (org.eclipse.equinox.p2.operations.RepositoryTracker)12 URI (java.net.URI)7 ProvisioningSession (org.eclipse.equinox.p2.operations.ProvisioningSession)5 ArrayList (java.util.ArrayList)4 ProvisioningUI (org.eclipse.equinox.p2.ui.ProvisioningUI)4 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)2 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)2 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 Collections (java.util.Collections)1 List (java.util.List)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1