Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Sennikovsky2006-06-09 15:25:49 +0000
committerMikhail Sennikovsky2006-06-09 15:25:49 +0000
commit27eee377fe38fb9fe846ef9539bac0959173150d (patch)
tree0089c29f0c05a29069e2843c2e5709d0e4bb8bee
parent6d81ef8ab250efcdedadf4c2da8db5a065f17f7f (diff)
downloadorg.eclipse.cdt-27eee377fe38fb9fe846ef9539bac0959173150d.tar.gz
org.eclipse.cdt-27eee377fe38fb9fe846ef9539bac0959173150d.tar.xz
org.eclipse.cdt-27eee377fe38fb9fe846ef9539bac0959173150d.zip
Work-around fix for 145099
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java106
1 files changed, 101 insertions, 5 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 e3d4d5f4e8..6f5745367d 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
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.buildmodel;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -20,8 +21,8 @@ import java.util.Map;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
/**
@@ -35,14 +36,23 @@ import org.eclipse.core.runtime.SubProgressMonitor;
*
*/
public class CommandBuilder implements IBuildModelBuilder {
+ private static final String PATH_ENV = "PATH"; //$NON-NLS-1$
+ private static final String PROPERTY_DELIMITER = "path.separator"; //$NON-NLS-1$
+ private static final String PROPERTY_OS_NAME = "os.name"; //$NON-NLS-1$
+ private static final String PROPERTY_OS_VALUE = "windows";//$NON-NLS-1$
+ static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
+ static final String DELIMITER_WINDOWS = ";"; //$NON-NLS-1$
+
private IBuildCommand fCmd;
private Process fProcess;
private String fErrMsg;
- private boolean fUseSpawner;
private static final String BUILDER_MSG_HEADER = "InternalBuilder.msg.header"; //$NON-NLS-1$
private static final String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
+/*
+ * no need in this for now, Spawner is always used
+ *
protected class SpawnerfreeLauncher extends CommandLauncher{
public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory) {
@@ -59,7 +69,45 @@ public class CommandBuilder implements IBuildModelBuilder {
return fProcess;
}
}
+*/
+ /*
+ * a temporary work-around to resolve the bug#145099
+ * (https://bugs.eclipse.org/bugs/show_bug.cgi?id=145099)
+ *
+ * this will be removed after fixing the bug#145737
+ * (https://bugs.eclipse.org/bugs/show_bug.cgi?id=145737)
+ */
+ private class CommandSearchLauncher extends CommandLauncher{
+
+ protected String[] constructCommandArray(String command, String[] commandArgs) {
+ String[] args = new String[1 + commandArgs.length];
+ if(!isWindows()){
+ //find a full path to an executable
+ String cmd = getExecutable(command, fCmd.getEnvironment());
+ if(cmd != null)
+ command = cmd;
+ //if not found, continue with the command passed as an argument
+ }
+
+ args[0] = command;
+ System.arraycopy(commandArgs, 0, args, 1, commandArgs.length);
+ return args;
+ }
+
+ 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;
@@ -153,9 +201,9 @@ public class CommandBuilder implements IBuildModelBuilder {
}
protected CommandLauncher createLauncher() {
- if(fUseSpawner)
- return new CommandLauncher();
- return new SpawnerfreeLauncher();
+// if(isWindows())
+// return new CommandLauncher();
+ return new CommandSearchLauncher();
}
public String getErrMsg(){
@@ -207,4 +255,52 @@ public class CommandBuilder implements IBuildModelBuilder {
return buf.toString();
}
+ private String getExecutable(String command, Map environment){
+ if(new Path(command).isAbsolute())
+ return command;
+ return searchExecutable(command, getPaths(environment));
+ }
+
+ private String[] getPaths(Map env){
+ String pathsStr = (String)env.get(PATH_ENV);
+ if(pathsStr == null){
+ for(Iterator iter = env.entrySet().iterator(); iter.hasNext();){
+ Map.Entry entry = (Map.Entry)iter.next();
+ if(PATH_ENV.equalsIgnoreCase((String)entry.getKey())){
+ pathsStr = (String)entry.getValue();
+ break;
+ }
+ }
+ }
+ if(pathsStr != null){
+ String delimiter = getDelimiter();
+
+ return pathsStr.split(delimiter);
+ }
+ return null;
+ }
+
+ private String getDelimiter(){
+ String delimiter = System.getProperty(PROPERTY_DELIMITER);
+ if(delimiter == null)
+ delimiter = isWindows() ? DELIMITER_WINDOWS : DELIMITER_UNIX;
+ return delimiter;
+ }
+
+ private String searchExecutable(String command, String paths[]){
+ if(paths == null)
+ return null;
+
+ for(int i = 0; i < paths.length; i++){
+ File file = new File(paths[i], command.toString());
+ if(file.isFile())
+ return file.toString();
+ }
+ return null;
+ }
+
+ private boolean isWindows() {
+ String prop = System.getProperty(PROPERTY_OS_NAME);
+ return prop != null ? prop.toLowerCase().startsWith(PROPERTY_OS_VALUE) : false;
+ }
}

Back to the top