Search in sources :

Example 76 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project generator by mybatis.

the class RunGeneratorAction method run.

public void run(IAction action) {
    Shell shell = new Shell();
    if (!MessageDialog.openConfirm(shell, "Deprecated Funtionality", DEPRECATION_MESSAGE)) {
        return;
    }
    try {
        List<String> warnings = new ArrayList<String>();
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        IRunnableWithProgress thread = new GeneratorRunner(warnings);
        dialog.run(true, true, thread);
        if (warnings.size() > 0) {
            MultiStatus ms = new MultiStatus(Activator.PLUGIN_ID, Status.WARNING, "Generation Warnings Occured", null);
            Iterator<String> iter = warnings.iterator();
            while (iter.hasNext()) {
                Status status = new Status(Status.WARNING, Activator.PLUGIN_ID, Status.WARNING, iter.next(), null);
                ms.add(status);
            }
            ErrorDialog.openError(shell, "MyBatis Generator", "Run Complete With Warnings", ms, Status.WARNING);
        }
    } catch (Exception e) {
        handleException(e, shell);
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 77 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project generator by mybatis.

the class RunGeneratorThread method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor)
     */
public void run(IProgressMonitor monitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(monitor, 1000);
    subMonitor.beginTask("Generating MyBatis/iBATIS Artifacts:", 1000);
    setClassLoader();
    try {
        subMonitor.subTask("Parsing Configuration");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(inputFile.getLocation().toFile());
        subMonitor.worked(50);
        MyBatisGenerator mybatisGenerator = new MyBatisGenerator(config, new EclipseShellCallback(), warnings);
        monitor.subTask("Generating Files from Database Tables");
        SubMonitor spm = subMonitor.newChild(950);
        mybatisGenerator.generate(new EclipseProgressCallback(spm));
    } catch (InterruptedException e) {
        throw new OperationCanceledException();
    } catch (SQLException e) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
        throw new CoreException(status);
    } catch (IOException e) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
        throw new CoreException(status);
    } catch (XMLParserException e) {
        List<String> errors = e.getErrors();
        MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "XML Parser Errors\n  See Details for more Information", null);
        Iterator<String> iter = errors.iterator();
        while (iter.hasNext()) {
            Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
            multiStatus.add(message);
        }
        throw new CoreException(multiStatus);
    } catch (InvalidConfigurationException e) {
        List<String> errors = e.getErrors();
        MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "Invalid Configuration\n  See Details for more Information", null);
        Iterator<String> iter = errors.iterator();
        while (iter.hasNext()) {
            Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
            multiStatus.add(message);
        }
        throw new CoreException(multiStatus);
    } finally {
        monitor.done();
        restoreClassLoader();
    }
}
Also used : EclipseShellCallback(org.mybatis.generator.eclipse.core.callback.EclipseShellCallback) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Configuration(org.mybatis.generator.config.Configuration) SQLException(java.sql.SQLException) XMLParserException(org.mybatis.generator.exception.XMLParserException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) IOException(java.io.IOException) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) EclipseProgressCallback(org.mybatis.generator.eclipse.core.callback.EclipseProgressCallback) CoreException(org.eclipse.core.runtime.CoreException) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 78 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project sling by apache.

the class ServerBehaviourDelegateWithModulePublishSupport method publish.

// from WST's ServerBehavior
public IStatus publish(int kind, IProgressMonitor monitor) {
    Activator.getDefault().getPluginLogger().trace("-->-- Publishing to server: " + getServer().toString() + " -->--");
    if (getServer().getServerType().hasRuntime() && getServer().getRuntime() == null)
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "No runtime available", null);
    //getAllModules();
    final List<IModule[]> moduleList = modules3 == null ? getAllModules() : new LinkedList<>(modules3);
    List<Integer> deltaKindList = computeDelta(moduleList);
    PublishOperation[] tasks = getTasks(kind, moduleList, deltaKindList);
    int size = 2000 + 3500 * moduleList.size() + 500 * tasks.length;
    //        monitor = ProgressUtil.getMonitorFor(monitor); //TODO
    //NLS.bind(Messages.publishing, getServer().getName());
    String mainTaskMsg = "Publishing to " + getServer().getName();
    monitor.beginTask(mainTaskMsg, size);
    MultiStatus tempMulti = new MultiStatus(Activator.PLUGIN_ID, 0, "", null);
    if (monitor.isCanceled())
        return Status.CANCEL_STATUS;
    try {
        Activator.getDefault().getPluginLogger().trace("Starting publish");
        //ProgressUtil.getSubMonitorFor(monitor, 1000)); //TODO
        publishStart(monitor);
        if (monitor.isCanceled())
            return Status.CANCEL_STATUS;
        // execute tasks
        MultiStatus taskStatus = performTasks(tasks, monitor);
        monitor.setTaskName(mainTaskMsg);
        if (taskStatus != null && !taskStatus.isOK())
            tempMulti.addAll(taskStatus);
        // execute publishers
        taskStatus = executePublishers(kind, moduleList, deltaKindList, monitor, info3);
        monitor.setTaskName(mainTaskMsg);
        if (taskStatus != null && !taskStatus.isOK())
            tempMulti.addAll(taskStatus);
        if (monitor.isCanceled())
            return Status.CANCEL_STATUS;
        // publish the server
        //ProgressUtil.getSubMonitorFor(monitor, 1000));//TODO
        publishServer(kind, monitor);
        monitor.setTaskName(mainTaskMsg);
        if (monitor.isCanceled())
            return Status.CANCEL_STATUS;
        // publish modules
        publishModules(kind, moduleList, deltaKindList, tempMulti, monitor);
        if (monitor.isCanceled())
            return Status.CANCEL_STATUS;
        monitor.done();
    } catch (CoreException ce) {
        Activator.getDefault().getPluginLogger().error("CoreException publishing to " + toString(), ce);
        return ce.getStatus();
    } catch (Exception e) {
        Activator.getDefault().getPluginLogger().error("Error publishing  to " + toString(), e);
        tempMulti.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error publishing", e));
    } finally {
        // end the publishing
        try {
            //ProgressUtil.getSubMonitorFor(monitor, 500));
            publishFinish(monitor);
        } catch (CoreException ce) {
            Activator.getDefault().getPluginLogger().error("CoreException publishing to " + toString(), ce);
            tempMulti.add(ce.getStatus());
        } catch (Exception e) {
            Activator.getDefault().getPluginLogger().error("Error stopping publish to " + toString(), e);
            tempMulti.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error publishing", e));
        }
    }
    Activator.getDefault().getPluginLogger().trace("--<-- Done publishing --<--");
    if (tempMulti.getChildren().length == 1)
        return tempMulti.getChildren()[0];
    MultiStatus multi = null;
    if (tempMulti.getSeverity() == IStatus.OK)
        return Status.OK_STATUS;
    else if (tempMulti.getSeverity() == IStatus.INFO)
        multi = new MultiStatus(Activator.PLUGIN_ID, 0, "Publishing completed with information", null);
    else if (tempMulti.getSeverity() == IStatus.WARNING)
        multi = new MultiStatus(Activator.PLUGIN_ID, 0, "Publishing completed with a warning", null);
    else if (tempMulti.getSeverity() == IStatus.ERROR)
        multi = new MultiStatus(Activator.PLUGIN_ID, 0, "Publishing failed", null);
    if (multi != null)
        multi.addAll(tempMulti);
    return multi;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus) PublishOperation(org.eclipse.wst.server.core.model.PublishOperation) CoreException(org.eclipse.core.runtime.CoreException)

Example 79 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project eclipse.platform.text by eclipse.

the class ResourceFileBuffer method validateState.

@Override
public void validateState(IProgressMonitor monitor, Object computationContext) throws CoreException {
    if (!isDisconnected() && !fIsStateValidated) {
        fStatus = null;
        fManager.fireStateChanging(this);
        try {
            if (fFile.isReadOnly()) {
                IWorkspace workspace = fFile.getWorkspace();
                fStatus = workspace.validateEdit(new IFile[] { fFile }, computationContext);
                if (fStatus.isOK())
                    handleFileContentChanged(false, false);
            }
            if (fFile.isDerived(IResource.CHECK_ANCESTORS)) {
                IStatus status = new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.DERIVED_FILE, FileBuffersMessages.ResourceFileBuffer_warning_fileIsDerived, null);
                if (fStatus == null || fStatus.isOK())
                    fStatus = status;
                else
                    fStatus = new MultiStatus(FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.STATE_VALIDATION_FAILED, new IStatus[] { fStatus, status }, FileBuffersMessages.ResourceFileBuffer_stateValidationFailed, null);
            }
        } catch (RuntimeException x) {
            fManager.fireStateChangeFailed(this);
            throw x;
        }
        fIsStateValidated = fStatus == null || fStatus.getSeverity() != IStatus.CANCEL;
        fManager.fireStateValidationChanged(this, fIsStateValidated);
    }
}
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) IFile(org.eclipse.core.resources.IFile) IWorkspace(org.eclipse.core.resources.IWorkspace) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 80 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project linuxtools by eclipse.

the class SRPMImportOperation method getStatus.

/**
 * @return The result of the operation.
 */
public MultiStatus getStatus() {
    IStatus[] errors = new IStatus[rpmErrorTable.size()];
    int iCount = 0;
    for (CoreException ex : rpmErrorTable) {
        errors[iCount] = ex.getStatus();
        iCount++;
    }
    return new // $NON-NLS-1$
    MultiStatus(// $NON-NLS-1$
    PlatformUI.PLUGIN_ID, // $NON-NLS-1$
    IStatus.OK, // $NON-NLS-1$
    errors, // $NON-NLS-1$
    Messages.getString("SRPMImportOperation.3"), null);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) 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