Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Rennie2012-04-26 21:03:42 +0000
committerMike Rennie2012-04-26 21:03:42 +0000
commitcdee84d00f6fac0350e76b4780eda4000eae5da1 (patch)
treeccc4abf771e036ea384e425dbe14a10305090c6a
parent118a08613f14fbf910ee63d882ae035942f93cc1 (diff)
downloadeclipse.jdt.debug-cdee84d00f6fac0350e76b4780eda4000eae5da1.tar.gz
eclipse.jdt.debug-cdee84d00f6fac0350e76b4780eda4000eae5da1.tar.xz
eclipse.jdt.debug-cdee84d00f6fac0350e76b4780eda4000eae5da1.zip
from Developer Package
-rw-r--r--org.eclipse.jdt.debug.tests/testresources/plist-bad1.xml86
-rw-r--r--org.eclipse.jdt.debug.tests/testresources/plist-bad2.xml85
-rw-r--r--org.eclipse.jdt.debug.tests/testresources/plist-bad3.xml85
-rw-r--r--org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/PListParserTests.java117
-rw-r--r--org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/MacInstalledJREs.java19
5 files changed, 392 insertions, 0 deletions
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 000000000..49b4c441d
--- /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 000000000..f2b775172
--- /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 000000000..8d66dc3ea
--- /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 2bf556b10..242bb8411 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 java.util.HashMap;
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 @@ public class PListParserTests extends AbstractDebugTest {
}
}
+ /**
+ * 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 @@ public class PListParserTests extends AbstractDebugTest {
}
}
+ /**
+ * 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 @@ public class PListParserTests extends AbstractDebugTest {
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 f39619cfd..f6e885f25 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 @@ package org.eclipse.jdt.internal.launching;
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 @@ public class MacInstalledJREs {
}
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 @@ public class MacInstalledJREs {
return jres.toArray(new JREDescriptor[jres.size()]);
}
}
+ catch(CoreException ce) {
+ //do nothing fall through and return no descriptors
+ }
return NO_DESCRIPTORS;
}

Back to the top