Search in sources :

Example 21 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project linuxtools by eclipse.

the class SystemTapScriptLaunch method forceRemove.

public void forceRemove() {
    removeConsole();
    runStopped = true;
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    manager.removeLaunch(this);
}
Also used : ILaunchManager(org.eclipse.debug.core.ILaunchManager)

Example 22 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project linuxtools by eclipse.

the class SystemTapScriptLaunchShortcut method findLaunchConfiguration.

private ILaunchConfiguration findLaunchConfiguration(String scriptPath, String scriptProject) {
    ILaunchConfiguration configuration = null;
    ArrayList<ILaunchConfiguration> candidateConfigurations = new ArrayList<>();
    try {
        ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
        ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(getLaunchConfigType());
        for (ILaunchConfiguration config : configs) {
            if (config.getAttribute(SystemTapScriptLaunchConfigurationTab.SCRIPT_PATH_ATTR, "").equals(scriptPath)) {
                // $NON-NLS-1$
                candidateConfigurations.add(config);
            }
        }
        int candidateCount = candidateConfigurations.size();
        if (candidateCount == 0) {
            LinkedList<String> configNames = new LinkedList<>();
            configs = launchManager.getLaunchConfigurations();
            for (ILaunchConfiguration config : configs) {
                configNames.add(config.getName());
            }
            String configName = // $NON-NLS-1$ //$NON-NLS-2$
            (scriptProject == null ? "" : scriptProject + " ") + Path.fromOSString(scriptPath).lastSegment();
            String wcName = configName;
            int conflict_index, conflict_count = 0;
            while ((conflict_index = configNames.indexOf(wcName)) != -1) {
                // $NON-NLS-1$
                wcName = configName.concat(String.format(" (%d)", ++conflict_count));
                configNames.remove(conflict_index);
            }
            ILaunchConfigurationType type = getLaunchConfigType();
            ILaunchConfigurationWorkingCopy wc = type.newInstance(null, wcName);
            wc.setAttribute(SystemTapScriptLaunchConfigurationTab.SCRIPT_PATH_ATTR, scriptPath);
            configuration = wc.doSave();
        } else if (candidateCount == 1) {
            configuration = candidateConfigurations.get(0);
        } else {
            configuration = chooseConfiguration(candidateConfigurations, ILaunchManager.RUN_MODE);
        }
    } catch (CoreException e) {
        ExceptionErrorDialog.openError(Messages.SystemTapScriptLaunchShortcut_couldNotFindConfig, e);
    }
    return configuration;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) LinkedList(java.util.LinkedList)

Example 23 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project linuxtools by eclipse.

the class VagrantConnection method rtCall.

private static void rtCall(String[] args, File vagrantDir, Map<String, String> environment) {
    // org.eclipse.core.externaltools.internal.IExternalToolConstants
    // $NON-NLS-1$
    final String EXTERNAL_TOOLS = "org.eclipse.ui.externaltools.ProgramLaunchConfigurationType";
    // $NON-NLS-1$
    final String UI_PLUGIN_ID = "org.eclipse.ui.externaltools";
    // $NON-NLS-1$
    final String ATTR_LOCATION = UI_PLUGIN_ID + ".ATTR_LOCATION";
    // $NON-NLS-1$
    final String ATTR_TOOL_ARGUMENTS = UI_PLUGIN_ID + ".ATTR_TOOL_ARGUMENTS";
    // $NON-NLS-1$
    final String ATTR_WORKING_DIRECTORY = UI_PLUGIN_ID + ".ATTR_WORKING_DIRECTORY";
    String arguments = Arrays.asList(args).stream().map(u -> u.toString()).collect(// $NON-NLS-1$
    Collectors.joining(" "));
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = manager.getLaunchConfigurationType(EXTERNAL_TOOLS);
    try {
        // TODO: worth handling 'vagrant' (not on PATH) as an alias ?
        String vagrantPath = findVagrantPath();
        ILaunchConfigurationWorkingCopy wc = type.newInstance(null, VG);
        wc.setAttribute(ATTR_LOCATION, vagrantPath);
        wc.setAttribute(ATTR_TOOL_ARGUMENTS, arguments);
        wc.setAttribute(ATTR_WORKING_DIRECTORY, vagrantDir != null ? vagrantDir.getAbsolutePath() : null);
        wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, environment);
        wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
    } catch (CoreException e1) {
        Activator.log(e1);
    }
}
Also used : Arrays(java.util.Arrays) DebugPlugin(org.eclipse.debug.core.DebugPlugin) CoreException(org.eclipse.core.runtime.CoreException) ListenerList(org.eclipse.core.runtime.ListenerList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IVagrantVM(org.eclipse.linuxtools.vagrant.core.IVagrantVM) IVagrantConnection(org.eclipse.linuxtools.vagrant.core.IVagrantConnection) Map(java.util.Map) IVagrantVMListener(org.eclipse.linuxtools.vagrant.core.IVagrantVMListener) IVagrantBox(org.eclipse.linuxtools.vagrant.core.IVagrantBox) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) Iterator(java.util.Iterator) Set(java.util.Set) IOException(java.io.IOException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Version(org.osgi.framework.Version) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) File(java.io.File) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) List(java.util.List) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Paths(java.nio.file.Paths) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Closeable(java.io.Closeable) Platform(org.eclipse.core.runtime.Platform) BufferedReader(java.io.BufferedReader) EnumVMStatus(org.eclipse.linuxtools.vagrant.core.EnumVMStatus) Collections(java.util.Collections) IVagrantBoxListener(org.eclipse.linuxtools.vagrant.core.IVagrantBoxListener) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 24 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project linuxtools by eclipse.

the class JavaAppInContainerLaunchDelegate method launch.

/* (non-Javadoc)
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    // $NON-NLS-1$
    monitor.beginTask(NLS.bind("{0}...", new String[] { configuration.getName() }), 3);
    // check for cancellation
    if (monitor.isCanceled()) {
        return;
    }
    String connectionURI = configuration.getAttribute(JavaLaunchConfigurationConstants.CONNECTION_URI, (String) null);
    String imageID = configuration.getAttribute(JavaLaunchConfigurationConstants.IMAGE_ID, (String) null);
    List<String> extraDirs = configuration.getAttribute(JavaLaunchConfigurationConstants.DIRS, Arrays.asList(new String[0]));
    try {
        DockerConnection conn = (DockerConnection) DockerConnectionManager.getInstance().getConnectionByUri(connectionURI);
        if (conn == null) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_connection_not_found_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_connection_not_found_text, connectionURI));
                }
            });
            return;
        } else if (!conn.isOpen()) {
            try {
                conn.open(false);
            } catch (DockerException e) {
            }
            if (!conn.isOpen()) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_connection_not_active_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_connection_not_active_text, connectionURI));
                    }
                });
                return;
            }
        }
        IDockerImage img = conn.getImage(imageID);
        if (img == null) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_image_not_found_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_image_not_found_text, imageID));
                }
            });
            return;
        }
        // randomized port between 1025 and 65535
        int port = ILaunchManager.DEBUG_MODE.equals(mode) ? (int) ((65535 - 1025) * Math.random()) + 1025 : -1;
        monitor.subTask(Messages.JavaAppInContainerLaunchDelegate_Verifying_launch_attributes____1);
        String mainTypeName = verifyMainTypeName(configuration);
        IVMInstall vm = new ContainerVMInstall(configuration, img, port);
        ContainerVMRunner runner = new ContainerVMRunner(vm);
        File workingDir = verifyWorkingDirectory(configuration);
        String workingDirName = null;
        if (workingDir != null) {
            workingDirName = workingDir.getAbsolutePath();
        }
        runner.setAdditionalDirectories(extraDirs);
        // Environment variables
        String[] envp = getEnvironment(configuration);
        // Program & VM arguments
        String pgmArgs = getProgramArguments(configuration);
        String vmArgs = getVMArguments(configuration);
        ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
        // VM-specific attributes
        Map<String, Object> vmAttributesMap = getVMSpecificAttributesMap(configuration);
        // Classpath
        String[] classpath = getClasspath(configuration);
        if (Platform.OS_WIN32.equals(Platform.getOS())) {
            for (int i = 0; i < classpath.length; i++) {
                classpath[i] = UnixFile.convertDOSPathToUnixPath(classpath[i]);
            }
        }
        // Create VM config
        VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath);
        runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
        runConfig.setEnvironment(envp);
        List<String> finalVMArgs = new ArrayList<>(Arrays.asList(execArgs.getVMArgumentsArray()));
        if (ILaunchManager.DEBUG_MODE.equals(mode)) {
            double version = getJavaVersion(conn, img);
            if (version < 1.5) {
                // $NON-NLS-1$
                finalVMArgs.add("-Xdebug");
                // $NON-NLS-1$
                finalVMArgs.add("-Xnoagent");
            }
            // check if java 1.4 or greater
            if (version < 1.4) {
                // $NON-NLS-1$
                finalVMArgs.add("-Djava.compiler=NONE");
            }
            if (version < 1.5) {
                // $NON-NLS-1$
                finalVMArgs.add("-Xrunjdwp:transport=dt_socket,server=y,address=" + port);
            } else {
                // $NON-NLS-1$
                finalVMArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,address=" + port);
            }
        }
        runConfig.setVMArguments(finalVMArgs.toArray(new String[0]));
        runConfig.setWorkingDirectory(workingDirName);
        runConfig.setVMSpecificAttributesMap(vmAttributesMap);
        // Bootpath
        runConfig.setBootClassPath(getBootpath(configuration));
        // check for cancellation
        if (monitor.isCanceled()) {
            return;
        }
        // stop in main
        prepareStopInMain(configuration);
        // done the verification phase
        monitor.worked(1);
        monitor.subTask(Messages.JavaAppInContainerLaunchDelegate_Creating_source_locator____2);
        // set the default source locator if required
        setDefaultSourceLocator(launch, configuration);
        monitor.worked(1);
        // Launch the configuration - 1 unit of work
        runner.run(runConfig, launch, monitor);
        // check for cancellation
        if (monitor.isCanceled()) {
            return;
        }
        if (ILaunchManager.DEBUG_MODE.equals(mode)) {
            while (runner.getIPAddress() == null || !runner.isListening()) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
            IDockerContainerInfo info = runner.getContainerInfo();
            // $NON-NLS-1$
            String configName = info.name().startsWith("/") ? info.name().substring(1) : info.name();
            ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
            ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_REMOTE_JAVA_APPLICATION);
            ILaunchConfiguration cfgForAttach = type.newInstance(null, configName);
            ILaunchConfigurationWorkingCopy wc = cfgForAttach.getWorkingCopy();
            String ip = runner.getIPAddress();
            // Can we reach it ? Or is it on a different network.
            if (!isListening(ip, port)) {
                // If the daemon is reachable via TCP it should forward traffic.
                if (conn.getSettings() instanceof TCPConnectionSettings) {
                    ip = ((TCPConnectionSettings) conn.getSettings()).getAddr();
                    if (!isListening(ip, port)) {
                        // Try to find some network interface that's listening
                        ip = getIPAddressListening(port);
                        if (!isListening(ip, port)) {
                            ip = null;
                        }
                    }
                } else {
                    ip = null;
                }
            }
            if (ip == null) {
                String imageName = conn.getImage(imageID).repoTags().get(0);
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_session_unreachable_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_session_unreachable_text, new Object[] { imageName, imageID, runner.getIPAddress() }));
                    }
                });
                return;
            }
            Map<String, String> map = new HashMap<>();
            // $NON-NLS-1$
            map.put("hostname", ip);
            // $NON-NLS-1$
            map.put("port", String.valueOf(port));
            wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, map);
            String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
            wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
            wc.doSave();
            DebugUITools.launch(cfgForAttach, ILaunchManager.DEBUG_MODE);
        }
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) VMRunnerConfiguration(org.eclipse.jdt.launching.VMRunnerConfiguration) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) DockerException(org.eclipse.linuxtools.docker.core.DockerException) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) TCPConnectionSettings(org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings) IVMInstall(org.eclipse.jdt.launching.IVMInstall) ExecutionArguments(org.eclipse.jdt.launching.ExecutionArguments) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) File(java.io.File)

Example 25 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project linuxtools by eclipse.

the class GcovLaunchConfigurationDelegate method launch.

@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    this.config = config;
    this.project = getProject();
    IPath exePath = getExePath(config);
    // then cancle the launch process.
    if (!preRequisiteCheck()) {
        return;
    }
    /*
         * this code written by QNX Software Systems and others and was
         * originally in the CDT under LocalCDILaunchDelegate::RunLocalApplication
         */
    // set up and launch the local c/c++ program
    IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(getProject());
    File workDir = getWorkingDirectory(config);
    if (workDir == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        workDir = new File(System.getProperty("user.home", "."));
    }
    String[] arguments = getProgramArgumentsArray(config);
    // add a listener for termination of the launch
    ILaunchManager lmgr = DebugPlugin.getDefault().getLaunchManager();
    lmgr.addLaunchListener(new LaunchTerminationWatcher(launch, exePath));
    // gcov.out is generated here:
    Process process = launcher.execute(exePath, arguments, getEnvironment(config), new Path(workDir.getAbsolutePath()), monitor);
    DebugPlugin.newProcess(launch, process, renderProcessLabel(exePath.toOSString()));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) ILaunchManager(org.eclipse.debug.core.ILaunchManager) File(java.io.File)

Aggregations

ILaunchManager (org.eclipse.debug.core.ILaunchManager)26 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)14 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)13 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)10 CoreException (org.eclipse.core.runtime.CoreException)8 ArrayList (java.util.ArrayList)7 ILaunch (org.eclipse.debug.core.ILaunch)6 File (java.io.File)4 IPath (org.eclipse.core.runtime.IPath)4 Path (org.eclipse.core.runtime.Path)4 LinkedList (java.util.LinkedList)3 IProcess2 (org.talend.core.model.process.IProcess2)3 Map (java.util.Map)2 IStatus (org.eclipse.core.runtime.IStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Status (org.eclipse.core.runtime.Status)2 IVMInstall (org.eclipse.jdt.launching.IVMInstall)2 IRemoteCommandLauncher (org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher)2 ProcessItem (org.talend.core.model.properties.ProcessItem)2 Project (org.talend.core.model.properties.Project)2