mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Set the environment when doing "run" launching.
This commit is contained in:
parent
a080d56b16
commit
0fe4bfc865
1 changed files with 22 additions and 5 deletions
|
@ -9,6 +9,8 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IProcessInfo;
|
import org.eclipse.cdt.core.IProcessInfo;
|
||||||
|
@ -22,6 +24,8 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
||||||
import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
|
import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
|
||||||
import org.eclipse.cdt.launch.ICDTLaunchConfigurationConstants;
|
import org.eclipse.cdt.launch.ICDTLaunchConfigurationConstants;
|
||||||
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
|
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
|
||||||
|
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
|
||||||
|
import org.eclipse.cdt.utils.spawner.ProcessFactory;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -131,7 +135,7 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
|
||||||
if (wd == null) {
|
if (wd == null) {
|
||||||
wd = new File(System.getProperty("user.home", ".")); //NON-NLS-1;
|
wd = new File(System.getProperty("user.home", ".")); //NON-NLS-1;
|
||||||
}
|
}
|
||||||
Process process = exec(commandArray, getEnvironmentArray(config), wd);
|
Process process = exec(commandArray, getEnvironmentProperty(config), wd);
|
||||||
DebugPlugin.getDefault().newProcess(launch, process, renderProcessLabel(commandArray[0]));
|
DebugPlugin.getDefault().newProcess(launch, process, renderProcessLabel(commandArray[0]));
|
||||||
}
|
}
|
||||||
monitor.done();
|
monitor.done();
|
||||||
|
@ -183,13 +187,26 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
|
||||||
* cancelled
|
* cancelled
|
||||||
* @see Runtime
|
* @see Runtime
|
||||||
*/
|
*/
|
||||||
protected Process exec(String[] cmdLine, String[] envp, File workingDirectory) throws CoreException {
|
protected Process exec(String[] cmdLine, Properties environ, File workingDirectory) throws CoreException {
|
||||||
Process p = null;
|
Process p = null;
|
||||||
|
Properties props = EnvironmentReader.getEnvVars();
|
||||||
|
props.putAll(environ);
|
||||||
|
String[] envp = null;
|
||||||
|
ArrayList envList = new ArrayList();
|
||||||
|
Enumeration names = props.propertyNames();
|
||||||
|
if (names != null) {
|
||||||
|
while (names.hasMoreElements()) {
|
||||||
|
String key = (String) names.nextElement();
|
||||||
|
envList.add(key + "=" + props.getProperty(key));
|
||||||
|
}
|
||||||
|
envp = (String[]) envList.toArray(new String[envList.size()]);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (workingDirectory == null) {
|
if (workingDirectory == null) {
|
||||||
p = Runtime.getRuntime().exec(cmdLine, envp);
|
p = ProcessFactory.getFactory().exec(cmdLine, envp);
|
||||||
} else {
|
} else {
|
||||||
p = Runtime.getRuntime().exec(cmdLine, envp, workingDirectory);
|
p = ProcessFactory.getFactory().exec(cmdLine, envp, workingDirectory);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
|
@ -211,7 +228,7 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
Object result = handler.handleStatus(status, this);
|
Object result = handler.handleStatus(status, this);
|
||||||
if (result instanceof Boolean && ((Boolean) result).booleanValue()) {
|
if (result instanceof Boolean && ((Boolean) result).booleanValue()) {
|
||||||
p = exec(cmdLine, envp, null);
|
p = exec(cmdLine, environ, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue