Search in sources :

Example 1 with ILaunchConfigurationDelegate

use of org.eclipse.debug.core.model.ILaunchConfigurationDelegate in project n4js by eclipse.

the class RunnerUiUtils method getRunnerId.

/**
 * Read the N4JS runner ID from the given Eclipse launch configuration type. Will throw exceptions if 'failFast' is
 * <code>true</code>, otherwise will return <code>null</code> in case of error.
 */
public static String getRunnerId(ILaunchConfigurationType launchConfigType, boolean failFast) {
    final Set<Set<String>> modeCombis = launchConfigType.getSupportedModeCombinations();
    final Set<String> runnerIds = new HashSet<>();
    for (Set<String> modeCombi : modeCombis) {
        final ILaunchDelegate[] delegates;
        try {
            delegates = launchConfigType.getDelegates(modeCombi);
        } catch (CoreException e) {
            continue;
        }
        for (ILaunchDelegate launchDelegate : delegates) {
            final ILaunchConfigurationDelegate launchConfigDelegate;
            try {
                launchConfigDelegate = launchDelegate.getDelegate();
            } catch (CoreException e) {
                throw new WrappedException("error while getting launch configuration delegate from launch delegate", e);
            }
            if (launchConfigDelegate instanceof IDERunnerDelegate) {
                final String runnerId = ((IDERunnerDelegate) launchConfigDelegate).getRunnerId();
                if (runnerId != null)
                    runnerIds.add(runnerId);
            }
        }
    }
    if (runnerIds.size() == 1)
        return runnerIds.iterator().next();
    if (failFast) {
        if (runnerIds.isEmpty()) {
            throw new IllegalStateException("cannot find an N4JS runner ID for the launch configuration type with ID: " + launchConfigType.getIdentifier());
        } else {
            // runnerIds.size() > 1
            throw new IllegalStateException("several N4JS runner IDs used for a single ILaunchConfigurationType: " + launchConfigType.getIdentifier());
        }
    }
    return null;
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) HashSet(java.util.HashSet) Set(java.util.Set) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationDelegate(org.eclipse.debug.core.model.ILaunchConfigurationDelegate) ILaunchDelegate(org.eclipse.debug.core.ILaunchDelegate) HashSet(java.util.HashSet)

Example 2 with ILaunchConfigurationDelegate

use of org.eclipse.debug.core.model.ILaunchConfigurationDelegate in project erlide_eclipse by erlang.

the class DebugTraceLaunching method launch.

public static void launch(final IDebugTarget target, final DebuggerTraceView debuggerTraceView) {
    if (target == null) {
        return;
    }
    try {
        final ILaunchConfigurationType lcType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType("org.erlide.runtime.debug.launchDebugTrace");
        final String name = target.toString();
        final ILaunchConfigurationWorkingCopy wc = lcType.newInstance(null, name);
        final Set<String> modes = new HashSet<>();
        modes.add(ILaunchManager.DEBUG_MODE);
        final ILaunchDelegate[] delegates = lcType.getDelegates(modes);
        final ILaunchConfigurationDelegate delegate = delegates[0].getDelegate();
        if (!(delegate instanceof DebugTraceLaunchConfigurationDelegate)) {
            return;
        }
        final DebugTraceLaunchConfigurationDelegate ldtlcd = (DebugTraceLaunchConfigurationDelegate) delegate;
        ldtlcd.setInfo(target.getLaunch(), target, debuggerTraceView.getEventsForLaunch(target));
        wc.launch(ILaunchManager.DEBUG_MODE, null);
    } catch (final CoreException e) {
        ErlLogger.error(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationDelegate(org.eclipse.debug.core.model.ILaunchConfigurationDelegate) ILaunchDelegate(org.eclipse.debug.core.ILaunchDelegate) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 CoreException (org.eclipse.core.runtime.CoreException)2 ILaunchDelegate (org.eclipse.debug.core.ILaunchDelegate)2 ILaunchConfigurationDelegate (org.eclipse.debug.core.model.ILaunchConfigurationDelegate)2 Set (java.util.Set)1 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1