Search in sources :

Example 96 with MultiStatus

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);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) Certification(org.eclipse.equinox.internal.p2.discovery.model.Certification) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) CoreException(org.eclipse.core.runtime.CoreException) AbstractDiscoveryStrategy(org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag)

Example 97 with MultiStatus

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));
    }
}
Also used : ProfileChangeOperation(org.eclipse.equinox.p2.operations.ProfileChangeOperation) MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Field(java.lang.reflect.Field) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProfileChangeRequest(org.eclipse.equinox.p2.planner.IProfileChangeRequest) ProfileChangeRequest(org.eclipse.equinox.internal.p2.director.ProfileChangeRequest)

Example 98 with MultiStatus

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;
}
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) IPath(org.eclipse.core.runtime.IPath) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) MultiStatus(org.eclipse.core.runtime.MultiStatus) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)

Example 99 with MultiStatus

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;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 100 with MultiStatus

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);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) 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