Search in sources :

Example 81 with ILaunchConfigurationType

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

the class ErlangNodeLaunchShortcut method getLaunchConfiguration.

private ILaunchConfiguration getLaunchConfiguration(final Collection<IErlProject> projects, final String mode) throws CoreException {
    final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    final List<String> projectNames = getProjectNames(projects);
    String name = ListsUtils.packList(projectNames, "_");
    if (name.length() > 15) {
        name = ListsUtils.packList(StringUtils.removeCommonPrefixes(projectNames), "_");
    }
    // try and find one
    final ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations();
    for (final ILaunchConfiguration launchConfiguration : launchConfigurations) {
        if (launchConfiguration.getName().equals(name)) {
            if (mode.equals(ILaunchManager.DEBUG_MODE)) {
                return addInterpretedModules(projects, launchConfiguration);
            }
            return launchConfiguration;
        }
    }
    // try and make one
    final ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(IErlangLaunchDelegateConstants.CONFIGURATION_TYPE);
    ILaunchConfigurationWorkingCopy wc;
    wc = launchConfigurationType.newInstance(null, name);
    wc.setAttribute(ErlRuntimeAttributes.PROJECTS, ListsUtils.packList(projectNames, ErlangNodeLaunchShortcut.PROJECT_NAME_SEPARATOR));
    wc.setAttribute(ErlRuntimeAttributes.RUNTIME_NAME, projects.iterator().next().getRuntimeInfo().getName());
    wc.setAttribute(ErlRuntimeAttributes.NODE_NAME, name);
    wc.setAttribute(ErlRuntimeAttributes.USE_LONG_NAME, // prefer short names
    !HostnameChecker.getInstance().canUseShortNames());
    wc.setAttribute(ErlRuntimeAttributes.CONSOLE, true);
    wc.setAttribute(ErlRuntimeAttributes.INTERNAL, false);
    wc.setAttribute(ErlRuntimeAttributes.LOAD_ALL_NODES, false);
    wc.setAttribute(ErlRuntimeAttributes.COOKIE, "erlide");
    wc.setAttribute(ErlRuntimeAttributes.WORKING_DIR, getWorkingDir(projectNames));
    final Map<String, String> map = Maps.newHashMap();
    wc.setAttribute("org.eclipse.debug.core.environmentVariables", map);
    if ("debug".equals(mode)) {
        final List<String> moduleNames = getProjectAndModuleNames(projects);
        wc.setAttribute(ErlRuntimeAttributes.DEBUG_INTERPRET_MODULES, moduleNames);
    }
    wc.setMappedResources(getProjectResources(projects));
    return wc.doSave();
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 82 with ILaunchConfigurationType

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

the class ToolExecutor method run_0.

@Deprecated
public ToolResults run_0(final String cmd0, final String args, final String wdir, final ProgressCallback progressCallback, final BuildNotifier notifier) {
    final String cmd = new Path(cmd0).isAbsolute() ? cmd0 : ToolExecutor.getToolLocation(cmd0);
    if (cmd == null) {
        ErlLogger.warn("Tool '" + cmd0 + "' can't be found in $PATH");
        return new ToolResults();
    }
    final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    final ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_BUILDER_LAUNCH_CONFIGURATION_TYPE);
    if (type == null) {
        return null;
    }
    try {
        final ILaunchConfigurationWorkingCopy launchConfig = type.newInstance(null, launchManager.generateLaunchConfigurationName("erlTool"));
        launchConfig.setAttribute(IExternalToolConstants.ATTR_LOCATION, cmd);
        launchConfig.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, args);
        launchConfig.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, wdir);
        launchConfig.setAttribute(IExternalToolConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
        launchConfig.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
        final ILaunch myLaunch = launchConfig.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor(), false, false);
        final ToolResults result = new ToolResults();
        if (myLaunch.getProcesses().length == 0) {
            ErlLogger.error("Tool process was not created?!");
            return null;
        }
        final IProcess process = myLaunch.getProcesses()[0];
        process.getStreamsProxy().getOutputStreamMonitor().addListener((text, mon) -> {
            final List<String> lines = Arrays.asList(text.split("\n"));
            if (progressCallback != null) {
                for (final String line : lines) {
                    progressCallback.stdout(line);
                }
            }
        });
        process.getStreamsProxy().getErrorStreamMonitor().addListener((text, mon) -> {
            final List<String> lines = Arrays.asList(text.split("\n"));
            if (progressCallback != null) {
                for (final String line : lines) {
                    progressCallback.stderr(line);
                }
            }
        });
        boolean done = false;
        try {
            Thread.sleep(60);
        } catch (final InterruptedException e1) {
        }
        final boolean canceled = notifier != null && notifier.isCanceled();
        while (!done && !canceled) {
            try {
                result.exit = process.getExitValue();
                done = true;
            } catch (final Exception e) {
                try {
                    Thread.sleep(60);
                } catch (final InterruptedException e1) {
                }
            }
        }
        if (canceled) {
            process.terminate();
        }
        return result;
    } catch (final CoreException e) {
        ErlLogger.error(e);
        return null;
    }
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunch(org.eclipse.debug.core.ILaunch) IProcess(org.eclipse.debug.core.model.IProcess)

Example 83 with ILaunchConfigurationType

use of org.eclipse.debug.core.ILaunchConfigurationType 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)

Example 84 with ILaunchConfigurationType

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

the class ErlangLaunchDelegate method isErlangLaunch.

public static boolean isErlangLaunch(final ILaunch aLaunch) {
    try {
        final ILaunchConfiguration cfg = aLaunch.getLaunchConfiguration();
        final ILaunchConfigurationType type = cfg.getType();
        final String id = type.getIdentifier();
        return IErlangLaunchDelegateConstants.CONFIGURATION_TYPE.equals(id) || IErlangLaunchDelegateConstants.CONFIGURATION_TYPE_INTERNAL.equals(id);
    } catch (final CoreException e) {
        ErlLogger.warn(e);
        return false;
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType)

Example 85 with ILaunchConfigurationType

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

the class BackendData method asLaunchConfiguration.

public ILaunchConfiguration asLaunchConfiguration() {
    final ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    final ILaunchConfigurationType type = manager.getLaunchConfigurationType(IErlangLaunchDelegateConstants.CONFIGURATION_TYPE_INTERNAL);
    ILaunchConfigurationWorkingCopy workingCopy;
    try {
        final RuntimeInfo info = getRuntimeInfo();
        final String name = getNodeName();
        workingCopy = type.newInstance(null, name);
        if (info.getVersion().isReleaseCompatible(new RuntimeVersion(17))) {
            workingCopy.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, Charsets.UTF_8.name());
        } else {
            workingCopy.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, Charsets.ISO_8859_1.name());
        }
        workingCopy.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, "org.erlide.backend.ertsProcessFactory");
        workingCopy.setAttribute(ErlRuntimeAttributes.NODE_NAME, getNodeName());
        workingCopy.setAttribute(ErlRuntimeAttributes.RUNTIME_NAME, info.getName());
        workingCopy.setAttribute(ErlRuntimeAttributes.COOKIE, getCookie());
        // workingCopy.setAttribute(ErlLaunchAttributes.CONSOLE,
        // !options.contains(BackendOptions.NO_CONSOLE));
        workingCopy.setAttribute(ErlRuntimeAttributes.USE_LONG_NAME, hasLongName());
        workingCopy.setAttribute(ErlRuntimeAttributes.INTERNAL, isInternal());
        workingCopy.setAttribute(ErlRuntimeAttributes.WORKING_DIR, getWorkingDir());
        return workingCopy;
    } catch (final CoreException e) {
        ErlLogger.error(e);
        return null;
    }
}
Also used : RuntimeInfo(org.erlide.runtime.runtimeinfo.RuntimeInfo) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) RuntimeVersion(org.erlide.runtime.runtimeinfo.RuntimeVersion) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Aggregations

ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)91 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)62 ILaunchManager (org.eclipse.debug.core.ILaunchManager)54 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)50 CoreException (org.eclipse.core.runtime.CoreException)43 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)8 IPath (org.eclipse.core.runtime.IPath)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 Path (org.eclipse.core.runtime.Path)6 ILaunch (org.eclipse.debug.core.ILaunch)6 File (java.io.File)5 IOException (java.io.IOException)5 Map (java.util.Map)5 IProject (org.eclipse.core.resources.IProject)5 IResource (org.eclipse.core.resources.IResource)4 IStatus (org.eclipse.core.runtime.IStatus)4 List (java.util.List)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)2