Search in sources :

Example 21 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project liferay-ide by liferay.

the class LiferayPublishOperation 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
 */
protected static void throwException(List status) throws CoreException {
    if (status == null || status.size() == 0)
        return;
    if (status.size() == 1) {
        IStatus status2 = (IStatus) status.get(0);
        throw new CoreException(status2);
    }
    IStatus[] children = new IStatus[status.size()];
    status.toArray(children);
    String message = Msgs.errorPublish;
    MultiStatus status2 = new MultiStatus(TomcatPlugin.PLUGIN_ID, 0, children, message, null);
    throw new CoreException(status2);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 22 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project liferay-ide by liferay.

the class SDK method validate.

public IStatus validate(boolean reload) {
    MultiStatus status = new MultiStatus(SDKCorePlugin.PLUGIN_ID, IStatus.OK, "", null);
    boolean validLocation = SDKUtil.isValidSDKLocation(getLocation().toOSString());
    IPath buildXmlLocation = getLocation().append("build.xml");
    if (!validLocation) {
        status.add(SDKCorePlugin.createErrorStatus(Msgs.sdkLocationInvalid));
        return status;
    }
    if (!buildXmlLocation.toFile().exists()) {
        status.add(SDKCorePlugin.createErrorStatus(Msgs.buildXmlFileNotExist));
        return status;
    }
    Map<String, Object> sdkProperties = null;
    try {
        sdkProperties = getBuildProperties(reload);
        if (sdkProperties == null) {
            status.add(SDKCorePlugin.createErrorStatus("Could not find any sdk settings."));
            return status;
        }
    } catch (Exception e) {
        status.add(SDKCorePlugin.createErrorStatus(e.getMessage()));
        return status;
    }
    for (String propertyKey : appServerPropertiesKeys) {
        if (!status.isOK()) {
            break;
        }
        String propertyValue = (String) sdkProperties.get(propertyKey);
        if (propertyValue == null) {
            status.add(SDKCorePlugin.createErrorStatus(propertyKey + " is null."));
        } else {
            switch(propertyKey) {
                case "app.server.type":
                    if (!supportedServerTypes.contains(propertyValue)) {
                        status.add(SDKCorePlugin.createErrorStatus("The " + propertyKey + "(" + propertyValue + ") server is not supported by Liferay IDE."));
                    }
                    break;
                case "app.server.dir":
                case "app.server.deploy.dir":
                case "app.server.lib.global.dir":
                case "app.server.parent.dir":
                case "app.server.portal.dir":
                    IPath propertyPath = new Path(propertyValue);
                    if (!propertyPath.toFile().exists()) {
                        String errorMessage = new String(propertyKey + " is invalid. Please reconfigure Plugins SDK setting: " + propertyKey + "=" + propertyValue);
                        status.add(SDKCorePlugin.createErrorStatus(SDKCorePlugin.PLUGIN_ID, errorMessage));
                    }
                    break;
                default:
            }
        }
    }
    return status;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) MultiStatus(org.eclipse.core.runtime.MultiStatus) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 23 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project jbosstools-hibernate by jbosstools.

the class HibernatePlugin method throwableToStatus.

public static IStatus throwableToStatus(Throwable t, int code) {
    List<IStatus> causes = new ArrayList<IStatus>();
    Throwable temp = t;
    while (temp != null && temp.getCause() != temp) {
        causes.add(new Status(IStatus.ERROR, getId(), code, temp.getMessage() == null ? temp.toString() + HibernateConsoleMessages.HibernateConsolePlugin_no_message_1 : temp.toString(), temp));
        temp = temp.getCause();
    }
    String msg = HibernateConsoleMessages.HibernateConsolePlugin_no_message_2;
    if (t != null && t.getMessage() != null) {
        msg = t.toString();
    }
    if (causes.isEmpty()) {
        return new Status(IStatus.ERROR, getId(), code, msg, t);
    } else {
        return new MultiStatus(getId(), code, causes.toArray(new IStatus[causes.size()]), msg, t);
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 24 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project jbosstools-hibernate by jbosstools.

the class HibernateConsolePlugin method openError.

/*public ConsoleConfiguration getLastUsedConfiguration() {
		String lastUsedName = getDefault().getPreferenceStore().getString(HibernateConsolePlugin.LAST_USED_CONFIGURATION_PREFERENCE);

		ConsoleConfiguration lastUsed = (lastUsedName == null || lastUsedName.trim().length()==0)
				? null
				: KnownConfigurations.getInstance().find(lastUsedName);

	    if(lastUsed==null && KnownConfigurations.getInstance().getConfigurations().length==1) {
	        lastUsed = KnownConfigurations.getInstance().getConfigurations()[0];
	    }

		return lastUsed;
	}*/
/*public void setLastUsedConfiguration(ConsoleConfiguration lastUsed) {
		String name;
		if(lastUsed==null) {
			name = "";
		} else {
			name = lastUsed.getName();
		}

		HibernateConsolePlugin.getDefault().getPreferenceStore().setValue(
				LAST_USED_CONFIGURATION_PREFERENCE, name );
	}*/
/**
 * Convenience method for showing an error dialog
 * @param shell a valid shell or null
 * @param exception the exception to be report
 * @param title the title to be displayed
 * @param flags customizing attributes for the error handling
 * @return IStatus the status that was displayed to the user
 */
public static IStatus openError(Shell providedShell, String title, String message, Throwable exception, int flags) {
    // Unwrap InvocationTargetExceptions
    if (exception instanceof InvocationTargetException) {
        Throwable target = ((InvocationTargetException) exception).getTargetException();
        // re-throw any runtime exceptions or errors so they can be handled by the workbench
        if (target instanceof RuntimeException) {
            throw (RuntimeException) target;
        }
        if (target instanceof Error) {
            throw (Error) target;
        }
        return openError(providedShell, title, message, target, flags);
    }
    // Determine the status to be displayed (and possibly logged)
    IStatus status = null;
    if (exception instanceof CoreException) {
        status = ((CoreException) exception).getStatus();
    } else if (exception != null) {
        status = new MultiStatus(ID, IStatus.ERROR, new IStatus[] { throwableToStatus(exception.getCause()) }, exception.toString(), exception);
    }
    if (status.isOK()) {
        return status;
    }
    // Create a runnable that will display the error status
    final String displayTitle = title;
    final String displayMessage = message;
    final IStatus displayStatus = status;
    final IOpenableInShell openable = new IOpenableInShell() {

        public void open(Shell shell) {
            if (displayStatus.getSeverity() == IStatus.INFO && !displayStatus.isMultiStatus()) {
                // $NON-NLS-1$
                MessageDialog.openInformation(shell, "Information", displayStatus.getMessage());
            } else {
                ErrorDialog.openError(shell, displayTitle, displayMessage, displayStatus);
            }
        }
    };
    openDialog(providedShell, openable, flags);
    // return the status we display
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 25 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project jbosstools-hibernate by jbosstools.

the class HibernateConsolePlugin method logErrorMessage.

public void logErrorMessage(String message, Throwable[] t) {
    IStatus[] children = new IStatus[t.length];
    for (int i = 0; i < t.length; i++) {
        Throwable throwable = t[i];
        children[i] = throwableToStatus(throwable);
    }
    IStatus s = new MultiStatus(ID, 150, children, message, null);
    log(s);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Aggregations

MultiStatus (org.eclipse.core.runtime.MultiStatus)140 IStatus (org.eclipse.core.runtime.IStatus)98 Status (org.eclipse.core.runtime.Status)60 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