diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/CommandLineUtil.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/CommandLineUtil.java index 77d19531d5a..4928b7e1f38 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/CommandLineUtil.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/CommandLineUtil.java @@ -24,14 +24,18 @@ import org.eclipse.osgi.service.environment.Constants; */ public class CommandLineUtil { - public static String[] argumentsToArray(String line) { + private static boolean isWindows() { boolean osWin; try { osWin = Platform.getOS().equals(Constants.OS_WIN32); } catch (Exception e) { osWin = false; } - if (osWin) { + return osWin; + } + + public static String[] argumentsToArray(String line) { + if (isWindows()) { return argumentsToArrayWindowsStyle(line); } else { return argumentsToArrayUnixStyle(line); @@ -260,4 +264,160 @@ public class CommandLineUtil { } return aList.toArray(new String[aList.size()]); } + + /** + * Converts argument array to a string suitable for passing to Bash like: + * + * This process reverses {@link #argumentsToArray(String)}, but does not + * restore the exact same results. + * + * @param args + * the arguments to convert and escape + * @param encodeNewline + * true if newline (\r or + * \n) should be encoded + * + * @return args suitable for passing to some process that decodes the string + * into an argument array + * @since 6.2 + */ + public static String argumentsToString(String[] args, boolean encodeNewline) { + if (isWindows()) { + return argumentsToStringWindowsCreateProcess(args, encodeNewline); + } else { + // XXX: Bug 507568: We are currently using incorrect assumption that + // shell is always bash. AFAIK this is only problematic when + // encoding newlines + return argumentsToStringBash(args, encodeNewline); + } + + } + + /** + * Converts argument array to a string suitable for passing to Bash like: + * + *
+	 * /bin/bash -c <args>
+	 * 
+ * + * In this case the arguments array passed to exec or equivalent will be: + * + *
+	 * argv[0] = "/bin/bash"
+	 * argv[1] = "-c"
+	 * argv[2] = argumentsToStringBashStyle(argumentsAsArray)
+	 * 
+ * + * Replace and concatenate all occurrences of: + *