Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gvozdev2012-03-15 21:49:38 +0000
committerAndrew Gvozdev2012-03-15 21:49:38 +0000
commit12d44ec8becdf85fbc87e8e0da7fde7bd5d3a3ac (patch)
tree91690b61832a4b28033a42d89fac50a4387fa6c6
parent4c83576d7e036937a37cc0de496344020b677ee1 (diff)
downloadorg.eclipse.cdt-12d44ec8becdf85fbc87e8e0da7fde7bd5d3a3ac.tar.gz
org.eclipse.cdt-12d44ec8becdf85fbc87e8e0da7fde7bd5d3a3ac.tar.xz
org.eclipse.cdt-12d44ec8becdf85fbc87e8e0da7fde7bd5d3a3ac.zip
bug 145099: MBS Internal Builder: Switch to using the Spawner for
detecting an executable to be launched
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java49
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java68
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java26
3 files changed, 67 insertions, 76 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java
index b0a23fdb090..f0ff0a7a194 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Intel Corporation and others.
+ * Copyright (c) 2006, 2012 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,14 +20,11 @@ import java.util.Set;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.core.ICommandLauncher;
-import org.eclipse.cdt.internal.core.Cygwin;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor;
/**
@@ -48,44 +45,6 @@ public class CommandBuilder implements IBuildModelBuilder {
private Process fProcess;
private String fErrMsg;
- private class CommandSearchLauncher extends CommandLauncher {
- @Override
- protected String[] constructCommandArray(String command, String[] commandArgs) {
- String[] args = new String[1 + commandArgs.length];
- if (Platform.getOS().equals(Platform.OS_WIN32)) {
- // find a location of the executable
- String envPathValue = fCmd.getEnvironment().get(PATH_ENV);
- IPath location = PathUtil.findProgramLocation(command, envPathValue);
- if(location != null) {
- try {
- // Handle cygwin link
- command = Cygwin.cygwinToWindowsPath(location.toString(), envPathValue);
- } catch (Exception e) {
- command = location.toString();
- }
- }
- //if not found, continue with the command passed as an argument
- }
-
- args[0] = command;
- System.arraycopy(commandArgs, 0, args, 1, commandArgs.length);
- return args;
- }
-
- @Override
- protected void printCommandLine(OutputStream os) {
- if (os != null) {
- String cmd = CommandBuilder.this.getCommandLine();
- try {
- os.write(cmd.getBytes());
- os.flush();
- } catch (IOException e) {
- // ignore;
- }
- }
- }
- }
-
protected class OutputStreamWrapper extends OutputStream {
private OutputStream fOut;
@@ -205,12 +164,10 @@ public class CommandBuilder implements IBuildModelBuilder {
}
protected ICommandLauncher createLauncher() {
-// if(isWindows())
-// return new CommandLauncher();
- return new CommandSearchLauncher();
+ return new CommandLauncher();
}
- public String getErrMsg(){
+ public String getErrMsg() {
return fErrMsg;
}
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);
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java
index 57a04880ed8..e0f94d4f315 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -20,7 +20,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
/**
* An interface for launchers of external commands.
- *
+ *
* @since 5.1
*/
public interface ICommandLauncher {
@@ -28,19 +28,19 @@ public interface ICommandLauncher {
public final static int COMMAND_CANCELED = 1;
public final static int ILLEGAL_COMMAND = -1;
public final static int OK = 0;
-
-
+
+
/**
* Sets the project that this launcher is associated with, or <code>null</code> if there is no such
* project.
- *
+ *
* @param project
*/
public void setProject(IProject project);
-
+
/**
* Gets the project this launcher is associated with.
- *
+ *
* @return IProject, or <code>null</code> if there is no such project.
*/
public IProject getProject();
@@ -53,7 +53,7 @@ public interface ICommandLauncher {
/**
* Returns a human readable error message corresponding to the last error encountered during command
* execution.
- *
+ *
* @return A String corresponding to the error, or <code>null</code> if there has been no error.
*/
public String getErrorMessage();
@@ -61,7 +61,7 @@ public interface ICommandLauncher {
/**
* Sets the human readable error message corresponding to the last error encountered during command
* execution. A subsequent call to getErrorMessage() will return this string.
- *
+ *
* @param error A String corresponding to the error message, or <code>null</code> if the error state is
* intended to be cleared.
*/
@@ -69,7 +69,7 @@ public interface ICommandLauncher {
/**
* Returns an array of the command line arguments that were last used to execute a command.
- *
+ *
* @return an array of type String[] corresponding to the arguments. The array can be empty, but should not
* be null.
*/
@@ -78,14 +78,14 @@ public interface ICommandLauncher {
/**
* Returns the set of environment variables in the context of which
* this launcher will execute commands.
- *
+ *
* @return Properties
*/
public Properties getEnvironment();
/**
* Returns the constructed command line of the last command executed.
- *
+ *
* @return String
*/
public String getCommandLine();
@@ -99,7 +99,9 @@ public interface ICommandLauncher {
/**
* Reads output form the process to the streams.
+ * @deprecated Deprecated as of CDT 8.1. Use method taking IProgressMonitor instead.
*/
+ @Deprecated
public int waitAndRead(OutputStream out, OutputStream err);
/**

Back to the top