Search in sources :

Example 26 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project epp.mpc by eclipse.

the class MarketplaceCatalog method checkForUpdates.

protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
    Map<URI, List<MarketplaceNodeCatalogItem>> installedCatalogItemsByUpdateUri = new HashMap<URI, List<MarketplaceNodeCatalogItem>>();
    for (MarketplaceNodeCatalogItem catalogItem : updateCheckNeeded) {
        INode node = catalogItem.getData();
        String updateurl = node.getUpdateurl();
        try {
            if (updateurl == null) {
                catalogItem.setAvailable(false);
                continue;
            }
            URI uri = new URI(updateurl);
            List<MarketplaceNodeCatalogItem> catalogItemsThisSite = installedCatalogItemsByUpdateUri.get(uri);
            if (catalogItemsThisSite == null) {
                catalogItemsThisSite = new ArrayList<MarketplaceNodeCatalogItem>();
                installedCatalogItemsByUpdateUri.put(uri, catalogItemsThisSite);
            }
            catalogItemsThisSite.add(catalogItem);
        } catch (URISyntaxException e) {
            MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceCatalog_InvalidRepositoryUrl, node.getName(), updateurl);
            catalogItem.setAvailable(false);
        }
    }
    if (installedCatalogItemsByUpdateUri.isEmpty()) {
        return Status.OK_STATUS;
    }
    ConcurrentTaskManager executor = new ConcurrentTaskManager(installedCatalogItemsByUpdateUri.size(), Messages.MarketplaceCatalog_checkingForUpdates);
    try {
        final IProgressMonitor pm = new NullProgressMonitor() {

            @Override
            public boolean isCanceled() {
                return super.isCanceled() || monitor.isCanceled();
            }
        };
        for (Map.Entry<URI, List<MarketplaceNodeCatalogItem>> entry : installedCatalogItemsByUpdateUri.entrySet()) {
            final URI uri = entry.getKey();
            final List<MarketplaceNodeCatalogItem> catalogItemsThisSite = entry.getValue();
            executor.submit(new Runnable() {

                public void run() {
                    ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
                    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
                    try {
                        for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
                            if (Boolean.TRUE.equals(item.getAvailable())) {
                                item.setAvailable(null);
                            }
                        }
                        IMetadataRepository repository = manager.loadRepository(uri, pm);
                        IQuery<IInstallableUnit> query = // 
                        QueryUtil.createMatchQuery(// $NON-NLS-1$
                        "id ~= /*.feature.group/ && " + // $NON-NLS-1$
                        "properties['org.eclipse.equinox.p2.type.group'] == true ");
                        IQueryResult<IInstallableUnit> result = repository.query(query, pm);
                        // compute highest version for all available IUs.
                        Map<String, Version> repositoryIuVersionById = new HashMap<String, Version>();
                        for (IInstallableUnit iu : result) {
                            String key = createRepositoryIuKey(uri.toString(), iu.getId());
                            Version version = iu.getVersion();
                            Version priorVersion = repositoryIuVersionById.put(key, version);
                            if (priorVersion != null && priorVersion.compareTo(version) > 0) {
                                repositoryIuVersionById.put(key, priorVersion);
                            }
                        }
                        for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
                            List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
                            for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
                                String key = createRepositoryIuKey(uri.toString(), iuItem.getId());
                                Version availableVersion = repositoryIuVersionById.get(key);
                                MarketplaceCatalog.this.repositoryIuVersionById.put(key, availableVersion);
                                if (availableVersion != null) {
                                    item.setAvailable(true);
                                }
                            }
                        }
                        for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
                            setUpdatesAvailable(installedIUs, item);
                        }
                    } catch (ProvisionException e) {
                        MultiStatus errorStatus = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, IStatus.WARNING, NLS.bind(Messages.MarketplaceCatalog_ErrorReadingRepository, uri), e);
                        for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
                            item.setAvailable(false);
                            errorStatus.add(MarketplaceClientUi.newStatus(IStatus.INFO, item.getName()));
                        }
                        MarketplaceClientUi.getLog().log(errorStatus);
                    } catch (OperationCanceledException e) {
                    // nothing to do
                    }
                }
            });
        }
        try {
            executor.waitUntilFinished(monitor);
        } catch (CoreException e) {
            MarketplaceClientUi.error(e);
            return e.getStatus();
        }
        return Status.OK_STATUS;
    } finally {
        executor.shutdownNow();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IQuery(org.eclipse.equinox.p2.query.IQuery) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) MultiStatus(org.eclipse.core.runtime.MultiStatus) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) Version(org.eclipse.equinox.p2.metadata.Version) ArrayList(java.util.ArrayList) List(java.util.List) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) IQueryResult(org.eclipse.equinox.p2.query.IQueryResult) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ConcurrentTaskManager(org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project archi by archimatetool.

the class P2UninstallHandler method execute.

public boolean execute(Shell shell, List<IInstallableUnit> selected) {
    this.shell = shell;
    if (selected.isEmpty()) {
        return false;
    }
    boolean ok = MessageDialog.openQuestion(shell, Messages.P2UninstallHandler_0, Messages.P2UninstallHandler_2);
    if (!ok) {
        return false;
    }
    IProgressMonitor monitor = new NullProgressMonitor();
    try {
        IStatus status = P2Handler.getInstance().uninstall(selected, monitor);
        if (status.isOK()) {
            needsRestart = true;
        } else {
            displayErrorDialog(Messages.P2UninstallHandler_1);
        }
    } catch (ProvisionException ex) {
        displayErrorDialog(ex.getMessage());
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException)

Example 28 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project archi by archimatetool.

the class P2Handler method getInstalledFeatures.

List<IInstallableUnit> getInstalledFeatures() throws ProvisionException {
    IProfile profile = getDefaultProfile();
    ArrayList<IInstallableUnit> list = new ArrayList<IInstallableUnit>();
    IQuery<IInstallableUnit> query = QueryUtil.createIUGroupQuery();
    IQueryResult<IInstallableUnit> queryResult = profile.query(query, null);
    for (IInstallableUnit feature : queryResult) {
        if (!isInternalFeature(feature)) {
            list.add(feature);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IProfile(org.eclipse.equinox.p2.engine.IProfile)

Example 29 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project archi by archimatetool.

the class P2Handler method getProvisioningAgent.

private IProvisioningAgent getProvisioningAgent() throws ProvisionException {
    if (provisioningAgent == null) {
        ServiceReference<?> sr = Activator.getContext().getServiceReference(IProvisioningAgentProvider.SERVICE_NAME);
        IProvisioningAgentProvider agentProvider = (IProvisioningAgentProvider) Activator.getContext().getService(sr);
        provisioningAgent = agentProvider.createAgent(null);
    }
    return provisioningAgent;
}
Also used : IProvisioningAgentProvider(org.eclipse.equinox.p2.core.IProvisioningAgentProvider)

Example 30 with ProvisionException

use of org.eclipse.equinox.p2.core.ProvisionException in project archi by archimatetool.

the class P2Handler method update.

public IStatus update(URI uri, IProgressMonitor monitor) throws ProvisionException {
    loadRepository(uri, monitor);
    UpdateOperation operation = new UpdateOperation(getProvisioningSession());
    return performOperation(operation, monitor);
}
Also used : UpdateOperation(org.eclipse.equinox.p2.operations.UpdateOperation)

Aggregations

ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)29 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)14 IStatus (org.eclipse.core.runtime.IStatus)13 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)10 Test (org.junit.Test)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IArtifactRepository (org.eclipse.equinox.p2.repository.artifact.IArtifactRepository)8 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)8 URI (java.net.URI)7 ArrayList (java.util.ArrayList)7 File (java.io.File)6 Status (org.eclipse.core.runtime.Status)6 IOException (java.io.IOException)5 IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)5 IProvisioningAgentProvider (org.eclipse.equinox.p2.core.IProvisioningAgentProvider)5 OutputStream (java.io.OutputStream)4 HashSet (java.util.HashSet)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ProvisioningSession (org.eclipse.equinox.p2.operations.ProvisioningSession)4 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)4