From 3d78256606069c4a7ab7176ffbdb59ab9d54f296 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 19 Jun 2014 18:53:26 -0400 Subject: [PATCH] Bug 437782 - Standalone Debugger does not consider the executable PATH - add code to search PATH using "which" command if the executable consists of a single segment and is not absolute Change-Id: I0e36adc99d206c4f61e58747eb3ebfc30cd1437c Reviewed-on: https://git.eclipse.org/r/28790 Tested-by: Hudson CI Reviewed-by: Jeff Johnston Tested-by: Jeff Johnston --- .../ApplicationWorkbenchWindowAdvisor.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/ApplicationWorkbenchWindowAdvisor.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/ApplicationWorkbenchWindowAdvisor.java index 13b4a135c81..68f4ec537e7 100644 --- a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/ApplicationWorkbenchWindowAdvisor.java +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/ApplicationWorkbenchWindowAdvisor.java @@ -10,8 +10,12 @@ *******************************************************************************/ package org.eclipse.cdt.debug.application; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; @@ -19,11 +23,13 @@ import org.eclipse.cdt.internal.debug.application.DebugAttachedExecutable; import org.eclipse.cdt.internal.debug.application.DebugCoreFile; import org.eclipse.cdt.internal.debug.application.DebugExecutable; import org.eclipse.cdt.internal.debug.application.JobContainer; +import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; @@ -105,6 +111,37 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { } } + // Private method to search for executable names on PATH + private String findExecutable(String input) { + String result = input; + + Path x = new Path(input); + try { + if (!x.isAbsolute() && x.segmentCount() == 1) { + String command = "which " + input; //$NON-NLS-1$ + Process p = null; + InputStream in = null; + try { + p = ProcessFactory.getFactory().exec(command); + in = p.getInputStream(); + InputStreamReader reader = new InputStreamReader(in); + BufferedReader br = new BufferedReader(reader); + String line = br.readLine(); + if (line != null) + result = line; + } finally { + if (in != null) + in.close(); + if (p != null) + p.destroy(); + } + } + } catch (IOException e) { + // do nothing + } + return result; + } + public class PostWindowCreateRunnable implements IRunnableWithProgress { @Override @@ -143,7 +180,7 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { else if ("-e".equals(args[i])) { ++i; if (i < args.length) - executable = args[i]; + executable = findExecutable(args[i]); ++i; StringBuffer argBuffer = new StringBuffer(); // Remaining values are arguments to the executable