Search in sources :

Example 1 with IStatusHandler

use of org.eclipse.debug.core.IStatusHandler in project statecharts by Yakindu.

the class AbstractSimulationEngine method handleException.

protected void handleException(Throwable t) {
    if (t instanceof WrappedException) {
        t = ((WrappedException) t).getCause();
    }
    String statusMessage = t.getMessage() == null ? ERROR_MSG : t.getMessage();
    Status errorStatus = new Status(Status.ERROR, SimulationCoreActivator.PLUGIN_ID, ERROR_DURING_SIMULATION, statusMessage, t);
    SimulationCoreActivator.getDefault().getLog().log(errorStatus);
    IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(errorStatus);
    try {
        statusHandler.handleStatus(errorStatus, getDebugTarget());
    } catch (CoreException e) {
        e.printStackTrace();
    } finally {
        terminate();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) WrappedException(org.eclipse.emf.common.util.WrappedException) CoreException(org.eclipse.core.runtime.CoreException) IStatusHandler(org.eclipse.debug.core.IStatusHandler)

Example 2 with IStatusHandler

use of org.eclipse.debug.core.IStatusHandler in project statecharts by Yakindu.

the class AbstractExecutionFlowSimulationEngine method init.

@Override
public void init() {
    try {
        ListBasedValidationIssueAcceptor acceptor = new ListBasedValidationIssueAcceptor();
        ExecutionFlow flow = sequencer.transform(statechart, acceptor);
        if (acceptor.getTraces(Severity.ERROR).size() > 0) {
            Status errorStatus = new Status(Status.ERROR, SimulationCoreActivator.PLUGIN_ID, ERROR_DURING_SIMULATION, acceptor.getTraces(Severity.ERROR).iterator().next().toString(), null);
            IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(errorStatus);
            try {
                statusHandler.handleStatus(errorStatus, getDebugTarget());
            } catch (CoreException e) {
                e.printStackTrace();
            }
        }
        if (!context.isSnapshot()) {
            contextInitializer.initialize(context, flow);
        }
        interpreter.initialize(flow, context, useInternalEventQueue());
    } catch (Exception ex) {
        handleException(ex);
        throw new InitializationException(ex.getMessage());
    }
}
Also used : ListBasedValidationIssueAcceptor(org.yakindu.base.types.validation.IValidationIssueAcceptor.ListBasedValidationIssueAcceptor) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) IStatusHandler(org.eclipse.debug.core.IStatusHandler) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) InitializationException(org.yakindu.sct.simulation.core.launch.AbstractSCTLaunchConfigurationDelegate.InitializationException) InitializationException(org.yakindu.sct.simulation.core.launch.AbstractSCTLaunchConfigurationDelegate.InitializationException) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with IStatusHandler

use of org.eclipse.debug.core.IStatusHandler in project bndtools by bndtools.

the class AbstractOSGiLaunchDelegate method finalLaunchCheck.

@Override
public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
    // Check for existing launches of same resource
    BndPreferences prefs = new BndPreferences();
    if (prefs.getWarnExistingLaunches()) {
        IResource launchResource = LaunchUtils.getTargetResource(configuration);
        if (launchResource == null)
            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Bnd launch target was not specified or does not exist.", null));
        int processCount = 0;
        for (ILaunch l : DebugPlugin.getDefault().getLaunchManager().getLaunches()) {
            // ... is it the same launch resource?
            ILaunchConfiguration launchConfig = l.getLaunchConfiguration();
            if (launchConfig == null) {
                continue;
            }
            if (launchResource.equals(LaunchUtils.getTargetResource(launchConfig))) {
                // Iterate existing processes
                for (IProcess process : l.getProcesses()) {
                    if (!process.isTerminated())
                        processCount++;
                }
            }
        }
        // Warn if existing processes running
        if (processCount > 0) {
            Status status = new Status(IStatus.WARNING, Plugin.PLUGIN_ID, 0, "One or more OSGi Frameworks have already been launched for this configuration. Additional framework instances may interfere with each other due to the shared storage directory.", null);
            IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(status);
            if (prompter != null) {
                boolean okay = (Boolean) prompter.handleStatus(status, launchResource);
                if (!okay)
                    return okay;
            }
        }
    }
    IStatus launchStatus = getLauncherStatus();
    IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(launchStatus);
    if (prompter != null)
        return (Boolean) prompter.handleStatus(launchStatus, run);
    return true;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IStatus(org.eclipse.core.runtime.IStatus) BndPreferences(bndtools.preferences.BndPreferences) CoreException(org.eclipse.core.runtime.CoreException) IStatusHandler(org.eclipse.debug.core.IStatusHandler) ILaunch(org.eclipse.debug.core.ILaunch) IProcess(org.eclipse.debug.core.model.IProcess) IResource(org.eclipse.core.resources.IResource)

Example 4 with IStatusHandler

use of org.eclipse.debug.core.IStatusHandler in project bndtools by bndtools.

the class OSGiJUnitLaunchDelegate method finalLaunchCheck.

@Override
public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
    boolean result = super.finalLaunchCheck(configuration, mode, monitor);
    // Trigger opening of the JUnit view
    Status junitStatus = new Status(IStatus.INFO, Plugin.PLUGIN_ID, LaunchConstants.LAUNCH_STATUS_JUNIT, "", null);
    IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(junitStatus);
    if (handler != null)
        handler.handleStatus(junitStatus, null);
    return result;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatusHandler(org.eclipse.debug.core.IStatusHandler)

Example 5 with IStatusHandler

use of org.eclipse.debug.core.IStatusHandler in project bndtools by bndtools.

the class NativeBndLaunchDelegate method launch.

/*
     * The Eclipse launch interface.
     */
@Override
public void launch(ILaunchConfiguration configuration, String mode, final ILaunch launch, IProgressMonitor m) throws CoreException {
    final IProgressMonitor monitor = m == null ? new NullProgressMonitor() : m;
    Callable<Boolean> isCancelled = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return canceled || monitor.isCanceled();
        }
    };
    Processor p = new Processor();
    try {
        monitor.setTaskName("Detecting if configuration is already launched");
        if (isAlreadyRunning(configuration)) {
            return;
        }
        String target = configuration.getAttribute(LaunchConstants.ATTR_LAUNCH_TARGET, (String) null);
        if (target == null || target.length() == 0) {
            p.error("No target specified in the launch configuration");
            return;
        }
        IResource targetResource = ResourcesPlugin.getWorkspace().getRoot().findMember(target);
        if (targetResource == null) {
            p.error("No actual resource found for " + target);
            return;
        }
        IProject parent = targetResource.getProject();
        if (parent == null) {
            p.error("Not part of a project " + targetResource);
            return;
        }
        Project parentModel = Central.getProject(parent);
        if (parentModel == null) {
            p.error("Cannot locate Bnd project for " + targetResource);
            return;
        }
        Project model;
        if (targetResource.getName().equals(Project.BNDFILE)) {
            model = parentModel;
        } else {
            File file = targetResource.getLocation().toFile();
            if (file == null || !file.isFile()) {
                p.error("No file associated with the entry " + targetResource);
                return;
            }
            model = new Run(parentModel.getWorkspace(), parentModel.getBase(), file);
        }
        monitor.setTaskName("Target is " + model);
        boolean debug = "debug".equals(mode);
        try {
            List<LaunchThread> lts = new ArrayList<LaunchThread>();
            ProjectLauncher projectLauncher = model.getProjectLauncher();
            try {
                List<? extends RunSession> sessions = projectLauncher.getRunSessions();
                if (sessions == null) {
                    projectLauncher.error("This launcher for %s cannot handle the new style", target);
                    return;
                }
                for (RunSession session : sessions) try {
                    monitor.setTaskName("validating session " + session.getLabel());
                    if (!session.validate(isCancelled)) {
                        continue;
                    }
                    LaunchThread lt = new LaunchThread(projectLauncher, session, launch);
                    if (debug) {
                        lt.doDebug(monitor);
                    }
                    if (monitor.isCanceled())
                        return;
                    launch.addProcess(lt);
                    lts.add(lt);
                } catch (Exception e) {
                    projectLauncher.exception(e, "Starting session %s in project %s", session.getName(), model);
                }
            } catch (Exception e) {
                projectLauncher.exception(e, "starting processes");
            } finally {
                p.getInfo(projectLauncher);
            }
            if (!p.isOk()) {
                IStatus status = Central.toStatus(projectLauncher, "Errors detected during the launch");
                IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(status);
                Boolean cont = (Boolean) prompter.handleStatus(status, null);
                if (cont == null || !cont || monitor.isCanceled()) {
                    launch.terminate();
                    return;
                }
            }
            for (LaunchThread lt : lts) {
                lt.start();
            }
        } catch (Exception e) {
            launch.terminate();
            abort("Internal error", e, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
        }
    } catch (Exception e) {
        p.exception(e, "While starting a launch %s", configuration);
    } finally {
        if (!p.isOk()) {
            IStatus status = Central.toStatus(p, "Errors detected during the launch");
            IStatusHandler prompter = new LaunchStatusHandler();
            prompter.handleStatus(status, null);
            launch.terminate();
        }
        monitor.done();
        IO.close(p);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Processor(aQute.bnd.osgi.Processor) ArrayList(java.util.ArrayList) ProjectLauncher(aQute.bnd.build.ProjectLauncher) Run(aQute.bnd.build.Run) Callable(java.util.concurrent.Callable) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatusHandler(org.eclipse.debug.core.IStatusHandler) RunSession(aQute.bnd.build.RunSession) File(java.io.File) IResource(org.eclipse.core.resources.IResource) LaunchStatusHandler(bndtools.launch.ui.internal.LaunchStatusHandler)

Aggregations

IStatusHandler (org.eclipse.debug.core.IStatusHandler)6 Status (org.eclipse.core.runtime.Status)5 CoreException (org.eclipse.core.runtime.CoreException)4 IStatus (org.eclipse.core.runtime.IStatus)4 IResource (org.eclipse.core.resources.IResource)3 BndPreferences (bndtools.preferences.BndPreferences)2 ILaunch (org.eclipse.debug.core.ILaunch)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 IProcess (org.eclipse.debug.core.model.IProcess)2 Project (aQute.bnd.build.Project)1 ProjectLauncher (aQute.bnd.build.ProjectLauncher)1 Run (aQute.bnd.build.Run)1 RunSession (aQute.bnd.build.RunSession)1 Processor (aQute.bnd.osgi.Processor)1 LaunchStatusHandler (bndtools.launch.ui.internal.LaunchStatusHandler)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1