Bug 548886 - Support 'Show Command Line' button for external tool
launches

Change-Id: I0f51d0a10187c86a310d75a40552a19021fa3af4
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
diff --git a/org.eclipse.core.externaltools/plugin.xml b/org.eclipse.core.externaltools/plugin.xml
index b60e930..7dcbf78 100644
--- a/org.eclipse.core.externaltools/plugin.xml
+++ b/org.eclipse.core.externaltools/plugin.xml
@@ -23,6 +23,7 @@
             category="org.eclipse.ui.externaltools"
             modes="run"
             id="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"
+            allowCommandLine="true"
             allowOutputMerging="true">
       </launchConfigurationType>
       <launchConfigurationType
@@ -31,6 +32,7 @@
             category="org.eclipse.ui.externaltools.builder"
             modes="run"
             id="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType"
+            allowCommandLine="true"
             allowOutputMerging="true">
       </launchConfigurationType>
    </extension>
@@ -39,10 +41,10 @@
          name="%Builder.externalTools"
          point="org.eclipse.core.resources.builders">
      <builder
-      	isConfigurable= "true">
+        isConfigurable= "true">
          <run
                class="org.eclipse.core.externaltools.internal.model.ExternalToolBuilder">
          </run>
       </builder>
-   </extension>   
+   </extension>
 </plugin>
diff --git a/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/launchConfigurations/ProgramLaunchDelegate.java b/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/launchConfigurations/ProgramLaunchDelegate.java
index b7a0e29..5133bd9 100644
--- a/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/launchConfigurations/ProgramLaunchDelegate.java
+++ b/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/launchConfigurations/ProgramLaunchDelegate.java
@@ -88,23 +88,12 @@
 			return;
 		}
 
-		// resolve arguments
-		String[] arguments = ExternalToolsCoreUtil.getArguments(configuration);
+		String[] cmdLine = buildCommandLine(configuration, location);
 
 		if (monitor.isCanceled()) {
 			return;
 		}
 
-		int cmdLineLength = 1;
-		if (arguments != null) {
-			cmdLineLength += arguments.length;
-		}
-		String[] cmdLine = new String[cmdLineLength];
-		cmdLine[0] = location.toOSString();
-		if (arguments != null) {
-			System.arraycopy(arguments, 0, cmdLine, 1, arguments.length);
-		}
-
 		File workingDir = null;
 		if (workingDirectory != null) {
 			workingDir = workingDirectory.toFile();
@@ -180,6 +169,22 @@
 		}
 	}
 
+	private String[] buildCommandLine(ILaunchConfiguration configuration, IPath location) throws CoreException {
+		// resolve arguments
+		String[] arguments = ExternalToolsCoreUtil.getArguments(configuration);
+
+		int cmdLineLength = 1;
+		if (arguments != null) {
+			cmdLineLength += arguments.length;
+		}
+		String[] cmdLine = new String[cmdLineLength];
+		cmdLine[0] = location.toOSString();
+		if (arguments != null) {
+			System.arraycopy(arguments, 0, cmdLine, 1, arguments.length);
+		}
+		return cmdLine;
+	}
+
 	private String generateCommandLine(String[] commandLine) {
 		if (commandLine.length < 1) {
 			return IExternalToolConstants.EMPTY_STRING;
@@ -237,4 +242,11 @@
 		return super.saveBeforeLaunch(configuration, mode, monitor);
 	}
 
+	@Override
+	public String showCommandLine(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+		IPath location = ExternalToolsCoreUtil.getLocation(configuration);
+		String[] cmd = buildCommandLine(configuration, location);
+		String cmdLine = generateCommandLine(cmd);
+		return cmdLine;
+	}
 }
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/model/ILaunchConfigurationDelegate.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/model/ILaunchConfigurationDelegate.java
index a108941..e50c347 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/core/model/ILaunchConfigurationDelegate.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/model/ILaunchConfigurationDelegate.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -56,14 +56,12 @@
 
 	/**
 	 * Gets the command line to launch the given configuration in the specified
-	 * mode, contributing debug targets and/or processes to the given launch
-	 * object. The launch object has already been registered with the launch
-	 * manager.
+	 * mode.
 	 *
-	 * @param configuration the configuration to launch
-	 * @param mode the mode in which to launch, one of the mode constants
-	 *            defined by <code>ILaunchManager</code> - <code>RUN_MODE</code>
-	 *            or <code>DEBUG_MODE</code>.
+	 * @param configuration the configuration to build command line for
+	 * @param mode the mode in which to build command line, one of the mode
+	 *            constants defined by <code>ILaunchManager</code> -
+	 *            <code>RUN_MODE</code> or <code>DEBUG_MODE</code>.
 	 * @param monitor progress monitor, or <code>null</code> progress monitor,
 	 *            or <code>null</code>. A cancelable progress monitor is
 	 *            provided by the Job framework. It should be noted that the
@@ -74,10 +72,9 @@
 	 *            workspace batch jobs to be canceled, as the canceled flag is
 	 *            propagated up the top-level parent monitor. The provided
 	 *            monitor is not guaranteed to have been started.
-	 * @param launch the launch object to contribute processes and debug targets
-	 *            to
+	 * @param launch the launch to create command line for
 	 * @return the command line string
-	 * @exception CoreException if launching fails
+	 * @exception CoreException if building the command line failed
 	 * @since 3.13
 	 */
 	public default String showCommandLine(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {