Bug 369524 - [tests]'Installed JREs > Search...' should also find JDKs
from
Developer Package
diff --git a/org.eclipse.jdt.debug.tests/testresources/plist-bad1.xml b/org.eclipse.jdt.debug.tests/testresources/plist-bad1.xml
new file mode 100644
index 0000000..49b4c44
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testresources/plist-bad1.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<array>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>com.apple.javajdk16</string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <true/>
+        <key>JVMName</key>
+        <true/>
+        <key>JVMPlatformVersion</key>
+        <string>1.6</string>
+        <key>JVMVendor</key>
+        <string>Apple Inc.</string>
+        <key>JVMVersion</key>
+        <string>1.6.0_29-b11-402</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>net.java.openjdk</string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>OpenJDK 7</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.7</string>
+        <key>JVMVendor</key>
+        <string>openjdk-osx-build project</string>
+        <key>JVMVersion</key>
+        <string>1.7.0</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>com.apple.javajdk.1.6.0_29-b11-402</string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/1.6.0_29-b11-402.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>Java SE 6</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.6</string>
+        <key>JVMVendor</key>
+        <string>Apple Inc.</string>
+        <key>JVMVersion</key>
+        <string>1.6.0_29-b11-402</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string></string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>Java SE 7 Developer Preview</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.7</string>
+        <key>JVMVendor</key>
+        <string>Oracle Corporation</string>
+        <key>JVMVersion</key>
+        <string>1.7.0-ea-b213</string>
+    </dict>
+</array>
+</plist>
\ No newline at end of file
diff --git a/org.eclipse.jdt.debug.tests/testresources/plist-bad2.xml b/org.eclipse.jdt.debug.tests/testresources/plist-bad2.xml
new file mode 100644
index 0000000..f2b7751
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testresources/plist-bad2.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<array>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>com.apple.javajdk16</string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <true/>
+        <true/>
+        <key>JVMPlatformVersion</key>
+        <string>1.6</string>
+        <key>JVMVendor</key>
+        <string>Apple Inc.</string>
+        <key>JVMVersion</key>
+        <string>1.6.0_29-b11-402</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>net.java.openjdk</string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>OpenJDK 7</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.7</string>
+        <key>JVMVendor</key>
+        <string>openjdk-osx-build project</string>
+        <key>JVMVersion</key>
+        <string>1.7.0</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>com.apple.javajdk.1.6.0_29-b11-402</string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/1.6.0_29-b11-402.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>Java SE 6</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.6</string>
+        <key>JVMVendor</key>
+        <string>Apple Inc.</string>
+        <key>JVMVersion</key>
+        <string>1.6.0_29-b11-402</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string></string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>Java SE 7 Developer Preview</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.7</string>
+        <key>JVMVendor</key>
+        <string>Oracle Corporation</string>
+        <key>JVMVersion</key>
+        <string>1.7.0-ea-b213</string>
+    </dict>
+</array>
+</plist>
\ No newline at end of file
diff --git a/org.eclipse.jdt.debug.tests/testresources/plist-bad3.xml b/org.eclipse.jdt.debug.tests/testresources/plist-bad3.xml
new file mode 100644
index 0000000..8d66dc3
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testresources/plist-bad3.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<array>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>com.apple.javajdk16</string>
+        <key>JVMEnabled</key>
+        <true/
+        <key>JVMHomePath</key>
+        <string>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <true/>
+        <true/>
+        <key>JVMPlatformVersion</key>
+        <string>1.6</string>
+        <key>JVMVendor</key>
+        <string>Apple Inc.</string>
+        <key>JVMVersion</key>
+        <string>1.6.0_29-b11-402</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>net.java.openjdk</string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>OpenJDK 7</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.7</string>
+        <key>JVMVendor</key>
+        <string>openjdk-osx-build project</string>
+        <key>JVMVersion</key>
+        <string>1.7.0</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string>com.apple.javajdk.1.6.0_29-b11-402</string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/1.6.0_29-b11-402.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>Java SE 6</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.6</string>
+        <key>JVMVendor</key>
+        <string>Apple Inc.</string>
+        <key>JVMVersion</key>
+        <string>1.6.0_29-b11-402</string>
+    </dict>
+    <dict>
+        <key>JVMArch</key>
+        <string>x86_64</string>
+        <key>JVMBundleID</key>
+        <string></string>
+        <key>JVMEnabled</key>
+        <true/>
+        <key>JVMHomePath</key>
+        <string>/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home</string>
+        <key>JVMIsBuiltIn</key>
+        <false/>
+        <key>JVMName</key>
+        <string>Java SE 7 Developer Preview</string>
+        <key>JVMPlatformVersion</key>
+        <string>1.7</string>
+        <key>JVMVendor</key>
+        <string>Oracle Corporation</string>
+        <key>JVMVersion</key>
+        <string>1.7.0-ea-b213</string>
+    </dict>
+</array>
+</plist>
\ No newline at end of file
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/PListParserTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/PListParserTests.java
index 2bf556b..242bb84 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/PListParserTests.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/PListParserTests.java
@@ -17,6 +17,8 @@
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jdt.debug.testplugin.JavaTestPlugin;
 import org.eclipse.jdt.debug.tests.AbstractDebugTest;
+import org.eclipse.jdt.internal.launching.MacInstalledJREs.JREDescriptor;
+import org.eclipse.jdt.internal.launching.MacInstalledJREs;
 import org.eclipse.jdt.internal.launching.PListParser;
 
 /**
@@ -86,6 +88,12 @@
 		}
 	}
 
+	/**
+	 * Tests that we parse out the correct number of raw entries from the 'lion' plist output
+	 * 
+	 * @throws Exception
+	 * @since 3.8
+	 */
 	public void testParseLionJREs() throws Exception {
 		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/plist-lion.xml"));
 		assertNotNull(file);
@@ -100,6 +108,12 @@
 		}
 	}
 	
+	/**
+	 * Tests that we parse out the correct number of raw entries from the 'now leopard' ploist output
+	 * 
+	 * @throws Exception
+	 * @since 3.8
+	 */
 	public void testParseSnowLeopardJREs() throws Exception {
 		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/plist-snowleopard.xml"));
 		assertNotNull(file);
@@ -113,4 +127,107 @@
 			assertTrue("Top level object should be an array", false);
 		}
 	}
+	
+	/**
+	 * Tests that we can parse out certain {@link JREDescriptor}s from the 'old' style
+	 * of plist output.
+	 * 
+	 * @throws Exception
+	 * @since 3.8
+	 */
+	public void testParseJREDescriptors() throws Exception {
+		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/plist.xml"));
+		assertNotNull(file);
+		assertEquals(true, file.exists());
+		MacInstalledJREs mij = new MacInstalledJREs();
+		JREDescriptor[] desc = mij.parseJREInfo(new FileInputStream(file));
+		assertEquals("There should be 2 JRE descriptions", 2, desc.length);
+	}
+	
+	/**
+	 * Tests that we can parse out certain {@link JREDescriptor}s from the 'snow leopard' style
+	 * of plist output.
+	 * 
+	 * @throws Exception
+	 * @since 3.8
+	 */
+	public void testParseJREDescriptorsSnowLeopard() throws Exception {
+		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/plist-snowleopard.xml"));
+		assertNotNull(file);
+		assertEquals(true, file.exists());
+		MacInstalledJREs mij = new MacInstalledJREs();
+		JREDescriptor[] desc = mij.parseJREInfo(new FileInputStream(file));
+		assertEquals("There should be 1 JRE description", 1, desc.length);
+	}
+	
+	/**
+	 * Tests that we can parse out certain {@link JREDescriptor}s from the 'lion' style
+	 * of plist output.
+	 * 
+	 * @throws Exception
+	 * @since 3.8
+	 */
+	public void testParseJREDescriptorsLion() throws Exception {
+		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/plist-lion.xml"));
+		assertNotNull(file);
+		assertEquals(true, file.exists());
+		MacInstalledJREs mij = new MacInstalledJREs();
+		JREDescriptor[] desc = mij.parseJREInfo(new FileInputStream(file));
+		assertEquals("There should be 4 JRE descriptions", 4, desc.length);
+	}
+	
+	/**
+	 * Tests that we can parse out certain {@link JREDescriptor}s from the plist
+	 * output known to be bad - wrong data types.
+	 * <br><br>
+	 * <code>plist-bad1.xml</code> has a boolean value in place of the VM name for the 1.6 VM, 
+	 * but we should still recover the remainder of the VMs defined (3 of them)
+	 * 
+	 * @throws Exception
+	 * @since 3.8
+	 */
+	public void testParseJREDescriptorsBad() throws Exception {
+		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/plist-bad1.xml"));
+		assertNotNull(file);
+		assertEquals(true, file.exists());
+		MacInstalledJREs mij = new MacInstalledJREs();
+		JREDescriptor[] desc = mij.parseJREInfo(new FileInputStream(file));
+		assertEquals("There should be 3 JRE descriptions", 3, desc.length);
+	}
+	
+	/**
+	 * Tests that we can parse out certain {@link JREDescriptor}s from the plist
+	 * output known to be bad - missing element.
+	 * <br><br>
+	 * <code>plist-bad2.xml</code> is missing a key element - but still has the value for the key.
+	 * 
+	 * @throws Exception
+	 * @since 3.8
+	 */
+	public void testParseJREDescriptorsBad2() throws Exception {
+		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/plist-bad2.xml"));
+		assertNotNull(file);
+		assertEquals(true, file.exists());
+		MacInstalledJREs mij = new MacInstalledJREs();
+		JREDescriptor[] desc = mij.parseJREInfo(new FileInputStream(file));
+		assertEquals("There should be 3 JRE descriptions", 3, desc.length);
+	}
+	
+	/**
+	 * Tests that we can parse out certain {@link JREDescriptor}s from the plist
+	 * output known to be bad - corrupt XML syntax.
+	 * <br><br>
+	 * <code>plist-bad3.xml</code> has corrupt XML syntax
+	 * 
+	 * @throws Exception
+	 * @since 3.8
+	 */
+	public void testParseJREDescriptorsBad3() throws Exception {
+		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/plist-bad3.xml"));
+		assertNotNull(file);
+		assertEquals(true, file.exists());
+		MacInstalledJREs mij = new MacInstalledJREs();
+		JREDescriptor[] desc = mij.parseJREInfo(new FileInputStream(file));
+		assertEquals("There should be 0 JRE descriptions", 0, desc.length);
+	}
 }
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/MacInstalledJREs.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/MacInstalledJREs.java
index f39619c..f6e885f 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/MacInstalledJREs.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/MacInstalledJREs.java
@@ -12,6 +12,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -174,6 +175,21 @@
 		}
 		if (text != null && text.length() > 0) {
 			ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes());
+			return parseJREInfo(stream);
+		}
+		return NO_DESCRIPTORS;
+	}
+	
+	/**
+	 * Parse {@link JREDescriptor}s from the given input stream. The stream is expected to be in the 
+	 * XML properties format.
+	 * 
+	 * @param stream
+	 * @return the array of {@link JREDescriptor}s or an empty array never <code>null</code>
+	 * @since 3.8
+	 */
+	public JREDescriptor[] parseJREInfo(InputStream stream) {
+		try {
 			Object result = new PListParser().parse(stream);
 			if (result instanceof Object[]) {
 				Object[] maps = (Object[]) result;
@@ -197,6 +213,9 @@
 				return jres.toArray(new JREDescriptor[jres.size()]);
 			}
 		}
+		catch(CoreException ce) {
+			//do nothing fall through and return no descriptors
+		}
 		return NO_DESCRIPTORS;
 	}