From 81d54c12736bec0978f2ff153541b5d71100756a Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 15 Apr 2020 19:56:47 +0200 Subject: [PATCH] JetBrains OpenJDK 11 detection OpenJDK from JetBrains does not have the `jre` directory which, so far, has been required by the `JdkInfo` class. Instead, there's just the `lib` directory which should be searched for the JVM libraries instead of `jre`. Modify `JdkInfo` so that it first checks the `jre` directory and, failing to find it, looks for the `lib` directory in the OpenJDK installation root. The changes make Xamarin.Android.Tools detect JetBrains OpenJDK 11 properly. --- .../JdkInfo.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs b/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs index 9ec28ed..4d7f453 100644 --- a/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs +++ b/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs @@ -13,6 +13,10 @@ namespace Xamarin.Android.Tools { public class JdkInfo { + static readonly string[] JdkLibraryTopDirs = { + "jre", + "lib", + }; public string HomePath {get;} @@ -52,9 +56,23 @@ public JdkInfo (string homePath) JarPath = ProcessUtils.FindExecutablesInDirectory (binPath, "jar").FirstOrDefault (); JavaPath = ProcessUtils.FindExecutablesInDirectory (binPath, "java").FirstOrDefault (); JavacPath = ProcessUtils.FindExecutablesInDirectory (binPath, "javac").FirstOrDefault (); + + string topDir = null; + foreach (string dir in JdkLibraryTopDirs) { + topDir = Path.Combine (HomePath, dir); + if (!Directory.Exists (topDir)) { + topDir = null; + continue; + } + break; + } + + if (String.IsNullOrEmpty (topDir)) + topDir = Path.Combine (HomePath, JdkLibraryTopDirs [0]); + JdkJvmPath = OS.IsMac - ? FindLibrariesInDirectory (Path.Combine (HomePath, "jre"), "jli").FirstOrDefault () - : FindLibrariesInDirectory (Path.Combine (HomePath, "jre"), "jvm").FirstOrDefault (); + ? FindLibrariesInDirectory (topDir, "jli").FirstOrDefault () + : FindLibrariesInDirectory (topDir, "jvm").FirstOrDefault (); ValidateFile ("jar", JarPath); ValidateFile ("java", JavaPath);