Search in sources :

Example 46 with MultiStatus

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

the class TomcatVersionHelper method addCatalinaContextConfig.

/**
 * If the specified Context is linked to a project, try to
 * update it with any configuration from a META-INF/context.xml found
 * relative to the specified web applications directory and context docBase.
 *
 * @param webappsDir Path to server's web applications directory.
 * @param context Context object to receive context.xml contents.
 * @param ms MultiStatus object to receive error status.
 * @return Returns true if context is modified.
 */
private static boolean addCatalinaContextConfig(IPath webappsDir, Context context, MultiStatus ms) {
    boolean modified = false;
    String source = context.getSource();
    if (source != null && source.length() > 0) {
        File docBase = new File(context.getDocBase());
        if (!docBase.isAbsolute())
            docBase = new File(webappsDir.toOSString(), docBase.getPath());
        try {
            Context contextConfig = loadCatalinaContextConfig(docBase);
            if (null != contextConfig) {
                if (context.hasChildNodes())
                    context.removeChildren();
                contextConfig.copyChildrenTo(context);
                Map attrs = contextConfig.getAttributes();
                Iterator iter = attrs.keySet().iterator();
                while (iter.hasNext()) {
                    String name = (String) iter.next();
                    if (!name.equalsIgnoreCase("path") && !name.equalsIgnoreCase("docBase") && !name.equalsIgnoreCase("source")) {
                        String value = (String) attrs.get(name);
                        context.setAttributeValue(name, value);
                    }
                }
                modified = true;
            }
        } catch (Exception e) {
            String contextPath = context.getPath();
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
            Trace.trace(Trace.SEVERE, "Error reading context.xml file for " + contextPath, e);
            IStatus s = new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadContextXml, contextPath), e);
            ms.add(s);
        }
    }
    return modified;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Iterator(java.util.Iterator) JarFile(java.util.jar.JarFile) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 47 with MultiStatus

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

the class TransportFactory method diagnoseTransportServiceRegistration.

private static IStatus diagnoseTransportServiceRegistration(BundleContext context, ServiceReference<ITransportFactory> serviceReference) {
    MultiStatus serviceError = null;
    if (serviceReference != null) {
        serviceError = new MultiStatus(MarketplaceClientCore.BUNDLE_ID, 0, Messages.TransportFactory_ServiceErrorUnregistered, null);
        serviceError.add(new Status(IStatus.ERROR, MarketplaceClientCore.BUNDLE_ID, Messages.TransportFactory_ServiceErrorServiceReference + serviceReference));
    } else {
        serviceError = new MultiStatus(MarketplaceClientCore.BUNDLE_ID, 0, Messages.TransportFactory_ServiceErrorNotFound, null);
        try {
            Collection<ServiceReference<ITransportFactory>> allServiceReferences = context.getServiceReferences(ITransportFactory.class, null);
            if (allServiceReferences.isEmpty()) {
                serviceError.add(new Status(IStatus.ERROR, MarketplaceClientCore.BUNDLE_ID, Messages.TransportFactory_ServiceErrorNoneAvailable));
            } else {
                String filter = computeDisabledTransportsFilter();
                serviceError.add(new Status(IStatus.ERROR, MarketplaceClientCore.BUNDLE_ID, Messages.TransportFactory_ServiceErrorAppliedFilter + filter));
            }
            for (ServiceReference<ITransportFactory> availableReference : allServiceReferences) {
                serviceError.add(new Status(IStatus.INFO, MarketplaceClientCore.BUNDLE_ID, Messages.TransportFactory_ServiceErrorFilteredService + availableReference.toString()));
            }
        } catch (InvalidSyntaxException e) {
            // Unreachable
            serviceError.add(new Status(IStatus.ERROR, MarketplaceClientCore.BUNDLE_ID, Messages.TransportFactory_ServiceErrorDetails, e));
        }
    }
    return serviceError;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MultiStatus(org.eclipse.core.runtime.MultiStatus) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ITransportFactory(org.eclipse.epp.mpc.core.service.ITransportFactory) ServiceReference(org.osgi.framework.ServiceReference)

Example 48 with MultiStatus

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

the class MarketplaceCatalog method performNewsDiscovery.

public IStatus performNewsDiscovery(IProgressMonitor monitor) {
    if (getDiscoveryStrategies().isEmpty()) {
        throw new IllegalStateException();
    }
    INews news = null;
    MultiStatus status = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, 0, Messages.MarketplaceCatalog_queryFailed, null);
    final int totalTicks = 100000;
    final SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceCatalog_Checking_News, totalTicks);
    try {
        int strategyTicks = totalTicks / getDiscoveryStrategies().size();
        for (AbstractDiscoveryStrategy discoveryStrategy : getDiscoveryStrategies()) {
            if (monitor.isCanceled()) {
                status.add(Status.CANCEL_STATUS);
                break;
            }
            if (discoveryStrategy instanceof MarketplaceDiscoveryStrategy) {
                try {
                    MarketplaceDiscoveryStrategy marketplaceStrategy = (MarketplaceDiscoveryStrategy) discoveryStrategy;
                    news = marketplaceStrategy.performNewsDiscovery(progress.newChild(strategyTicks));
                    if (news != null) {
                        break;
                    }
                } catch (CoreException e) {
                    status.add(new Status(e.getStatus().getSeverity(), DiscoveryCore.ID_PLUGIN, NLS.bind(Messages.MarketplaceCatalog_failedWithError, discoveryStrategy.getClass().getSimpleName()), e));
                }
            }
        }
    } finally {
        monitor.done();
    }
    if (status.isOK()) {
        setNews(news);
    }
    return status;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) INews(org.eclipse.epp.mpc.core.model.INews) AbstractDiscoveryStrategy(org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 49 with MultiStatus

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

the class MarketplaceCatalog method performDiscovery.

@Override
public IStatus performDiscovery(IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 200000);
    IStatus status = super.performDiscovery(progress.newChild(100000));
    // check for updates
    if (status.getSeverity() < IStatus.ERROR) {
        IStatus updateStatus = checkForUpdates(progress.newChild(100000));
        if (!updateStatus.isOK()) {
            if (status.isOK()) {
                status = updateStatus;
            } else {
                MultiStatus multiStatus = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, 0, Messages.MarketplaceCatalog_Discovery_Error, null);
                multiStatus.add(status);
                multiStatus.add(updateStatus);
                status = multiStatus;
            }
        }
    }
    return computeStatus(status);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 50 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project vsDiaryWriter by shilongdai.

the class ExceptionDisplayer method errorDialogWithStackTrace.

public static void errorDialogWithStackTrace(String msg, Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);
    // stack trace as a string
    final String trace = sw.toString();
    // Temp holder of child statuses
    List<Status> childStatuses = new ArrayList<>();
    // Split output by OS-independend new-line
    for (String line : trace.split(System.getProperty("line.separator"))) {
        // build & add status
        childStatuses.add(new Status(IStatus.ERROR, "Journal", line));
    }
    MultiStatus ms = new // convert
    MultiStatus(// convert
    "Journal", // convert
    IStatus.ERROR, // convert
    childStatuses.toArray(new Status[] {}), // statuses
    t.getLocalizedMessage(), t);
    ErrorDialog.openError(null, "Error", msg, ms);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) PrintWriter(java.io.PrintWriter)

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