Bug 562456 - Show Command Line => Command Line could not be retrieved

Change-Id: Idf807f8684a3e444c03c6522b81252e70b7cb09b
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java
index 0d643ae..1a193b8 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -731,59 +731,7 @@
 		SubMonitor lmonitor = SubMonitor.convert(monitor, DebugCoreMessages.LaunchConfiguration_9, 23);
 		try {
 			// bug 28245 - force the delegate to load in case it is interested in launch notifications
-			Set<String> modes = getModes();
-			modes.add(mode);
-			ILaunchDelegate[] delegates = getType().getDelegates(modes);
-			ILaunchConfigurationDelegate delegate = null;
-			switch (delegates.length) {
-				case 1:
-					delegate = delegates[0].getDelegate();
-					break;
-				case 0:
-				{
-					IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(promptStatus);
-					if (handler != null) {
-						handler.handleStatus(delegateNotAvailable, new Object[] {this, mode});
-					}
-					IStatus status = new Status(IStatus.CANCEL, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, DebugCoreMessages.LaunchConfiguration_11, null);
-					throw new CoreException(status);
-				}
-				default:
-				{
-					ILaunchDelegate del = getPreferredDelegate(modes);
-					if(del == null) {
-						del = getType().getPreferredDelegate(modes);
-					}
-					if(del == null) {
-						IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(promptStatus);
-						IStatus status = null;
-						if (handler != null) {
-							status = (IStatus) handler.handleStatus(duplicateDelegates, new Object[] {this, mode});
-						}
-						if(status != null && status.isOK()) {
-							del = getPreferredDelegate(modes);
-							if(del == null) {
-								del = getType().getPreferredDelegate(modes);
-							}
-							if(del != null) {
-								delegate = del.getDelegate();
-							}
-							else {
-								status = new Status(IStatus.CANCEL, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, DebugCoreMessages.LaunchConfiguration_13, null);
-								throw new CoreException(status);
-							}
-						}
-						else {
-							status = new Status(IStatus.CANCEL, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, DebugCoreMessages.LaunchConfiguration_13, null);
-							throw new CoreException(status);
-						}
-					}
-					else {
-						delegate = del.getDelegate();
-					}
-					break;
-				}
-			}
+			ILaunchConfigurationDelegate delegate = getPreferredLaunchDelegate(mode);
 
 			ILaunchConfigurationDelegate2 delegate2 = null;
 			if (delegate instanceof ILaunchConfigurationDelegate2) {
@@ -1036,4 +984,63 @@
 	public void setPrototypeAttributeVisibility(String attribute, boolean visible) throws CoreException {
 		getInfo().setAttributeVisibility(attribute, visible);
 	}
+
+	/*
+	 * Get Preferred delegate with all fallbacks
+	 * 
+	 */
+	public ILaunchConfigurationDelegate getPreferredLaunchDelegate(String mode) throws CoreException {
+		Set<String> modes = getModes();
+		modes.add(mode);
+		ILaunchDelegate[] delegates = getType().getDelegates(modes);
+		ILaunchConfigurationDelegate delegate = null;
+		switch (delegates.length) {
+			case 1:
+				delegate = delegates[0].getDelegate();
+				break;
+			case 0: {
+				IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(promptStatus);
+				if (handler != null) {
+					handler.handleStatus(delegateNotAvailable, new Object[] {
+							this, mode });
+				}
+				IStatus status = new Status(IStatus.CANCEL, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, DebugCoreMessages.LaunchConfiguration_11, null);
+				throw new CoreException(status);
+			}
+			default: {
+				ILaunchDelegate del = getPreferredDelegate(modes);
+				if (del == null) {
+					del = getType().getPreferredDelegate(modes);
+				}
+				if (del == null) {
+					IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(promptStatus);
+					IStatus status = null;
+					if (handler != null) {
+						status = (IStatus) handler.handleStatus(duplicateDelegates, new Object[] {
+								this, mode });
+					}
+					if (status != null && status.isOK()) {
+						del = getPreferredDelegate(modes);
+						if (del == null) {
+							del = getType().getPreferredDelegate(modes);
+						}
+						if (del != null) {
+							delegate = del.getDelegate();
+						} else {
+							status = new Status(IStatus.CANCEL, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, DebugCoreMessages.LaunchConfiguration_13, null);
+							throw new CoreException(status);
+						}
+					} else {
+						status = new Status(IStatus.CANCEL, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, DebugCoreMessages.LaunchConfiguration_13, null);
+						throw new CoreException(status);
+					}
+				} else {
+					delegate = del.getDelegate();
+				}
+				break;
+			}
+		}
+
+		return delegate;
+	}
 }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
index 8e52c8d..a5c1c07 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2018 IBM Corporation and others.
+ * Copyright (c) 2018, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -27,6 +27,7 @@
 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2;
 import org.eclipse.debug.internal.core.DebugCoreMessages;
+import org.eclipse.debug.internal.core.LaunchConfiguration;
 import org.eclipse.debug.internal.core.LaunchManager;
 import org.eclipse.debug.internal.ui.DebugUIPlugin;
 import org.eclipse.jface.dialogs.Dialog;
@@ -108,8 +109,15 @@
 			Set<String> modes = flaunchConfiguration.getModes();
 			modes.add(fMode);
 			ILaunchDelegate[] delegates = flaunchConfiguration.getType().getDelegates(modes);
-			if (delegates.length ==1) {
-				ILaunchConfigurationDelegate delegate = delegates[0].getDelegate();
+			ILaunchConfigurationDelegate delegate = null;
+			if (delegates.length == 1) {
+				delegate = delegates[0].getDelegate();
+			} else {
+				if (flaunchConfiguration instanceof LaunchConfiguration) {
+					delegate = ((LaunchConfiguration) flaunchConfiguration).getPreferredLaunchDelegate(fMode);
+				}
+			}
+			if (delegate != null) {
 				ILaunchConfigurationDelegate2 delegate2;
 				ILaunch launch = null;
 				if (delegate instanceof ILaunchConfigurationDelegate2) {