Search in sources :

Example 71 with ILaunchConfigurationWorkingCopy

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

the class SystemTapScriptLaunchConfigurationDelegate method preLaunchCheck.

@Override
public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
    // Force the configuration to use the proper Process Factory.
    if (!configuration.getAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, "").equals(SystemTapRuntimeProcessFactory.PROCESS_FACTORY_ID)) {
        // $NON-NLS-1$
        ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
        wc.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, SystemTapRuntimeProcessFactory.PROCESS_FACTORY_ID);
        wc.doSave();
    }
    // Find the parent project of the target script.
    IPath path = Path.fromOSString(configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.SCRIPT_PATH_ATTR, (String) null));
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
    scriptProject = file == null ? null : new IProject[] { file.getProject() };
    // Only save the target script's project if a project is found.
    if (scriptProject != null) {
        return super.preLaunchCheck(configuration, mode, monitor);
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IProject(org.eclipse.core.resources.IProject)

Example 72 with ILaunchConfigurationWorkingCopy

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

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

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

the class ConfigurationTest method testConfig.

/**
 * This test checks if the commands sent by SystemTap match exactly the options
 * that are set. Uses the delegate.launch() function.
 *
 * Activates all options!
 * @throws CoreException
 */
@Test
public void testConfig() throws CoreException {
    LaunchStapGraph shortcut = new LaunchStapGraph();
    String testCDirectives = "-DRandomjunk -DMoreJunk";
    String testOutputPath = "/tmp/ThisFileDoesNothingDeleteIt";
    String testBinaryPath = "/path/to/binary";
    String testScriptPath = "/tmp/NotAScriptFile.stp";
    String testArguments = "/path/to/binary";
    int testPid = 413;
    int testBuffer = 100;
    int testPass = 10;
    ILaunchConfiguration config = shortcut.outsideGetLaunchConfigType().newInstance(null, "Temp name");
    ILaunchConfigurationWorkingCopy wc = config.copy("Testing configuration");
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_VERBOSE, 1);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_KEEP_TEMPORARY, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_GURU, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_PROLOGUE_SEARCH, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_NO_CODE_ELISION, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_DISABLE_WARNINGS, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_BULK_MODE, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_TIMING_INFO, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_SKIP_BADVARS, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_IGNORE_DWARF, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_TAPSET_COVERAGE, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_LEAVE_RUNNING, true);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_PASS, testPass);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_BUFFER_BYTES, testBuffer);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_TARGET_PID, testPid);
    wc.setAttribute(LaunchConfigurationConstants.COMMAND_C_DIRECTIVES, testCDirectives);
    wc.setAttribute(LaunchConfigurationConstants.BINARY_PATH, testBinaryPath);
    wc.setAttribute(LaunchConfigurationConstants.SCRIPT_PATH, testScriptPath);
    wc.setAttribute(LaunchConfigurationConstants.ARGUMENTS, testArguments);
    wc.setAttribute(LaunchConfigurationConstants.OUTPUT_PATH, testOutputPath);
    config = wc.doSave();
    SystemTapLaunchConfigurationDelegate del = new SystemTapLaunchConfigurationDelegate();
    del.launch(config, "profile", null, null);
    assertEquals("stap -v -p" + testPass + " -k -g -P -u -w -b -t -s" + testBuffer + " -x" + testPid + " " + testCDirectives + " -F --skip-badvars --ignore-dwarf -q " + " -c '" + testBinaryPath + "' " + testScriptPath + " --runtime=dyninst " + testArguments + " >& " + testOutputPath, del.generateCommand());
    killStap();
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) LaunchStapGraph(org.eclipse.linuxtools.internal.callgraph.launch.LaunchStapGraph) SystemTapLaunchConfigurationDelegate(org.eclipse.linuxtools.internal.callgraph.launch.SystemTapLaunchConfigurationDelegate) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Test(org.junit.Test)

Example 75 with ILaunchConfigurationWorkingCopy

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

the class SystemTapTabTest method testTabs.

@Test
public void testTabs() throws CoreException {
    Shell sh = new Shell();
    Composite cmp = new Composite(sh, SWT.NONE);
    LaunchStapGraph shortCut = new LaunchStapGraph();
    SystemTapOptionsTab stp = new SystemTapOptionsTab();
    stp.createControl(cmp);
    ILaunchConfiguration configuration;
    configuration = shortCut.outsideGetLaunchConfigType().newInstance(null, (DebugPlugin.getDefault().getLaunchManager()).generateLaunchConfigurationName("invalid"));
    ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
    stp.setDefaults(wc);
    stp.performApply(wc);
    wc.doSave();
    stp.initializeFrom(configuration);
    sh.open();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) Composite(org.eclipse.swt.widgets.Composite) LaunchStapGraph(org.eclipse.linuxtools.internal.callgraph.launch.LaunchStapGraph) SystemTapOptionsTab(org.eclipse.linuxtools.internal.callgraph.launch.SystemTapOptionsTab) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Test(org.junit.Test)

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