Search in sources :

Example 6 with IRemoteCommandLauncher

use of org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher 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)

Example 7 with IRemoteCommandLauncher

use of org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher in project linuxtools by eclipse.

the class GprofLaunchConfigurationDelegate method launch.

/**
 *  Checks if neccessary flags are set in Managed Build/Autotools <br>
 *  If they are not, asks the user if he want's to have them addded. <br>
 *  If so, it enables the option, rebuilds the project and continues with launch </p>
 *
 *  <p> Otherwise by this time the project is already build and it proceeds with launch of the plugin. </p>
 */
@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    // Save passed variables. useful later.
    this.config = config;
    this.project = getProject();
    // then cancle the launch process as there won't a gmon.out anyway.
    if (!preRequisiteCheck()) {
        return;
    }
    IPath exePath = getExePath(config);
    /*
         * 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));
    // gmon.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)

Example 8 with IRemoteCommandLauncher

use of org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher in project linuxtools by eclipse.

the class RuntimeProcessFactory method sudoExec.

/**
 * Execute one command, as root, using the path selected in 'Linux Tools Path'
 * preference page in the informed project.
 * @param cmdarray An array with the command to be executed and its params.
 * @param envp An array with extra enviroment variables to be used when running
 * the command
 * @param dir The directory used as current directory to run the command.
 * @param project The current project. If null, only system path will be
 * used to look for the command.
 * @return The process started by sudoExec
 *
 * @since 1.1
 */
private Process sudoExec(String[] cmdarray, String[] envp, IFileStore dir, IProject project) throws IOException {
    // $NON-NLS-1$
    URI uri = URI.create("sudo");
    List<String> cmdList = Arrays.asList(cmdarray);
    ArrayList<String> cmdArrayList = new ArrayList<>(cmdList);
    // $NON-NLS-1$
    cmdArrayList.add(0, "-n");
    String[] cmdArraySudo = new String[cmdArrayList.size()];
    cmdArrayList.toArray(cmdArraySudo);
    Process p = null;
    try {
        cmdArraySudo = fillPathSudoCommand(cmdArraySudo, project);
        IRemoteCommandLauncher launcher;
        IPath changeToDir = null, path;
        if (project != null) {
            IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project);
            path = new Path(proxy.toPath(uri));
            launcher = RemoteProxyManager.getInstance().getLauncher(project);
            envp = updateEnvironment(envp, project);
            if (dir != null) {
                changeToDir = new Path(proxy.toPath(dir.toURI()));
            }
        } else {
            launcher = RemoteProxyManager.getInstance().getLauncher(uri);
            path = new Path(uri.getPath());
            if (dir != null) {
                changeToDir = new Path(dir.toURI().getPath());
            }
        }
        List<String> cmdlist = new ArrayList<>(Arrays.asList(cmdArraySudo));
        cmdlist.remove(0);
        cmdlist.toArray(cmdArraySudo);
        cmdArraySudo = cmdlist.toArray(new String[0]);
        p = launcher.execute(path, cmdArraySudo, envp, changeToDir, new NullProgressMonitor());
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return p;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) ArrayList(java.util.ArrayList) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)

Example 9 with IRemoteCommandLauncher

use of org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher in project linuxtools by eclipse.

the class RuntimeProcessFactory method whichCommand.

/**
 * Used to get the full command path. It will look for the command in the
 * system path and in the path selected in 'Linux Tools Path' preference page
 * in the informed project.
 *
 * @param command The desired command
 * @param project The current project. If null, only system path will be
 * used to look for the command.
 * @return The full command path if command was found or the command if
 * command was not found.
 * @throws IOException If problem executing the command occured.
 *
 * @since 1.1
 */
public String whichCommand(String command, IProject project) throws IOException {
    String[] envp = updateEnvironment(null, project);
    try {
        IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project);
        URI whichUri;
        // For Windows, we use the where command, otherwise, we use the Unix which command
        if ((project != null && Platform.OS_WIN32.equals(RemoteProxyManager.getInstance().getOS(project))) || Platform.OS_WIN32.equals(Platform.getOS())) {
            whichUri = URI.create(WHERE_CMD);
        } else {
            whichUri = URI.create(WHICH_CMD);
        }
        IPath whichPath = new Path(proxy.toPath(whichUri));
        IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project);
        Process pProxy = launcher.execute(whichPath, new String[] { command }, envp, null, new NullProgressMonitor());
        if (pProxy != null) {
            ArrayList<String> lines = new ArrayList<>();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(pProxy.getInputStream()))) {
                String readLine = reader.readLine();
                while (readLine != null) {
                    lines.add(readLine);
                    readLine = reader.readLine();
                }
            }
            if (!lines.isEmpty()) {
                if (project != null && project.getLocationURI() != null) {
                    if (project.getLocationURI().toString().startsWith("rse:")) {
                        // RSE output
                        if (lines.size() > 1) {
                            command = lines.get(lines.size() - 2);
                        }
                    } else {
                        // Remotetools or o.e.Remote output
                        command = lines.get(0);
                    }
                } else {
                    // Local output
                    command = lines.get(0);
                }
            }
        }
    } catch (CoreException e) {
        throw new IOException(e);
    }
    // Command is not found
    return command;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) InputStreamReader(java.io.InputStreamReader) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) BufferedReader(java.io.BufferedReader)

Aggregations

IRemoteCommandLauncher (org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher)9 IPath (org.eclipse.core.runtime.IPath)7 Path (org.eclipse.core.runtime.Path)7 CoreException (org.eclipse.core.runtime.CoreException)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)3 AbstractProxyTest (org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest)3 Test (org.junit.Test)3 File (java.io.File)2 InputStream (java.io.InputStream)2 ILaunchManager (org.eclipse.debug.core.ILaunchManager)2 LocalLauncher (org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher)2 RDTCommandLauncher (org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 SSHCommandLauncher (org.eclipse.linuxtools.internal.ssh.proxy.SSHCommandLauncher)1 IRemoteProxyManager (org.eclipse.linuxtools.profiling.launch.IRemoteProxyManager)1