From dab06a4ff0d591dfbfc7d4f6dc2b5f8d49cb3168 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Mon, 3 Dec 2018 12:29:30 -0600 Subject: [PATCH] Check if system Java is installed This checks for /System/Library/Java/JavaVirtualMachines if we're trying to use the system java. If there is no system Java installed then calling /usr/bin/java has the unfortunate effect of popping up a dialog telling the user to install a JDK. Fixes VSTS #735545 --- .../JdkInfo.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs b/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs index 2a3d92eb..25e36346 100644 --- a/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs +++ b/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs @@ -192,6 +192,23 @@ Dictionary> GetJavaProperties () return GetJavaProperties (ProcessUtils.FindExecutablesInDirectory (Path.Combine (HomePath, "bin"), "java").First ()); } + static bool AnySystemJavasInstalled () + { + if (OS.IsMac) { + string path = Path.Combine (Path.DirectorySeparatorChar + "System", "Library", "Java", "JavaVirtualMachines"); + if (!Directory.Exists (path)) { + return false; + } + + string[] dirs = Directory.GetDirectories (path); + if (dirs == null || dirs.Length == 0) { + return false; + } + } + + return true; + } + static Dictionary> GetJavaProperties (string java) { var javaProps = new ProcessStartInfo { @@ -201,6 +218,10 @@ static Dictionary> GetJavaProperties (string java) var props = new Dictionary> (); string curKey = null; + + if (!AnySystemJavasInstalled () && (java == "/usr/bin/java" || java == "java")) + return props; + ProcessUtils.Exec (javaProps, (o, e) => { const string ContinuedValuePrefix = " "; const string NewValuePrefix = " ";