Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 378494 | Differences between
and this patch

Collapse All | Expand All

(-)a/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 9-15 Bundle-Localization: plugin Link Here
9
Require-Bundle: org.eclipse.core.runtime,
9
Require-Bundle: org.eclipse.core.runtime,
10
 org.eclipse.cdt.core,
10
 org.eclipse.cdt.core,
11
 org.eclipse.core.resources,
11
 org.eclipse.core.resources,
12
 org.eclipse.ui;bundle-version="3.7.0"
12
 org.eclipse.ui;bundle-version="3.7.0",
13
 org.eclipse.linuxtools.profiling.launch;bundle-version="0.10.0",
14
 org.eclipse.core.filesystem;bundle-version="1.3.100"
13
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
15
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
14
Bundle-ActivationPolicy: lazy
16
Bundle-ActivationPolicy: lazy
15
Export-Package: org.eclipse.linuxtools.tools.launch.core.factory,
17
Export-Package: org.eclipse.linuxtools.tools.launch.core.factory,
(-)a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java (-30 / +98 lines)
Lines 12-26 Link Here
12
package org.eclipse.linuxtools.tools.launch.core.factory;
12
package org.eclipse.linuxtools.tools.launch.core.factory;
13
13
14
import java.io.BufferedReader;
14
import java.io.BufferedReader;
15
import java.io.File;
16
import java.io.IOException;
15
import java.io.IOException;
17
import java.io.InputStreamReader;
16
import java.io.InputStreamReader;
17
import java.net.URI;
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.Arrays;
19
import java.util.Arrays;
20
import java.util.List;
20
import java.util.List;
21
import java.util.StringTokenizer;
21
import java.util.StringTokenizer;
22
22
23
import org.eclipse.core.filesystem.IFileStore;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.runtime.NullProgressMonitor;
28
import org.eclipse.core.runtime.Path;
29
import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher;
30
import org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy;
31
import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
24
32
25
/*
33
/*
26
 * Create process using Runtime.getRuntime().exec and prepends the
34
 * Create process using Runtime.getRuntime().exec and prepends the
Lines 32-37 import org.eclipse.core.resources.IProject; Link Here
32
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
40
public class RuntimeProcessFactory extends LinuxtoolsProcessFactory {
33
	private static RuntimeProcessFactory instance = null;
41
	private static RuntimeProcessFactory instance = null;
34
	private static final String WHICH_CMD = "which"; //$NON-NLS-1$
42
	private static final String WHICH_CMD = "which"; //$NON-NLS-1$
43
	
44
	private IRemoteFileProxy proxy;
45
	
35
46
36
	private String[] tokenizeCommand(String command) {
47
	private String[] tokenizeCommand(String command) {
37
		StringTokenizer tokenizer = new StringTokenizer(command);
48
		StringTokenizer tokenizer = new StringTokenizer(command);
Lines 42-72 public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { Link Here
42
		return cmdarray;
53
		return cmdarray;
43
	}
54
	}
44
55
45
	private String[] fillPathCommand(String[] cmdarray, String[] envp) throws IOException {
56
	private String[] fillPathCommand(String[] cmdarray, IProject project) throws IOException {
46
		cmdarray[0] = whichCommand(cmdarray[0], envp);
57
		cmdarray[0] = whichCommand(cmdarray[0], project);
47
		return cmdarray;
58
		return cmdarray;
48
	}
59
	}
49
	
60
	
50
	private String[] fillPathSudoCommand(String[] cmdarray, String[] envp) throws IOException {
61
	private String[] fillPathSudoCommand(String[] cmdarray, IProject project) throws IOException {
51
		cmdarray[2] = whichCommand(cmdarray[2], envp);
62
		cmdarray[1] = whichCommand(cmdarray[1], project);
52
		return cmdarray;
63
		return cmdarray;
53
	}
64
	}
54
65
55
	public String whichCommand(String command, IProject project) throws IOException {
66
	public String whichCommand(String command, IProject project) throws IOException {
56
		return whichCommand(command, updateEnvironment(null, project));
67
		
57
	}
68
		String[] envp = updateEnvironment(null, project);
58
69
		
59
	public String whichCommand(String command, String[] envp) throws IOException {
60
		Process p = Runtime.getRuntime().exec(new String[] {WHICH_CMD, command}, envp);
61
		try {
70
		try {
62
			if (p.waitFor() == 0) {
71
			proxy = RemoteProxyManager.getInstance().getFileProxy(project);
63
				BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
72
			URI whichUri = URI.create(WHICH_CMD);
64
				command = reader.readLine();
73
			IPath whichPath = new Path(proxy.toPath(whichUri));
65
			} else {
74
			IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project);
66
				BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
75
			envp = updateEnvironment(envp, project);
67
				throw new IOException(reader.readLine());
76
			Process pProxy = launcher.execute(whichPath, new String[]{command}, envp, null, new NullProgressMonitor());
77
			if (pProxy != null){
78
				BufferedReader error = new BufferedReader(new InputStreamReader(pProxy.getErrorStream()));
79
				if(error.readLine() != null){
80
					throw new IOException(error.readLine());
81
				}
82
				BufferedReader reader = new BufferedReader(new InputStreamReader(pProxy.getInputStream()));
83
				String readLine = reader.readLine();
84
				command = readLine;
68
			}
85
			}
69
		} catch (InterruptedException e) {
86
		} catch (CoreException e) {
70
			e.printStackTrace();
87
			e.printStackTrace();
71
		}
88
		}
72
		return command;
89
		return command;
Lines 94-110 public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { Link Here
94
		return exec(cmd, envp, null, project);
111
		return exec(cmd, envp, null, project);
95
	}
112
	}
96
113
97
	public Process exec(String cmd, String[] envp, File dir, IProject project)
114
	public Process exec(String cmd, String[] envp, IFileStore dir, IProject project)
98
		throws IOException {
115
		throws IOException {
99
		return exec(tokenizeCommand(cmd), envp, dir, project);
116
		return exec(tokenizeCommand(cmd), envp, dir, project);
100
	}
117
	}
101
118
102
	public Process exec(String cmdarray[], String[] envp, File dir, IProject project)
119
	public Process exec(String cmdarray[], String[] envp, IFileStore dir, IProject project)
103
		throws IOException {
120
		throws IOException {
104
		envp = updateEnvironment(envp, project);
121
			
105
		cmdarray = fillPathCommand(cmdarray, envp);
122
		String command = cmdarray[0];
123
		URI uri = URI.create(command);
106
124
107
		return Runtime.getRuntime().exec(cmdarray, envp, dir);
125
		Process p = null;
126
		try {
127
			cmdarray = fillPathCommand(cmdarray, project);
128
			
129
			IPath path = new Path(proxy.toPath(uri));
130
			IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project);
131
			envp = updateEnvironment(envp, project);
132
			
133
			IPath changeToDir;
134
			if (dir == null){
135
				changeToDir = null;
136
			} else{ 
137
				changeToDir = new Path(proxy.toPath(dir.toURI()));
138
			}
139
			
140
			List<String> cmdlist = new ArrayList<String>(Arrays.asList(cmdarray));
141
			cmdlist.remove(0);
142
			cmdlist.toArray(cmdarray);
143
			cmdarray = cmdlist.toArray(new String[0]);
144
145
			p = launcher.execute(path, cmdarray, envp, changeToDir , new NullProgressMonitor());
146
		} catch (CoreException e) {
147
			// TODO Auto-generated catch block
148
			e.printStackTrace();
149
		}
150
151
		return p;
108
	}
152
	}
109
	
153
	
110
	public Process sudoExec(String cmd, IProject project) throws IOException {
154
	public Process sudoExec(String cmd, IProject project) throws IOException {
Lines 115-121 public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { Link Here
115
		return exec(cmd, envp, null, project);
159
		return exec(cmd, envp, null, project);
116
	}
160
	}
117
	
161
	
118
	public Process sudoExec(String cmd, String[] envp, File dir, IProject project)
162
	public Process sudoExec(String cmd, String[] envp, IFileStore dir, IProject project)
119
			throws IOException {
163
			throws IOException {
120
			return sudoExec(tokenizeCommand(cmd), envp, dir, project);
164
			return sudoExec(tokenizeCommand(cmd), envp, dir, project);
121
		}
165
		}
Lines 128-145 public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { Link Here
128
		return sudoExec(cmdarray, envp, null, project);
172
		return sudoExec(cmdarray, envp, null, project);
129
	}
173
	}
130
	
174
	
131
	public Process sudoExec(String[] cmdarray, String[] envp, File dir, IProject project) throws IOException {
175
	public Process sudoExec(String[] cmdarray, String[] envp, IFileStore dir, IProject project) throws IOException {
176
		URI uri = URI.create("sudo");
177
		
132
		List<String> cmdList = Arrays.asList(cmdarray);
178
		List<String> cmdList = Arrays.asList(cmdarray);
133
		ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList);
179
		ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList);
134
		cmdArrayList.add(0, "sudo");
180
		cmdArrayList.add(0, "-n");
135
		cmdArrayList.add(1, "-n");
136
		
181
		
137
		String[] cmdArraySudo = new String[cmdArrayList.size()];
182
		String[] cmdArraySudo = new String[cmdArrayList.size()];
138
		cmdArrayList.toArray(cmdArraySudo);
183
		cmdArrayList.toArray(cmdArraySudo);
139
		
184
		
140
		envp = updateEnvironment(envp, project);
185
		Process p = null;
141
		cmdArraySudo = fillPathSudoCommand(cmdArraySudo, envp);
186
		try {
187
			cmdArraySudo = fillPathSudoCommand(cmdArraySudo, project);
188
			
189
			IPath path = new Path(proxy.toPath(uri));
190
			IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project);
191
			envp = updateEnvironment(envp, project);
192
			
193
			IPath changeToDir;
194
			if (dir == null){
195
				changeToDir = null;
196
			} else{ 
197
				changeToDir = new Path(proxy.toPath(dir.toURI()));
198
			}
199
			
200
			List<String> cmdlist = new ArrayList<String>(Arrays.asList(cmdArraySudo));
201
			cmdlist.remove(0);
202
			cmdlist.toArray(cmdArraySudo);
203
			cmdArraySudo = cmdlist.toArray(new String[0]);
204
205
			p = launcher.execute(path, cmdArraySudo, envp, changeToDir , new NullProgressMonitor());
206
		} catch (CoreException e) {
207
			// TODO Auto-generated catch block
208
			e.printStackTrace();
209
		}
210
		
211
		return p;
142
212
143
		return Runtime.getRuntime().exec(cmdArraySudo, envp, dir);
144
	}
213
	}
145
}
214
}
146
- 

Return to bug 378494