Bug 536943 - added extra waiting for output monitor to finish

This change adds extra waiting to
StandardVMType.generateLibraryInfo(File,
File), until the output monitor of the started process is done reading
the process output.

Change-Id: I2c1ec3922dc8bc43f2ef397c8523e2fc7f8f6054
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/org.eclipse.jdt.launching/META-INF/MANIFEST.MF b/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
index d490203..6fcb96d 100644
--- a/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
@@ -16,7 +16,7 @@
  org.eclipse.jdt.launching.sourcelookup.containers
 Require-Bundle: org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)",
  org.eclipse.jdt.core;bundle-version="[3.15.0,4.0.0)",
- org.eclipse.debug.core;bundle-version="[3.13.0,4.0.0)",
+ org.eclipse.debug.core;bundle-version="[3.13.200,4.0.0)",
  org.eclipse.jdt.debug;bundle-version="[3.11.0,4.0.0)",
  org.eclipse.core.variables;bundle-version="[3.2.0,4.0.0)",
  org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)",
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
index 92279eb..a5204bd 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
@@ -52,7 +52,9 @@
 import org.eclipse.debug.core.ILaunchManager;
 import org.eclipse.debug.core.Launch;
 import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IStreamMonitor;
 import org.eclipse.debug.core.model.IStreamsProxy;
+import org.eclipse.debug.internal.core.OutputStreamMonitor;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.launching.AbstractVMInstallType;
 import org.eclipse.jdt.launching.ILibraryLocationResolver;
@@ -696,9 +698,11 @@
 				p = DebugPlugin.exec(cmdLine, null, envp);
 				IProcess process = DebugPlugin.newProcess(new Launch(null, ILaunchManager.RUN_MODE, null), p, "Library Detection"); //$NON-NLS-1$
 				process.setAttribute(IProcess.ATTR_CMDLINE, String.join(" ", cmdLine)); //$NON-NLS-1$
+				IStreamMonitor outputStreamMonitor = process.getStreamsProxy().getOutputStreamMonitor();
 				for (int i= 0; i < 600; i++) {
-					// Wait no more than 30 seconds (600 * 50 milliseconds)
-					if (process.isTerminated()) {
+					// Wait no more than 30 seconds (600 * 50 milliseconds),
+					// also ensure we are done reading the process stream, if we have a OutputStreamMonitor
+					if (process.isTerminated() && isReadingDone(outputStreamMonitor)) {
 						break;
 					}
 					try {
@@ -724,6 +728,14 @@
 		return info;
 	}
 
+	@SuppressWarnings("restriction")
+	private boolean isReadingDone(IStreamMonitor monitor) {
+		if (monitor instanceof OutputStreamMonitor) {
+			return ((OutputStreamMonitor) monitor).isReadingDone();
+		}
+		return true;
+	}
+
 	/**
 	 * Parses the output from 'LibraryDetector'.
 	 *