use of org.eclipse.core.runtime.MultiStatus in project epp.mpc by eclipse.
the class MarketplaceCatalog method performDiscovery.
protected IStatus performDiscovery(DiscoveryOperation operation, boolean refresh, IProgressMonitor monitor) {
MultiStatus status = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, 0, Messages.MarketplaceCatalog_queryFailed, null);
if (getDiscoveryStrategies().isEmpty()) {
throw new IllegalStateException();
}
// reset, keeping no items but the same tags, categories and certifications
List<CatalogItem> items = new ArrayList<CatalogItem>();
List<CatalogCategory> categories = new ArrayList<CatalogCategory>(getCategories());
List<Certification> certifications = new ArrayList<Certification>(getCertifications());
List<Tag> tags = new ArrayList<Tag>(getTags());
if (!refresh) {
for (CatalogCategory catalogCategory : categories) {
catalogCategory.getItems().clear();
}
}
final int totalTicks = 100000;
final int discoveryTicks = totalTicks - (totalTicks / 10);
monitor.beginTask(Messages.MarketplaceCatalog_queryingMarketplace, totalTicks);
try {
int strategyTicks = discoveryTicks / getDiscoveryStrategies().size();
for (AbstractDiscoveryStrategy discoveryStrategy : getDiscoveryStrategies()) {
if (monitor.isCanceled()) {
status.add(Status.CANCEL_STATUS);
break;
}
if (discoveryStrategy instanceof MarketplaceDiscoveryStrategy) {
List<CatalogCategory> oldCategories = discoveryStrategy.getCategories();
List<CatalogItem> oldItems = discoveryStrategy.getItems();
List<Certification> oldCertifications = discoveryStrategy.getCertifications();
List<Tag> oldTags = discoveryStrategy.getTags();
discoveryStrategy.setCategories(categories);
discoveryStrategy.setItems(items);
discoveryStrategy.setCertifications(certifications);
discoveryStrategy.setTags(tags);
try {
MarketplaceDiscoveryStrategy marketplaceStrategy = (MarketplaceDiscoveryStrategy) discoveryStrategy;
operation.run(marketplaceStrategy, new SubProgressMonitor(monitor, strategyTicks));
} catch (CoreException e) {
IStatus error = MarketplaceClientCore.computeWellknownProblemStatus(e);
if (error == null) {
error = new Status(e.getStatus().getSeverity(), DiscoveryCore.ID_PLUGIN, NLS.bind(Messages.MarketplaceCatalog_failedWithError, discoveryStrategy.getClass().getSimpleName()), e);
}
status.add(error);
} finally {
// remove everything from strategy again, so it can't accidentally mess with the results later
discoveryStrategy.setCategories(oldCategories);
discoveryStrategy.setItems(oldItems);
discoveryStrategy.setCertifications(oldCertifications);
discoveryStrategy.setTags(oldTags);
// make sure strategy didn't misbehave
if (items.contains(null)) {
while (items.remove(null)) {
}
IStatus error = new Status(IStatus.WARNING, DiscoveryCore.ID_PLUGIN, NLS.bind(Messages.MarketplaceCatalog_addedNullEntry, discoveryStrategy.getClass().getSimpleName()));
status.add(error);
}
}
}
}
update(categories, items, certifications, tags);
} finally {
monitor.done();
}
return computeStatus(status);
}
use of org.eclipse.core.runtime.MultiStatus in project epp.mpc by eclipse.
the class CompositeProfileChangeOperation method computeProfileChangeRequest.
@Override
protected void computeProfileChangeRequest(MultiStatus status, IProgressMonitor monitor) {
ProfileChangeRequest request = ProfileChangeRequest.createByProfileId(session.getProvisioningAgent(), getProfileId());
SubMonitor progress = SubMonitor.convert(monitor, 1000 * operations.size());
for (ProfileChangeOperation operation : operations) {
updateRequest(request, operation, status, progress.newChild(1000));
}
try {
// $NON-NLS-1$
Field requestField = ProfileChangeOperation.class.getDeclaredField("request");
boolean accessible = requestField.isAccessible();
try {
requestField.setAccessible(true);
requestField.set(this, request);
} finally {
requestField.setAccessible(accessible);
}
} catch (Exception e) {
status.add(new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, Messages.CompositeProfileChangeOperation_ChangeRequestError, e));
}
}
use of org.eclipse.core.runtime.MultiStatus in project webtools.servertools by eclipse.
the class TomcatVersionHelper method localizeConfiguration.
/**
* If modules are not being deployed to the "webapps" directory, the
* context for the published modules is updated to contain the
* corrected docBase.
*
* @param baseDir runtime base directory for the server
* @param deployDir deployment directory for the server
* @param server server being localized
* @param monitor a progress monitor
* @return result of operation
*/
public static IStatus localizeConfiguration(IPath baseDir, IPath deployDir, TomcatServer server, IProgressMonitor monitor) {
try {
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Localizing configuration at " + baseDir);
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.publishConfigurationTask, 300);
IPath serverXml = baseDir.append("conf/server.xml");
Factory factory = new Factory();
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
Server publishedServer = (Server) factory.loadDocument(new FileInputStream(serverXml.toFile()));
ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
monitor.worked(100);
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
boolean modified = false;
// Only add root module if running in a test env (i.e. not on the installation)
boolean addRootWebapp = server.isTestEnvironment();
// If not deploying to "webapps", context docBase attributes need updating
// TODO Improve to compare with appBase value instead of hardcoded "webapps"
boolean deployingToAppBase = "webapps".equals(server.getDeployDirectory());
Map<String, String> pathMap = new HashMap<String, String>();
MultiStatus ms = new MultiStatus(TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishServer, server.getServer().getName()), null);
Context[] contexts = publishedInstance.getContexts();
if (contexts != null) {
for (int i = 0; i < contexts.length; i++) {
Context context = contexts[i];
// Normalize path and check for duplicates
String path = context.getPath();
if (path != null) {
// Save a copy of original in case it's "/"
String origPath = path;
// Normalize "/" to ""
if ("/".equals(path)) {
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Context path is being changed from \"/\" to \"\".");
path = "";
context.setPath(path);
modified = true;
}
// Context paths that are the same or differ only in case are not allowed
String lcPath = path.toLowerCase();
if (!pathMap.containsKey(lcPath)) {
pathMap.put(lcPath, origPath);
} else {
String otherPath = pathMap.get(lcPath);
IStatus s = new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, origPath.equals(otherPath) ? NLS.bind(Messages.errorPublishPathDup, origPath) : NLS.bind(Messages.errorPublishPathConflict, origPath, otherPath));
ms.add(s);
}
} else {
IStatus s = new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, Messages.errorPublishPathMissing);
ms.add(s);
}
// TODO Need to add a root context if deploying to webapps but with auto-deploy off
if (addRootWebapp && "".equals(context.getPath())) {
// A default webapp is being deployed, don't add one
addRootWebapp = false;
}
// If not deploying to appBase, convert to absolute path under deploy dir
if (!deployingToAppBase) {
String source = context.getSource();
if (source != null && source.length() > 0) {
context.setDocBase(deployDir.append(context.getDocBase()).toOSString());
modified = true;
}
}
}
}
// If errors are present, return status
if (!ms.isOK())
return ms;
if (addRootWebapp) {
// Add a context for the default webapp
Context rootContext = publishedInstance.createContext(0);
rootContext.setPath("");
rootContext.setDocBase(deployDir.append("ROOT").toOSString());
rootContext.setReloadable("false");
modified = true;
}
monitor.worked(100);
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
if (modified) {
monitor.subTask(Messages.savingContextConfigTask);
factory.save(serverXml.toOSString());
}
monitor.worked(100);
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Context docBase settings updated in server.xml.");
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not localize server configuration published to " + baseDir.toOSString() + ": " + e.getMessage());
return new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishConfiguration, new String[] { e.getLocalizedMessage() }), e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
use of org.eclipse.core.runtime.MultiStatus in project webtools.servertools by eclipse.
the class CleanWorkDirDialog method wrapErrorStatus.
protected IStatus wrapErrorStatus(IStatus status, String message) {
MultiStatus ms = new MultiStatus(TomcatUIPlugin.PLUGIN_ID, 0, message, null);
ms.add(status);
return ms;
}
use of org.eclipse.core.runtime.MultiStatus in project webtools.servertools by eclipse.
the class PreviewServerBehaviour 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(PreviewPlugin.PLUGIN_ID, 0, status, message, null);
throw new CoreException(status2);
}
Aggregations