Bug 574403 - Show process ID for process element in Debug view

Added process id to the process element label in the Debug view.

Change-Id: Id2c0e9a7b3240ce1b3a7a99689e07ca5bf0cf3eb
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/189972
Tested-by: JDT Bot <jdt-bot@eclipse.org>
Tested-by: Sarika Sinha <sarika.sinha@in.ibm.com>
Reviewed-by: Sarika Sinha <sarika.sinha@in.ibm.com>
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.java
index 9845c55..56fc147 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.java
@@ -124,6 +124,7 @@
 	public static String StandardVMDebugger_Establishing_debug_connection____5;
 
 	public static String StandardVMRunner__0____1___2;
+	public static String StandardVMRunner__0____1___2_3;
 	public static String StandardVMRunner__0__at_localhost__1__1;
 	public static String StandardVMRunner_Specified_working_directory_does_not_exist_or_is_not_a_directory___0__3;
 	public static String StandardVMRunner_Launching_VM____1;
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties
index 64aa308..41099b6 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties
@@ -102,6 +102,7 @@
 StandardVMDebugger_Establishing_debug_connection____5=Establishing debug connection...
 
 StandardVMRunner__0____1___2={0} ({1})
+StandardVMRunner__0____1___2_3={0} ({1}) [pid: {2}]
 StandardVMRunner__0__at_localhost__1__1={0} at localhost:{1}
 StandardVMRunner_Specified_working_directory_does_not_exist_or_is_not_a_directory___0__3=Specified working directory does not exist or is not a directory: {0}
 StandardVMRunner_Launching_VM____1=Launching VM...
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/Standard11xVMRunner.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/Standard11xVMRunner.java
index 33d7db5..16758a9 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/Standard11xVMRunner.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/Standard11xVMRunner.java
@@ -132,7 +132,7 @@
 			return;
 		}
 		String timestamp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(System.currentTimeMillis()));
-		IProcess process= DebugPlugin.newProcess(launch, p, renderProcessLabel(cmdLine, timestamp));
+		IProcess process = DebugPlugin.newProcess(launch, p, renderProcessLabel(p, cmdLine, timestamp));
 		process.setAttribute(DebugPlugin.ATTR_PATH, cmdLine[0]);
 		process.setAttribute(IProcess.ATTR_CMDLINE, renderCommandLine(cmdLine));
 		String ltime = launch.getAttribute(DebugPlugin.ATTR_LAUNCH_TIMESTAMP);
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMDebugger.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMDebugger.java
index f75790e..399d08b 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMDebugger.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMDebugger.java
@@ -347,7 +347,7 @@
 					return;
 				}
 				String timestamp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(System.currentTimeMillis()));
-				IProcess process= newProcess(launch, p, renderProcessLabel(cmdLine, timestamp), getDefaultProcessMap());
+				IProcess process = newProcess(launch, p, renderProcessLabel(p, cmdLine, timestamp), getDefaultProcessMap());
 				process.setAttribute(DebugPlugin.ATTR_PATH, cmdLine[0]);
 				process.setAttribute(IProcess.ATTR_CMDLINE, renderCommandLine(cmdLine));
 				String ltime = launch.getAttribute(DebugPlugin.ATTR_LAUNCH_TIMESTAMP);
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java
index 872f463..6997670 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java
@@ -81,13 +81,31 @@
 
 	/**
 	 * Returns the 'rendered' name for the specified command line
-	 * @param commandLine the command line
-	 * @param timestamp the run-at time for the process
+	 *
+	 * @param p
+	 * @param commandLine
+	 *            the command line
+	 * @param timestamp
+	 *            the run-at time for the process
 	 * @return the name for the process
 	 */
-	public static String renderProcessLabel(String[] commandLine, String timestamp) {
-		String format= LaunchingMessages.StandardVMRunner__0____1___2;
-		return NLS.bind(format, new String[] { commandLine[0], timestamp });
+	public static String renderProcessLabel(Process p, String[] commandLine, String timestamp) {
+		String processId = getProcessId(p);
+		if (processId == null) {
+			String format = LaunchingMessages.StandardVMRunner__0____1___2;
+			return NLS.bind(format, new String[] { commandLine[0], timestamp });
+		}
+		String format = LaunchingMessages.StandardVMRunner__0____1___2_3;
+		return NLS.bind(format, new String[] { commandLine[0], timestamp, processId });
+	}
+
+	private static String getProcessId(Process p) {
+		try {
+			return p != null ? Long.toString(p.pid()) : null;
+		} catch (UnsupportedOperationException e) {
+			// ignore, pid() is not implemented in this JVM
+		}
+		return null;
 	}
 
 	/**
@@ -524,7 +542,7 @@
 			return;
 		}
 		String timestamp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(System.currentTimeMillis()));
-		IProcess process= newProcess(launch, p, renderProcessLabel(cmdLine, timestamp), getDefaultProcessMap());
+		IProcess process = newProcess(launch, p, renderProcessLabel(p, cmdLine, timestamp), getDefaultProcessMap());
 		process.setAttribute(DebugPlugin.ATTR_PATH, cmdLine[0]);
 		process.setAttribute(IProcess.ATTR_CMDLINE, renderCommandLine(cmdLine));
 		String ltime = launch.getAttribute(DebugPlugin.ATTR_LAUNCH_TIMESTAMP);