|
Lines 15-26
import java.io.BufferedReader;
Link Here
|
| 15 |
import java.io.File; |
15 |
import java.io.File; |
| 16 |
import java.io.IOException; |
16 |
import java.io.IOException; |
| 17 |
import java.io.InputStreamReader; |
17 |
import java.io.InputStreamReader; |
|
|
18 |
import java.net.URI; |
| 18 |
import java.util.ArrayList; |
19 |
import java.util.ArrayList; |
| 19 |
import java.util.Arrays; |
20 |
import java.util.Arrays; |
| 20 |
import java.util.List; |
21 |
import java.util.List; |
| 21 |
import java.util.StringTokenizer; |
22 |
import java.util.StringTokenizer; |
| 22 |
|
23 |
|
|
|
24 |
import org.eclipse.core.filesystem.IFileStore; |
| 23 |
import org.eclipse.core.resources.IProject; |
25 |
import org.eclipse.core.resources.IProject; |
|
|
26 |
import org.eclipse.core.runtime.CoreException; |
| 27 |
import org.eclipse.core.runtime.IPath; |
| 28 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 29 |
import org.eclipse.core.runtime.Path; |
| 30 |
import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher; |
| 31 |
import org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy; |
| 32 |
import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager; |
| 24 |
|
33 |
|
| 25 |
/* |
34 |
/* |
| 26 |
* Create process using Runtime.getRuntime().exec and prepends the |
35 |
* Create process using Runtime.getRuntime().exec and prepends the |
|
Lines 42-61
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 42 |
return cmdarray; |
51 |
return cmdarray; |
| 43 |
} |
52 |
} |
| 44 |
|
53 |
|
|
|
54 |
private String[] fillPathCommand(String[] cmdarray, IProject project) throws IOException { |
| 55 |
cmdarray[0] = whichCommand(cmdarray[0], project); |
| 56 |
return cmdarray; |
| 57 |
} |
| 58 |
|
| 59 |
@Deprecated |
| 45 |
private String[] fillPathCommand(String[] cmdarray, String[] envp) throws IOException { |
60 |
private String[] fillPathCommand(String[] cmdarray, String[] envp) throws IOException { |
| 46 |
cmdarray[0] = whichCommand(cmdarray[0], envp); |
61 |
cmdarray[0] = whichCommand(cmdarray[0], envp); |
| 47 |
return cmdarray; |
62 |
return cmdarray; |
| 48 |
} |
63 |
} |
| 49 |
|
64 |
|
|
|
65 |
@Deprecated |
| 50 |
private String[] fillPathSudoCommand(String[] cmdarray, String[] envp) throws IOException { |
66 |
private String[] fillPathSudoCommand(String[] cmdarray, String[] envp) throws IOException { |
| 51 |
cmdarray[2] = whichCommand(cmdarray[2], envp); |
67 |
cmdarray[2] = whichCommand(cmdarray[2], envp); |
| 52 |
return cmdarray; |
68 |
return cmdarray; |
| 53 |
} |
69 |
} |
| 54 |
|
70 |
|
| 55 |
public String whichCommand(String command, IProject project) throws IOException { |
71 |
private String[] fillPathSudoCommand(String[] cmdarray, IProject project) throws IOException { |
| 56 |
return whichCommand(command, updateEnvironment(null, project)); |
72 |
cmdarray[1] = whichCommand(cmdarray[1], project); |
|
|
73 |
return cmdarray; |
| 57 |
} |
74 |
} |
| 58 |
|
75 |
|
|
|
76 |
@Deprecated |
| 59 |
public String whichCommand(String command, String[] envp) throws IOException { |
77 |
public String whichCommand(String command, String[] envp) throws IOException { |
| 60 |
Process p = Runtime.getRuntime().exec(new String[] {WHICH_CMD, command}, envp); |
78 |
Process p = Runtime.getRuntime().exec(new String[] {WHICH_CMD, command}, envp); |
| 61 |
try { |
79 |
try { |
|
Lines 72-77
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 72 |
return command; |
90 |
return command; |
| 73 |
} |
91 |
} |
| 74 |
|
92 |
|
|
|
93 |
public String whichCommand(String command, IProject project) throws IOException { |
| 94 |
if (project != null) { |
| 95 |
String[] envp = updateEnvironment(null, project); |
| 96 |
try { |
| 97 |
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project); |
| 98 |
URI whichUri = URI.create(WHICH_CMD); |
| 99 |
IPath whichPath = new Path(proxy.toPath(whichUri)); |
| 100 |
IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project); |
| 101 |
Process pProxy = launcher.execute(whichPath, new String[]{command}, envp, null, new NullProgressMonitor()); |
| 102 |
if (pProxy != null){ |
| 103 |
BufferedReader error = new BufferedReader(new InputStreamReader(pProxy.getErrorStream())); |
| 104 |
if(error.readLine() != null){ |
| 105 |
throw new IOException(error.readLine()); |
| 106 |
} |
| 107 |
BufferedReader reader = new BufferedReader(new InputStreamReader(pProxy.getInputStream())); |
| 108 |
String readLine = reader.readLine(); |
| 109 |
command = readLine; |
| 110 |
} |
| 111 |
} catch (CoreException e) { |
| 112 |
e.printStackTrace(); |
| 113 |
} |
| 114 |
} |
| 115 |
return command; |
| 116 |
} |
| 117 |
|
| 75 |
public static RuntimeProcessFactory getFactory() { |
118 |
public static RuntimeProcessFactory getFactory() { |
| 76 |
if (instance == null) |
119 |
if (instance == null) |
| 77 |
instance = new RuntimeProcessFactory(); |
120 |
instance = new RuntimeProcessFactory(); |
|
Lines 79-85
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 79 |
} |
122 |
} |
| 80 |
|
123 |
|
| 81 |
public Process exec(String cmd, IProject project) throws IOException { |
124 |
public Process exec(String cmd, IProject project) throws IOException { |
| 82 |
return exec(cmd, null, null, project); |
125 |
return exec(cmd, null, (IFileStore)null, project); |
| 83 |
} |
126 |
} |
| 84 |
|
127 |
|
| 85 |
public Process exec(String[] cmdarray, IProject project) throws IOException { |
128 |
public Process exec(String[] cmdarray, IProject project) throws IOException { |
|
Lines 87-104
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 87 |
} |
130 |
} |
| 88 |
|
131 |
|
| 89 |
public Process exec(String[] cmdarray, String[] envp, IProject project) throws IOException { |
132 |
public Process exec(String[] cmdarray, String[] envp, IProject project) throws IOException { |
| 90 |
return exec(cmdarray, envp, null, project); |
133 |
return exec(cmdarray, envp, (IFileStore)null, project); |
| 91 |
} |
134 |
} |
| 92 |
|
135 |
|
| 93 |
public Process exec(String cmd, String[] envp, IProject project) throws IOException { |
136 |
public Process exec(String cmd, String[] envp, IProject project) throws IOException { |
| 94 |
return exec(cmd, envp, null, project); |
137 |
return exec(cmd, envp, (IFileStore)null, project); |
| 95 |
} |
138 |
} |
| 96 |
|
139 |
|
|
|
140 |
@Deprecated |
| 97 |
public Process exec(String cmd, String[] envp, File dir, IProject project) |
141 |
public Process exec(String cmd, String[] envp, File dir, IProject project) |
| 98 |
throws IOException { |
142 |
throws IOException { |
| 99 |
return exec(tokenizeCommand(cmd), envp, dir, project); |
143 |
return exec(tokenizeCommand(cmd), envp, dir, project); |
| 100 |
} |
144 |
} |
| 101 |
|
145 |
|
|
|
146 |
public Process exec(String cmd, String[] envp, IFileStore dir, IProject project) |
| 147 |
throws IOException { |
| 148 |
return exec(tokenizeCommand(cmd), envp, dir, project); |
| 149 |
} |
| 150 |
|
| 151 |
@Deprecated |
| 102 |
public Process exec(String cmdarray[], String[] envp, File dir, IProject project) |
152 |
public Process exec(String cmdarray[], String[] envp, File dir, IProject project) |
| 103 |
throws IOException { |
153 |
throws IOException { |
| 104 |
envp = updateEnvironment(envp, project); |
154 |
envp = updateEnvironment(envp, project); |
|
Lines 106-133
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 106 |
|
156 |
|
| 107 |
return Runtime.getRuntime().exec(cmdarray, envp, dir); |
157 |
return Runtime.getRuntime().exec(cmdarray, envp, dir); |
| 108 |
} |
158 |
} |
|
|
159 |
|
| 160 |
public Process exec(String cmdarray[], String[] envp, IFileStore dir, IProject project) |
| 161 |
throws IOException { |
| 162 |
|
| 163 |
Process p = null; |
| 164 |
try { |
| 165 |
cmdarray = fillPathCommand(cmdarray, project); |
| 166 |
|
| 167 |
String command = cmdarray[0]; |
| 168 |
URI uri = URI.create(command); |
| 169 |
|
| 170 |
IPath changeToDir = null; |
| 171 |
IPath path; |
| 172 |
IRemoteCommandLauncher launcher; |
| 173 |
|
| 174 |
if (project != null) { |
| 175 |
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project); |
| 176 |
path = new Path(proxy.toPath(uri)); |
| 177 |
launcher = RemoteProxyManager.getInstance().getLauncher(project); |
| 178 |
envp = updateEnvironment(envp, project); |
| 179 |
if (dir != null) |
| 180 |
changeToDir = new Path(proxy.toPath(dir.toURI())); |
| 181 |
} else { |
| 182 |
path = new Path(uri.getPath()); |
| 183 |
launcher = RemoteProxyManager.getInstance().getLauncher(uri); |
| 184 |
if (dir != null) |
| 185 |
changeToDir = new Path(dir.toURI().getPath()); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
List<String> cmdlist = new ArrayList<String>(Arrays.asList(cmdarray)); |
| 190 |
cmdlist.remove(0); |
| 191 |
cmdlist.toArray(cmdarray); |
| 192 |
cmdarray = cmdlist.toArray(new String[0]); |
| 193 |
|
| 194 |
p = launcher.execute(path, cmdarray, envp, changeToDir , new NullProgressMonitor()); |
| 195 |
} catch (CoreException e) { |
| 196 |
e.printStackTrace(); |
| 197 |
} |
| 198 |
|
| 199 |
return p; |
| 200 |
} |
| 109 |
|
201 |
|
| 110 |
public Process sudoExec(String cmd, IProject project) throws IOException { |
202 |
public Process sudoExec(String cmd, IProject project) throws IOException { |
| 111 |
return sudoExec(cmd, null, null, project); |
203 |
return sudoExec(cmd, null, (IFileStore)null, project); |
| 112 |
} |
204 |
} |
| 113 |
|
205 |
|
| 114 |
public Process sudoExec(String cmd, String[] envp, IProject project) throws IOException { |
206 |
public Process sudoExec(String cmd, String[] envp, IProject project) throws IOException { |
| 115 |
return exec(cmd, envp, null, project); |
207 |
return exec(cmd, envp, (IFileStore)null, project); |
| 116 |
} |
208 |
} |
| 117 |
|
209 |
|
|
|
210 |
@Deprecated |
| 118 |
public Process sudoExec(String cmd, String[] envp, File dir, IProject project) |
211 |
public Process sudoExec(String cmd, String[] envp, File dir, IProject project) |
| 119 |
throws IOException { |
212 |
throws IOException { |
| 120 |
return sudoExec(tokenizeCommand(cmd), envp, dir, project); |
213 |
return sudoExec(tokenizeCommand(cmd), envp, dir, project); |
| 121 |
} |
214 |
} |
|
|
215 |
|
| 216 |
public Process sudoExec(String cmd, String[] envp, IFileStore dir, IProject project) |
| 217 |
throws IOException { |
| 218 |
return sudoExec(tokenizeCommand(cmd), envp, dir, project); |
| 219 |
} |
| 122 |
|
220 |
|
| 123 |
public Process sudoExec(String[] cmdarray, IProject project) throws IOException { |
221 |
public Process sudoExec(String[] cmdarray, IProject project) throws IOException { |
| 124 |
return sudoExec(cmdarray, null, project); |
222 |
return sudoExec(cmdarray, null, project); |
| 125 |
} |
223 |
} |
| 126 |
|
224 |
|
| 127 |
public Process sudoExec(String[] cmdarray, String[] envp, IProject project) throws IOException { |
225 |
public Process sudoExec(String[] cmdarray, String[] envp, IProject project) throws IOException { |
| 128 |
return sudoExec(cmdarray, envp, null, project); |
226 |
return sudoExec(cmdarray, envp, (IFileStore)null, project); |
| 129 |
} |
227 |
} |
| 130 |
|
228 |
|
|
|
229 |
@Deprecated |
| 131 |
public Process sudoExec(String[] cmdarray, String[] envp, File dir, IProject project) throws IOException { |
230 |
public Process sudoExec(String[] cmdarray, String[] envp, File dir, IProject project) throws IOException { |
| 132 |
List<String> cmdList = Arrays.asList(cmdarray); |
231 |
List<String> cmdList = Arrays.asList(cmdarray); |
| 133 |
ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList); |
232 |
ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList); |
|
Lines 142-145
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 142 |
|
241 |
|
| 143 |
return Runtime.getRuntime().exec(cmdArraySudo, envp, dir); |
242 |
return Runtime.getRuntime().exec(cmdArraySudo, envp, dir); |
| 144 |
} |
243 |
} |
|
|
244 |
|
| 245 |
public Process sudoExec(String[] cmdarray, String[] envp, IFileStore dir, IProject project) throws IOException { |
| 246 |
URI uri = URI.create("sudo"); //$NON-NLS-1$ |
| 247 |
|
| 248 |
List<String> cmdList = Arrays.asList(cmdarray); |
| 249 |
ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList); |
| 250 |
cmdArrayList.add(0, "-n"); //$NON-NLS-1$ |
| 251 |
|
| 252 |
String[] cmdArraySudo = new String[cmdArrayList.size()]; |
| 253 |
cmdArrayList.toArray(cmdArraySudo); |
| 254 |
|
| 255 |
Process p = null; |
| 256 |
try { |
| 257 |
cmdArraySudo = fillPathSudoCommand(cmdArraySudo, project); |
| 258 |
IRemoteCommandLauncher launcher; |
| 259 |
IPath changeToDir = null, path; |
| 260 |
if (project != null) { |
| 261 |
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project); |
| 262 |
path = new Path(proxy.toPath(uri)); |
| 263 |
launcher = RemoteProxyManager.getInstance().getLauncher(project); |
| 264 |
envp = updateEnvironment(envp, project); |
| 265 |
|
| 266 |
if (dir != null) |
| 267 |
changeToDir = new Path(proxy.toPath(dir.toURI())); |
| 268 |
} else { |
| 269 |
launcher = RemoteProxyManager.getInstance().getLauncher(uri); |
| 270 |
path = new Path(uri.getPath()); |
| 271 |
if (dir != null) |
| 272 |
changeToDir = new Path(dir.toURI().getPath()); |
| 273 |
} |
| 274 |
|
| 275 |
List<String> cmdlist = new ArrayList<String>(Arrays.asList(cmdArraySudo)); |
| 276 |
cmdlist.remove(0); |
| 277 |
cmdlist.toArray(cmdArraySudo); |
| 278 |
cmdArraySudo = cmdlist.toArray(new String[0]); |
| 279 |
|
| 280 |
p = launcher.execute(path, cmdArraySudo, envp, changeToDir , new NullProgressMonitor()); |
| 281 |
} catch (CoreException e) { |
| 282 |
e.printStackTrace(); |
| 283 |
} |
| 284 |
|
| 285 |
return p; |
| 286 |
|
| 287 |
} |
| 145 |
} |
288 |
} |
| 146 |
- |
|
|