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);
}
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;
}
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();
}
}
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();
}
}
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;
}
Aggregations