Search in sources :

Example 91 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project webtools.servertools by eclipse.

the class HttpServerBehaviour method throwException.

/**
 * Utility method to throw a CoreException based on the contents of a list of
 * error and warning status.
 *
 * @param status a List containing error and warning IStatus
 * @throws CoreException
 */
private static void throwException(IStatus[] status) throws CoreException {
    if (status == null || status.length == 0)
        return;
    if (status.length == 1)
        throw new CoreException(status[0]);
    String message = Messages.errorPublish;
    MultiStatus status2 = new MultiStatus(HttpCorePlugin.PLUGIN_ID, 0, status, message, null);
    throw new CoreException(status2);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 92 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project epp.mpc by eclipse.

the class DefaultMarketplaceService method getNodes.

public List<INode> getNodes(Collection<? extends INode> nodes, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_getNodesProgress, nodes.size());
    if (nodes.isEmpty()) {
        return new ArrayList<INode>();
    }
    List<INode> nodesById = null;
    List<INode> nodesByUrl = null;
    for (INode node : nodes) {
        if (node.getId() == null) {
            if (node.getUrl() == null) {
                throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_invalidNode, node));
            }
            if (nodesByUrl == null) {
                nodesByUrl = new ArrayList<INode>();
            }
            nodesByUrl.add(node);
        } else {
            if (nodesById == null) {
                nodesById = new ArrayList<INode>(nodes.size());
            }
            nodesById.add(node);
        }
    }
    Map<INode, INode> resolvedNodeMapping = new HashMap<INode, INode>(nodes.size());
    if (nodesById != null) {
        getNodesById(nodesById, resolvedNodeMapping, progress.newChild(nodesById.size()));
    }
    if (nodesByUrl != null) {
        getNodesByUrl(nodesByUrl, resolvedNodeMapping, progress.newChild(nodesByUrl.size()));
    }
    List<INode> resultNodes = new ArrayList<INode>(nodes.size());
    MultiStatus missingNodes = null;
    for (INode inputNode : nodes) {
        INode resolvedNode = resolvedNodeMapping.get(inputNode);
        if (resolvedNode != null) {
            resultNodes.add(resolvedNode);
        } else {
            String query;
            if (inputNode.getId() != null) {
                query = inputNode.getId();
            } else {
                query = inputNode.getUrl();
            }
            IStatus missingNodeDetailStatus = createStatus(IStatus.INFO, Messages.DefaultMarketplaceService_nodeNotFound, query);
            if (missingNodes == null) {
                missingNodes = new MultiStatus(MarketplaceClientCore.BUNDLE_ID, 0, "Some entries could not be found on the Marketplace", // $NON-NLS-1$
                null);
            }
            missingNodes.add(missingNodeDetailStatus);
        }
    }
    if (missingNodes != null) {
        MarketplaceClientCore.getLog().log(missingNodes);
    }
    return resultNodes;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 93 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project epp.mpc by eclipse.

the class ConcurrentTaskManager method waitUntilFinished.

public void waitUntilFinished(IProgressMonitor monitor) throws CoreException {
    final MultiStatus errorStatus = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, IStatus.OK, Messages.ConcurrentTaskManager_multipleErrorsOccurred, null);
    final int totalWork = futures.isEmpty() ? 1 : futures.size();
    monitor.beginTask(taskName, totalWork);
    try {
        if (!futures.isEmpty()) {
            final int workUnit = 1;
            while (!futures.isEmpty()) {
                Future<?> future = futures.remove(0);
                final int maxRetries = 15;
                for (int retryCount = 0; ; ++retryCount) {
                    try {
                        future.get(1L, TimeUnit.SECONDS);
                        break;
                    } catch (TimeoutException e) {
                        if (monitor.isCanceled()) {
                            return;
                        }
                    } catch (InterruptedException e) {
                        throw new CoreException(new Status(IStatus.CANCEL, MarketplaceClientUi.BUNDLE_ID, e.getMessage()));
                    } catch (ExecutionException e) {
                        errorStatus.add(new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, e.getCause().getMessage(), e.getCause()));
                        if (monitor.isCanceled()) {
                            break;
                        }
                    }
                    if (retryCount > maxRetries) {
                        future.cancel(true);
                        break;
                    }
                }
                monitor.worked(workUnit);
            }
        }
        if (!errorStatus.isOK() && errorStatus.getChildren().length > 0) {
            if (errorStatus.getChildren().length == 1) {
                throw new CoreException(errorStatus.getChildren()[0]);
            } else {
                throw new CoreException(errorStatus);
            }
        }
    } finally {
        executor.shutdownNow();
        monitor.done();
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 94 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus 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 95 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project epp.mpc by eclipse.

the class MarketplaceCatalog method computeStatus.

private IStatus computeStatus(IStatus status) {
    if (status.getSeverity() == IStatus.ERROR) {
        // unwrap a multistatus with one child see bug 309612
        if (status.isMultiStatus()) {
            MultiStatus multiStatus = (MultiStatus) status;
            if (multiStatus.getChildren().length == 1) {
                status = multiStatus.getChildren()[0];
            }
        }
        if (!status.isMultiStatus()) {
            Throwable exception = status.getException();
            IStatus newStatus = MarketplaceClientCore.computeWellknownProblemStatus(exception);
            if (newStatus != null) {
                return newStatus;
            }
        }
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Aggregations

MultiStatus (org.eclipse.core.runtime.MultiStatus)146 IStatus (org.eclipse.core.runtime.IStatus)102 Status (org.eclipse.core.runtime.Status)62 CoreException (org.eclipse.core.runtime.CoreException)41 ArrayList (java.util.ArrayList)29 File (java.io.File)24 SubMonitor (org.eclipse.core.runtime.SubMonitor)24 IOException (java.io.IOException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 List (java.util.List)11 HashMap (java.util.HashMap)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)10 IPath (org.eclipse.core.runtime.IPath)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 FileNotFoundException (java.io.FileNotFoundException)7 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 IContainer (org.eclipse.core.resources.IContainer)6 URI (java.net.URI)5