| author | Rafael Medeiros Teixeira | 2012-05-04 09:40:48 (EDT) |
|---|---|---|
| committer | Daniel Henrique Barboza | 2012-05-08 12:34:27 (EDT) |
| commit | e5b4d2c098f6bc0fda0b132fe24edd989e923c05 (patch) (side-by-side diff) | |
| tree | 9efea423620ff22a133b272967fb357d96bcbc64 | |
| parent | 99cfe57c1eb03e84062b1b15c8606f4425c7f9df (diff) | |
| download | org.eclipse.linuxtools-e5b4d2c098f6bc0fda0b132fe24edd989e923c05.zip org.eclipse.linuxtools-e5b4d2c098f6bc0fda0b132fe24edd989e923c05.tar.gz org.eclipse.linuxtools-e5b4d2c098f6bc0fda0b132fe24edd989e923c05.tar.bz2 | |
Change RuntimeProcessFactory to use file and process proxies
2 files changed, 101 insertions, 30 deletions
diff --git a/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF b/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF index b1fe24e..69b357f 100644 --- a/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF +++ b/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF @@ -9,7 +9,9 @@ Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime, org.eclipse.cdt.core, org.eclipse.core.resources, - org.eclipse.ui;bundle-version="3.7.0" + org.eclipse.ui;bundle-version="3.7.0", + org.eclipse.linuxtools.profiling.launch;bundle-version="0.10.0", + org.eclipse.core.filesystem;bundle-version="1.3.100" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.linuxtools.tools.launch.core.factory, diff --git a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java b/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java index b45d26b..b95b02f 100644 --- a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java +++ b/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java @@ -12,15 +12,23 @@ package org.eclipse.linuxtools.tools.launch.core.factory; import java.io.BufferedReader; -import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; +import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher; +import org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy; +import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager; /* * Create process using Runtime.getRuntime().exec and prepends the @@ -32,6 +40,9 @@ import org.eclipse.core.resources.IProject; public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { private static RuntimeProcessFactory instance = null; private static final String WHICH_CMD = "which"; //$NON-NLS-1$ + + private IRemoteFileProxy proxy; + private String[] tokenizeCommand(String command) { StringTokenizer tokenizer = new StringTokenizer(command); @@ -42,31 +53,37 @@ public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { return cmdarray; } - private String[] fillPathCommand(String[] cmdarray, String[] envp) throws IOException { - cmdarray[0] = whichCommand(cmdarray[0], envp); + private String[] fillPathCommand(String[] cmdarray, IProject project) throws IOException { + cmdarray[0] = whichCommand(cmdarray[0], project); return cmdarray; } - private String[] fillPathSudoCommand(String[] cmdarray, String[] envp) throws IOException { - cmdarray[2] = whichCommand(cmdarray[2], envp); + private String[] fillPathSudoCommand(String[] cmdarray, IProject project) throws IOException { + cmdarray[1] = whichCommand(cmdarray[1], project); return cmdarray; } public String whichCommand(String command, IProject project) throws IOException { - return whichCommand(command, updateEnvironment(null, project)); - } - - public String whichCommand(String command, String[] envp) throws IOException { - Process p = Runtime.getRuntime().exec(new String[] {WHICH_CMD, command}, envp); + + String[] envp = updateEnvironment(null, project); + try { - if (p.waitFor() == 0) { - BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); - command = reader.readLine(); - } else { - BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream())); - throw new IOException(reader.readLine()); + proxy = RemoteProxyManager.getInstance().getFileProxy(project); + URI whichUri = URI.create(WHICH_CMD); + IPath whichPath = new Path(proxy.toPath(whichUri)); + IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project); + envp = updateEnvironment(envp, project); + Process pProxy = launcher.execute(whichPath, new String[]{command}, envp, null, new NullProgressMonitor()); + if (pProxy != null){ + BufferedReader error = new BufferedReader(new InputStreamReader(pProxy.getErrorStream())); + if(error.readLine() != null){ + throw new IOException(error.readLine()); + } + BufferedReader reader = new BufferedReader(new InputStreamReader(pProxy.getInputStream())); + String readLine = reader.readLine(); + command = readLine; } - } catch (InterruptedException e) { + } catch (CoreException e) { e.printStackTrace(); } return command; @@ -94,17 +111,44 @@ public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { return exec(cmd, envp, null, project); } - public Process exec(String cmd, String[] envp, File dir, IProject project) + public Process exec(String cmd, String[] envp, IFileStore dir, IProject project) throws IOException { return exec(tokenizeCommand(cmd), envp, dir, project); } - public Process exec(String cmdarray[], String[] envp, File dir, IProject project) + public Process exec(String cmdarray[], String[] envp, IFileStore dir, IProject project) throws IOException { - envp = updateEnvironment(envp, project); - cmdarray = fillPathCommand(cmdarray, envp); + + String command = cmdarray[0]; + URI uri = URI.create(command); - return Runtime.getRuntime().exec(cmdarray, envp, dir); + Process p = null; + try { + cmdarray = fillPathCommand(cmdarray, project); + + IPath path = new Path(proxy.toPath(uri)); + IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project); + envp = updateEnvironment(envp, project); + + IPath changeToDir; + if (dir == null){ + changeToDir = null; + } else{ + changeToDir = new Path(proxy.toPath(dir.toURI())); + } + + List<String> cmdlist = new ArrayList<String>(Arrays.asList(cmdarray)); + cmdlist.remove(0); + cmdlist.toArray(cmdarray); + cmdarray = cmdlist.toArray(new String[0]); + + p = launcher.execute(path, cmdarray, envp, changeToDir , new NullProgressMonitor()); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return p; } public Process sudoExec(String cmd, IProject project) throws IOException { @@ -115,7 +159,7 @@ public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { return exec(cmd, envp, null, project); } - public Process sudoExec(String cmd, String[] envp, File dir, IProject project) + public Process sudoExec(String cmd, String[] envp, IFileStore dir, IProject project) throws IOException { return sudoExec(tokenizeCommand(cmd), envp, dir, project); } @@ -128,18 +172,43 @@ public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { return sudoExec(cmdarray, envp, null, project); } - public Process sudoExec(String[] cmdarray, String[] envp, File dir, IProject project) throws IOException { + public Process sudoExec(String[] cmdarray, String[] envp, IFileStore dir, IProject project) throws IOException { + URI uri = URI.create("sudo"); + List<String> cmdList = Arrays.asList(cmdarray); ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList); - cmdArrayList.add(0, "sudo"); - cmdArrayList.add(1, "-n"); + cmdArrayList.add(0, "-n"); String[] cmdArraySudo = new String[cmdArrayList.size()]; cmdArrayList.toArray(cmdArraySudo); - envp = updateEnvironment(envp, project); - cmdArraySudo = fillPathSudoCommand(cmdArraySudo, envp); + Process p = null; + try { + cmdArraySudo = fillPathSudoCommand(cmdArraySudo, project); + + IPath path = new Path(proxy.toPath(uri)); + IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project); + envp = updateEnvironment(envp, project); + + IPath changeToDir; + if (dir == null){ + changeToDir = null; + } else{ + changeToDir = new Path(proxy.toPath(dir.toURI())); + } + + List<String> cmdlist = new ArrayList<String>(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) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return p; - return Runtime.getRuntime().exec(cmdArraySudo, envp, dir); } } |

