Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 215063 Details for
Bug 378494
Change RuntimeProcessFactory to use file and process proxies
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch to use file and process proxies in RuntimeProcessFactory
0001-Change-RuntimeProcessFactory-to-use-file-and-process.patch (text/plain), 9.16 KB, created by
Rafael Medeiros Teixeira
on 2012-05-04 10:01:57 EDT
(
hide
)
Description:
Patch to use file and process proxies in RuntimeProcessFactory
Filename:
MIME Type:
Creator:
Rafael Medeiros Teixeira
Created:
2012-05-04 10:01:57 EDT
Size:
9.16 KB
patch
obsolete
>From 9087d1d1e183748d6282e5f2b3ac2346c94ab919 Mon Sep 17 00:00:00 2001 >From: Rafael Medeiros Teixeira <rafaelmt@linux.vnet.ibm.com> >Date: Fri, 4 May 2012 10:40:48 -0300 >Subject: [PATCH] Change RuntimeProcessFactory to use file and process proxies > >--- > .../META-INF/MANIFEST.MF | 4 +- > .../launch/core/factory/RuntimeProcessFactory.java | 127 +++++++++++++++----- > 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); > } > } >-- >1.7.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 378494
:
215063
|
215989
|
215990
|
216600
|
217547
|
217562
|
217688
|
217689