Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java68
1 files changed, 50 insertions, 18 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
index a0f99e68736..f8fb47ed057 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
@@ -15,27 +15,31 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
+import org.eclipse.cdt.internal.core.Cygwin;
import org.eclipse.cdt.internal.core.ProcessClosure;
+import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
/**
* @noextend This class is not intended to be subclassed by clients.
*/
public class CommandLauncher implements ICommandLauncher {
-
public final static int COMMAND_CANCELED = ICommandLauncher.COMMAND_CANCELED;
public final static int ILLEGAL_COMMAND = ICommandLauncher.ILLEGAL_COMMAND;
public final static int OK = ICommandLauncher.OK;
+ private static final String PATH_ENV = "PATH"; //$NON-NLS-1$
protected Process fProcess;
protected boolean fShowCommand;
protected String[] fCommandArgs;
+ private Properties fEnvironment = null;
protected String fErrorMessage = ""; //$NON-NLS-1$
@@ -95,7 +99,11 @@ public class CommandLauncher implements ICommandLauncher {
*/
@Override
public Properties getEnvironment() {
- return EnvironmentReader.getEnvVars();
+ if (fEnvironment == null) {
+ // for backward compatibility, note that this return may be not accurate
+ return EnvironmentReader.getEnvVars();
+ }
+ return fEnvironment;
}
/* (non-Javadoc)
@@ -117,29 +125,37 @@ public class CommandLauncher implements ICommandLauncher {
}
/**
+ * Parse array of "ENV=value" pairs to Properties.
+ */
+ private Properties parseEnv(String[] env) {
+ Properties envProperties = new Properties();
+ for (String envStr : env) {
+ // Split "ENV=value" and put in Properties
+ int pos = envStr.indexOf('=');
+ if (pos < 0)
+ pos = envStr.length();
+ String key = envStr.substring(0, pos);
+ String value = envStr.substring(pos + 1);
+ envProperties.put(key, value);
+ }
+ return envProperties;
+ }
+
+ /**
* @deprecated
* @since 5.1
*/
@Deprecated
public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory) {
try {
- // add platform specific arguments (shell invocation)
- fCommandArgs = constructCommandArray(commandPath.toOSString(), args);
-
- File file = null;
-
- if(changeToDirectory != null)
- file = changeToDirectory.toFile();
-
- fProcess = ProcessFactory.getFactory().exec(fCommandArgs, env, file);
- fErrorMessage = ""; //$NON-NLS-1$
- } catch (IOException e) {
- setErrorMessage(e.getMessage());
- fProcess = null;
+ return execute(commandPath, args, env, changeToDirectory, null);
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
}
- return fProcess;
+ return null;
}
+
/**
* @since 5.1
* @see org.eclipse.cdt.core.ICommandLauncher#execute(IPath, String[], String[], IPath, IProgressMonitor)
@@ -147,15 +163,30 @@ public class CommandLauncher implements ICommandLauncher {
@Override
public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory, IProgressMonitor monitor) throws CoreException {
try {
- // add platform specific arguments (shell invocation)
- fCommandArgs = constructCommandArray(commandPath.toOSString(), args);
+ String command = commandPath.toOSString();
+ fCommandArgs = constructCommandArray(command, args);
+ fEnvironment = parseEnv(env);
File file = null;
if(changeToDirectory != null)
file = changeToDirectory.toFile();
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ // Handle cygwin link
+ String envPathValue = (String) getEnvironment().get(PATH_ENV);
+ IPath location = PathUtil.findProgramLocation(command, envPathValue);
+ if(location != null) {
+ try {
+ fCommandArgs[0] = Cygwin.cygwinToWindowsPath(location.toString(), envPathValue);
+ } catch (Exception e) {
+ // if no cygwin nothing to worry about
+ }
+ }
+ }
+
fProcess = ProcessFactory.getFactory().exec(fCommandArgs, env, file);
+ fCommandArgs[0] = command; // to print original command on the console
fErrorMessage = ""; //$NON-NLS-1$
} catch (IOException e) {
setErrorMessage(e.getMessage());
@@ -168,6 +199,7 @@ public class CommandLauncher implements ICommandLauncher {
* @see org.eclipse.cdt.core.ICommandLauncher#waitAndRead(java.io.OutputStream, java.io.OutputStream)
*/
@Override
+ @Deprecated
public int waitAndRead(OutputStream out, OutputStream err) {
if (fShowCommand) {
printCommandLine(out);

Back to the top