Commit bdf0158
authored
Better support no installed JDKs on macOS (#48)
What happens if there is no JDK installed on macOS?
$ mv ~/Library/Developer/Xamarin/jdk ~/Library/Developer/Xamarin/jdk.bk
$ sudo mv /Library/Java/JavaVirtualMachines /Library/Java/JavaVirtualMachines.bk
`JdkInfo` doesn't like this, which is to be expected, but *how* it
doesn't like it is...bad:
$ csharp -r:bin/Debug/Xamarin.Android.Tools.AndroidSdk.dll
csharp> Xamarin.Android.Tools.JdkInfo.GetKnownSystemJdkInfos();
Error getting SDK info:
System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw (System.Exception e)
at System.Xml.XmlTextReaderImpl.Throw (System.String res, System.String arg)
at System.Xml.XmlTextReaderImpl.Throw (System.String res)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace ()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent ()
at System.Xml.XmlTextReaderImpl.Read ()
at System.Xml.XmlReader.MoveToContent ()
at System.Xml.Linq.XElement.Load (System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options)
at System.Xml.Linq.XElement.Parse (System.String text, System.Xml.Linq.LoadOptions options)
at System.Xml.Linq.XElement.Parse (System.String text)
at Xamarin.Android.Tools.JdkInfo+<GetLibexecJdkPaths>d__54.MoveNext ()
...
Er, what?
The problem is the output of `/usr/libexec/java_home -X`:
$ /usr/libexec/java_home -X
Unable to find any JVMs matching version "(null)".
<?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/>
</plist>
No Java runtime present, try --request to install.
What's happening is that `java_home` is writing XML to stdout, and an
error message to stderr. `ProcessUtils.Exec()`, meanwhile, was
*merging **both*** `stdout` and `stderr` into *one* stream, and the
result was *not* valid XML, hence the `XmlException`.
The fix? Allow `stderr` to be separate from `stdout`, so that
`JdkInfo.GetLibexecJdkPaths()` can get valid XML.
Additionally, because I'm finding it increasingly annoying needing to
provide the `logger` parameter to `AndroidSdkInfo`/etc., update the
`AndroidSdkInfo` constructor so that `logger` is *optional*. If it
isn't provided, we'll write our log messages to `System.Console`.1 parent 6353659 commit bdf0158
File tree
4 files changed
+7
-13
lines changed- src/Xamarin.Android.Tools.AndroidSdk
- Tests
4 files changed
+7
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
| |||
Lines changed: 0 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 45 | | |
53 | 46 | | |
54 | 47 | | |
| |||
0 commit comments