|
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 |
/** |
| 60 |
* @deprecated |
| 61 |
* |
| 62 |
* Use {@link RuntimeProcessFactory#fillPathCommand(String[], IProject)} instead. |
| 63 |
*/ |
| 64 |
@Deprecated |
| 45 |
private String[] fillPathCommand(String[] cmdarray, String[] envp) throws IOException { |
65 |
private String[] fillPathCommand(String[] cmdarray, String[] envp) throws IOException { |
| 46 |
cmdarray[0] = whichCommand(cmdarray[0], envp); |
66 |
cmdarray[0] = whichCommand(cmdarray[0], envp); |
| 47 |
return cmdarray; |
67 |
return cmdarray; |
| 48 |
} |
68 |
} |
| 49 |
|
69 |
|
|
|
70 |
/** |
| 71 |
* @deprecated |
| 72 |
* |
| 73 |
* Use {@link RuntimeProcessFactory#fillPathSudoCommand(String[], IProject)} instead. |
| 74 |
*/ |
| 75 |
@Deprecated |
| 50 |
private String[] fillPathSudoCommand(String[] cmdarray, String[] envp) throws IOException { |
76 |
private String[] fillPathSudoCommand(String[] cmdarray, String[] envp) throws IOException { |
| 51 |
cmdarray[2] = whichCommand(cmdarray[2], envp); |
77 |
cmdarray[2] = whichCommand(cmdarray[2], envp); |
| 52 |
return cmdarray; |
78 |
return cmdarray; |
| 53 |
} |
79 |
} |
| 54 |
|
80 |
|
| 55 |
public String whichCommand(String command, IProject project) throws IOException { |
81 |
private String[] fillPathSudoCommand(String[] cmdarray, IProject project) throws IOException { |
| 56 |
return whichCommand(command, updateEnvironment(null, project)); |
82 |
cmdarray[1] = whichCommand(cmdarray[1], project); |
|
|
83 |
return cmdarray; |
| 57 |
} |
84 |
} |
| 58 |
|
85 |
|
|
|
86 |
/** |
| 87 |
* @deprecated |
| 88 |
* |
| 89 |
* Use {@link RuntimeProcessFactory#whichCommand(String, IProject)} instead. |
| 90 |
*/ |
| 91 |
@Deprecated |
| 59 |
public String whichCommand(String command, String[] envp) throws IOException { |
92 |
public String whichCommand(String command, String[] envp) throws IOException { |
| 60 |
Process p = Runtime.getRuntime().exec(new String[] {WHICH_CMD, command}, envp); |
93 |
Process p = Runtime.getRuntime().exec(new String[] {WHICH_CMD, command}, envp); |
| 61 |
try { |
94 |
try { |
|
Lines 72-77
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 72 |
return command; |
105 |
return command; |
| 73 |
} |
106 |
} |
| 74 |
|
107 |
|
|
|
108 |
public String whichCommand(String command, IProject project) throws IOException { |
| 109 |
if (project != null) { |
| 110 |
String[] envp = updateEnvironment(null, project); |
| 111 |
try { |
| 112 |
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project); |
| 113 |
URI whichUri = URI.create(WHICH_CMD); |
| 114 |
IPath whichPath = new Path(proxy.toPath(whichUri)); |
| 115 |
IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project); |
| 116 |
Process pProxy = launcher.execute(whichPath, new String[]{command}, envp, null, new NullProgressMonitor()); |
| 117 |
if (pProxy != null){ |
| 118 |
BufferedReader error = new BufferedReader(new InputStreamReader(pProxy.getErrorStream())); |
| 119 |
if(error.readLine() != null){ |
| 120 |
throw new IOException(error.readLine()); |
| 121 |
} |
| 122 |
BufferedReader reader = new BufferedReader(new InputStreamReader(pProxy.getInputStream())); |
| 123 |
String readLine = reader.readLine(); |
| 124 |
command = readLine; |
| 125 |
} |
| 126 |
} catch (CoreException e) { |
| 127 |
e.printStackTrace(); |
| 128 |
} |
| 129 |
} |
| 130 |
return command; |
| 131 |
} |
| 132 |
|
| 75 |
public static RuntimeProcessFactory getFactory() { |
133 |
public static RuntimeProcessFactory getFactory() { |
| 76 |
if (instance == null) |
134 |
if (instance == null) |
| 77 |
instance = new RuntimeProcessFactory(); |
135 |
instance = new RuntimeProcessFactory(); |
|
Lines 79-85
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 79 |
} |
137 |
} |
| 80 |
|
138 |
|
| 81 |
public Process exec(String cmd, IProject project) throws IOException { |
139 |
public Process exec(String cmd, IProject project) throws IOException { |
| 82 |
return exec(cmd, null, null, project); |
140 |
return exec(cmd, null, (IFileStore)null, project); |
| 83 |
} |
141 |
} |
| 84 |
|
142 |
|
| 85 |
public Process exec(String[] cmdarray, IProject project) throws IOException { |
143 |
public Process exec(String[] cmdarray, IProject project) throws IOException { |
|
Lines 87-104
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 87 |
} |
145 |
} |
| 88 |
|
146 |
|
| 89 |
public Process exec(String[] cmdarray, String[] envp, IProject project) throws IOException { |
147 |
public Process exec(String[] cmdarray, String[] envp, IProject project) throws IOException { |
| 90 |
return exec(cmdarray, envp, null, project); |
148 |
return exec(cmdarray, envp, (IFileStore)null, project); |
| 91 |
} |
149 |
} |
| 92 |
|
150 |
|
| 93 |
public Process exec(String cmd, String[] envp, IProject project) throws IOException { |
151 |
public Process exec(String cmd, String[] envp, IProject project) throws IOException { |
| 94 |
return exec(cmd, envp, null, project); |
152 |
return exec(cmd, envp, (IFileStore)null, project); |
| 95 |
} |
153 |
} |
| 96 |
|
154 |
|
|
|
155 |
/** |
| 156 |
* @deprecated |
| 157 |
* |
| 158 |
* Use {@link RuntimeProcessFactory#exec(String, String[], IFileStore, IProject)} instead. |
| 159 |
*/ |
| 160 |
@Deprecated |
| 97 |
public Process exec(String cmd, String[] envp, File dir, IProject project) |
161 |
public Process exec(String cmd, String[] envp, File dir, IProject project) |
| 98 |
throws IOException { |
162 |
throws IOException { |
| 99 |
return exec(tokenizeCommand(cmd), envp, dir, project); |
163 |
return exec(tokenizeCommand(cmd), envp, dir, project); |
| 100 |
} |
164 |
} |
| 101 |
|
165 |
|
|
|
166 |
/** |
| 167 |
* @since 1.1 |
| 168 |
*/ |
| 169 |
public Process exec(String cmd, String[] envp, IFileStore dir, IProject project) |
| 170 |
throws IOException { |
| 171 |
return exec(tokenizeCommand(cmd), envp, dir, project); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* @deprecated |
| 176 |
* |
| 177 |
* Use {@link RuntimeProcessFactory#exec(String[], String[], IFileStore, IProject)} instead. |
| 178 |
*/ |
| 179 |
@Deprecated |
| 102 |
public Process exec(String cmdarray[], String[] envp, File dir, IProject project) |
180 |
public Process exec(String cmdarray[], String[] envp, File dir, IProject project) |
| 103 |
throws IOException { |
181 |
throws IOException { |
| 104 |
envp = updateEnvironment(envp, project); |
182 |
envp = updateEnvironment(envp, project); |
|
Lines 106-133
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 106 |
|
184 |
|
| 107 |
return Runtime.getRuntime().exec(cmdarray, envp, dir); |
185 |
return Runtime.getRuntime().exec(cmdarray, envp, dir); |
| 108 |
} |
186 |
} |
|
|
187 |
|
| 188 |
/** |
| 189 |
* @since 1.1 |
| 190 |
*/ |
| 191 |
public Process exec(String cmdarray[], String[] envp, IFileStore dir, IProject project) |
| 192 |
throws IOException { |
| 193 |
|
| 194 |
Process p = null; |
| 195 |
try { |
| 196 |
cmdarray = fillPathCommand(cmdarray, project); |
| 197 |
|
| 198 |
String command = cmdarray[0]; |
| 199 |
URI uri = URI.create(command); |
| 200 |
|
| 201 |
IPath changeToDir = null; |
| 202 |
IPath path; |
| 203 |
IRemoteCommandLauncher launcher; |
| 204 |
|
| 205 |
if (project != null) { |
| 206 |
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project); |
| 207 |
path = new Path(proxy.toPath(uri)); |
| 208 |
launcher = RemoteProxyManager.getInstance().getLauncher(project); |
| 209 |
envp = updateEnvironment(envp, project); |
| 210 |
if (dir != null) |
| 211 |
changeToDir = new Path(proxy.toPath(dir.toURI())); |
| 212 |
} else { |
| 213 |
path = new Path(uri.getPath()); |
| 214 |
launcher = RemoteProxyManager.getInstance().getLauncher(uri); |
| 215 |
if (dir != null) |
| 216 |
changeToDir = new Path(dir.toURI().getPath()); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
List<String> cmdlist = new ArrayList<String>(Arrays.asList(cmdarray)); |
| 221 |
cmdlist.remove(0); |
| 222 |
cmdlist.toArray(cmdarray); |
| 223 |
cmdarray = cmdlist.toArray(new String[0]); |
| 224 |
|
| 225 |
p = launcher.execute(path, cmdarray, envp, changeToDir , new NullProgressMonitor()); |
| 226 |
} catch (CoreException e) { |
| 227 |
e.printStackTrace(); |
| 228 |
} |
| 229 |
|
| 230 |
return p; |
| 231 |
} |
| 109 |
|
232 |
|
| 110 |
public Process sudoExec(String cmd, IProject project) throws IOException { |
233 |
public Process sudoExec(String cmd, IProject project) throws IOException { |
| 111 |
return sudoExec(cmd, null, null, project); |
234 |
return sudoExec(cmd, null, (IFileStore)null, project); |
| 112 |
} |
235 |
} |
| 113 |
|
236 |
|
| 114 |
public Process sudoExec(String cmd, String[] envp, IProject project) throws IOException { |
237 |
public Process sudoExec(String cmd, String[] envp, IProject project) throws IOException { |
| 115 |
return exec(cmd, envp, null, project); |
238 |
return exec(cmd, envp, (IFileStore)null, project); |
| 116 |
} |
239 |
} |
| 117 |
|
240 |
|
|
|
241 |
/** |
| 242 |
* @deprecated |
| 243 |
* |
| 244 |
* Use {@link RuntimeProcessFactory#sudoExec(String, String[], IFileStore, IProject)} instead. |
| 245 |
*/ |
| 246 |
@Deprecated |
| 118 |
public Process sudoExec(String cmd, String[] envp, File dir, IProject project) |
247 |
public Process sudoExec(String cmd, String[] envp, File dir, IProject project) |
| 119 |
throws IOException { |
248 |
throws IOException { |
| 120 |
return sudoExec(tokenizeCommand(cmd), envp, dir, project); |
249 |
return sudoExec(tokenizeCommand(cmd), envp, dir, project); |
| 121 |
} |
250 |
} |
|
|
251 |
|
| 252 |
/** |
| 253 |
* @since 1.1 |
| 254 |
*/ |
| 255 |
public Process sudoExec(String cmd, String[] envp, IFileStore dir, IProject project) |
| 256 |
throws IOException { |
| 257 |
return sudoExec(tokenizeCommand(cmd), envp, dir, project); |
| 258 |
} |
| 122 |
|
259 |
|
| 123 |
public Process sudoExec(String[] cmdarray, IProject project) throws IOException { |
260 |
public Process sudoExec(String[] cmdarray, IProject project) throws IOException { |
| 124 |
return sudoExec(cmdarray, null, project); |
261 |
return sudoExec(cmdarray, null, project); |
| 125 |
} |
262 |
} |
| 126 |
|
263 |
|
| 127 |
public Process sudoExec(String[] cmdarray, String[] envp, IProject project) throws IOException { |
264 |
public Process sudoExec(String[] cmdarray, String[] envp, IProject project) throws IOException { |
| 128 |
return sudoExec(cmdarray, envp, null, project); |
265 |
return sudoExec(cmdarray, envp, (IFileStore)null, project); |
| 129 |
} |
266 |
} |
| 130 |
|
267 |
|
|
|
268 |
/** |
| 269 |
* @deprecated |
| 270 |
* |
| 271 |
* Use {@link RuntimeProcessFactory#sudoExec(String[], String[], IFileStore, IProject)} instead. |
| 272 |
*/ |
| 273 |
@Deprecated |
| 131 |
public Process sudoExec(String[] cmdarray, String[] envp, File dir, IProject project) throws IOException { |
274 |
public Process sudoExec(String[] cmdarray, String[] envp, File dir, IProject project) throws IOException { |
| 132 |
List<String> cmdList = Arrays.asList(cmdarray); |
275 |
List<String> cmdList = Arrays.asList(cmdarray); |
| 133 |
ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList); |
276 |
ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList); |
|
Lines 142-145
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
Link Here
|
| 142 |
|
285 |
|
| 143 |
return Runtime.getRuntime().exec(cmdArraySudo, envp, dir); |
286 |
return Runtime.getRuntime().exec(cmdArraySudo, envp, dir); |
| 144 |
} |
287 |
} |
|
|
288 |
|
| 289 |
/** |
| 290 |
* @since 1.1 |
| 291 |
*/ |
| 292 |
public Process sudoExec(String[] cmdarray, String[] envp, IFileStore dir, IProject project) throws IOException { |
| 293 |
URI uri = URI.create("sudo"); //$NON-NLS-1$ |
| 294 |
|
| 295 |
List<String> cmdList = Arrays.asList(cmdarray); |
| 296 |
ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList); |
| 297 |
cmdArrayList.add(0, "-n"); //$NON-NLS-1$ |
| 298 |
|
| 299 |
String[] cmdArraySudo = new String[cmdArrayList.size()]; |
| 300 |
cmdArrayList.toArray(cmdArraySudo); |
| 301 |
|
| 302 |
Process p = null; |
| 303 |
try { |
| 304 |
cmdArraySudo = fillPathSudoCommand(cmdArraySudo, project); |
| 305 |
IRemoteCommandLauncher launcher; |
| 306 |
IPath changeToDir = null, path; |
| 307 |
if (project != null) { |
| 308 |
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project); |
| 309 |
path = new Path(proxy.toPath(uri)); |
| 310 |
launcher = RemoteProxyManager.getInstance().getLauncher(project); |
| 311 |
envp = updateEnvironment(envp, project); |
| 312 |
|
| 313 |
if (dir != null) |
| 314 |
changeToDir = new Path(proxy.toPath(dir.toURI())); |
| 315 |
} else { |
| 316 |
launcher = RemoteProxyManager.getInstance().getLauncher(uri); |
| 317 |
path = new Path(uri.getPath()); |
| 318 |
if (dir != null) |
| 319 |
changeToDir = new Path(dir.toURI().getPath()); |
| 320 |
} |
| 321 |
|
| 322 |
List<String> cmdlist = new ArrayList<String>(Arrays.asList(cmdArraySudo)); |
| 323 |
cmdlist.remove(0); |
| 324 |
cmdlist.toArray(cmdArraySudo); |
| 325 |
cmdArraySudo = cmdlist.toArray(new String[0]); |
| 326 |
|
| 327 |
p = launcher.execute(path, cmdArraySudo, envp, changeToDir , new NullProgressMonitor()); |
| 328 |
} catch (CoreException e) { |
| 329 |
e.printStackTrace(); |
| 330 |
} |
| 331 |
|
| 332 |
return p; |
| 333 |
|
| 334 |
} |
| 145 |
} |
335 |
} |
| 146 |
- |
|
|