Search in sources :

Example 76 with ILaunchConfigurationWorkingCopy

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

the class SystemTapLaunchShortcut method createConfiguration.

/**
 * Allows null configurations to be launched. Any launch that uses a binary
 * should never call this configuration with a null parameter, and any
 * launch that does not use a binary should never call this function. The
 * null handling is included for ease of testing.
 *
 * @param bin
 * @param name
 *            - Customize the name based on the shortcut being launched
 * @return A launch configuration, or null
 */
protected ILaunchConfigurationWorkingCopy createConfiguration(IBinary bin, String name) {
    ILaunchConfigurationWorkingCopy wc = null;
    if (bin != null) {
        try {
            String projectName = bin.getResource().getProjectRelativePath().toString();
            ILaunchConfigurationType configType = getLaunchConfigType();
            wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(// $NON-NLS-1$
            name + " - " + bin.getElementName()));
            wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectName);
            wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, bin.getCProject().getElementName());
            wc.setMappedResources(new IResource[] { bin.getResource(), bin.getResource().getProject() });
            wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
            setDefaultProfileAttributes(wc);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    } else {
        try {
            wc = getLaunchConfigType().newInstance(null, getLaunchManager().generateLaunchConfigurationName(name));
            setDefaultProfileAttributes(wc);
        } catch (CoreException e) {
            e.printStackTrace();
            return null;
        }
    }
    return wc;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 77 with ILaunchConfigurationWorkingCopy

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

the class SystemTapLaunchShortcut method launch.

/**
 * Default implementation of launch. It will run stap with the selected binary
 * as an argument and set the output path to <code>PluginConstants.getDefaultIOPath()</code>.
 * <br>
 * The name of the created launch will be 'DefaultSystemTapLaunch'
 */
@Override
public void launch(IBinary bin, String mode) {
    initialize();
    this.bin = bin;
    binName = getName(bin);
    // $NON-NLS-1$
    name = "DefaultSystemTapLaunch";
    try {
        ILaunchConfigurationWorkingCopy wc = createConfiguration(bin, name);
        binaryPath = bin.getResource().getLocation().toString();
        arguments = binaryPath;
        outputPath = PluginConstants.getDefaultIOPath();
        finishLaunch(name, mode, wc);
    } catch (IOException e) {
        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(// $NON-NLS-1$
        "LaunchShortcutScriptGen", // $NON-NLS-1$
        Messages.getString("LaunchStapGraph.ScriptGenErr"), // $NON-NLS-1$
        Messages.getString("LaunchStapGraph.ScriptGenErrMsg"));
        mess.schedule();
        e.printStackTrace();
    } finally {
        // $NON-NLS-1$
        resourceToSearchFor = "";
        searchForResource = false;
    }
}
Also used : SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IOException(java.io.IOException)

Example 78 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy 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 79 with ILaunchConfigurationWorkingCopy

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

the class JavaApplicationInContainerLaunchShortcut method createConfiguration.

@Override
protected ILaunchConfiguration createConfiguration(IType type) {
    ImageSelectionDialog isd = new ImageSelectionDialog();
    if (isd.open() != 0) {
        return null;
    }
    ILaunchConfiguration cfg = super.createConfiguration(type);
    try {
        ILaunchConfigurationWorkingCopy wc = cfg.getWorkingCopy();
        wc.setAttribute(JavaLaunchConfigurationConstants.CONNECTION_URI, isd.getConnection().getUri());
        wc.setAttribute(JavaLaunchConfigurationConstants.IMAGE_ID, isd.getImage().id());
        wc.doSave();
    } catch (CoreException e) {
    }
    return cfg;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 80 with ILaunchConfigurationWorkingCopy

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

the class AbstractProfilingOptionsTab method setConfigurationName.

/**
 * Set name of the launch configuration.
 *
 * @param newToolName String tool name to be appended to configuration name,
 */
protected void setConfigurationName(String newToolName) {
    try {
        String currentToolName = initial.getAttribute(ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT, // $NON-NLS-1$
        "");
        // names are different.
        if (newToolName != null && !newToolName.isEmpty() && !currentToolName.equals(newToolName)) {
            String projectName = initial.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, // $NON-NLS-1$
            "");
            // String of the form <project name> [<tool name>].
            String newConfigurationName = ProviderLaunchShortcut.generateProviderConfigurationName(projectName, newToolName);
            // Unique name of the form <project name> [<tool name>]{(<number>)}.
            String newUniqueToolName = getLaunchManager().generateLaunchConfigurationName(newConfigurationName);
            // Save changes in current configuration.
            ILaunchConfigurationWorkingCopy wc = initial.getWorkingCopy();
            wc.rename(newUniqueToolName);
            wc.setAttribute(ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT, newToolName);
            initial = wc.doSave();
            // Set name field in launch configuration dialog to avoid the
            // new configuration name from being overwritten.
            getLaunchConfigurationDialog().setName(newUniqueToolName);
        }
    } catch (CoreException e) {
    // If unable to set the name, leave the original name as is.
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Aggregations

ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)119 Test (org.junit.Test)75 ILaunch (org.eclipse.debug.core.ILaunch)52 IProcess (org.eclipse.debug.core.model.IProcess)49 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)29 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)18 CoreException (org.eclipse.core.runtime.CoreException)16 IPath (org.eclipse.core.runtime.IPath)12 ILaunchManager (org.eclipse.debug.core.ILaunchManager)10 AbstractTest (org.eclipse.linuxtools.profiling.tests.AbstractTest)8 IProject (org.eclipse.core.resources.IProject)7 Shell (org.eclipse.swt.widgets.Shell)7 ArrayList (java.util.ArrayList)6 Path (org.eclipse.core.runtime.Path)6 ILaunchConfigurationTab (org.eclipse.debug.ui.ILaunchConfigurationTab)5 Version (org.osgi.framework.Version)5 IResource (org.eclipse.core.resources.IResource)4 Launch (org.eclipse.debug.core.Launch)3 MassifViewPart (org.eclipse.linuxtools.internal.valgrind.massif.MassifViewPart)3 Button (org.eclipse.swt.widgets.Button)3