Skip to content

Commit

Permalink
JetBrains OpenJDK 11 detection (#82)
Browse files Browse the repository at this point in the history
Context: https://bintray.com/jetbrains/intellij-jdk/openjdk11-osx-x64

OpenJDK 11 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.

These changes allow Xamarin.Android.Tools tp detect
JetBrains OpenJDK 11 properly.
  • Loading branch information
grendello committed Apr 15, 2020
1 parent 12f52ac commit 36d7fee
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
namespace Xamarin.Android.Tools
{
public class JdkInfo {
static readonly string[] JdkLibraryTopDirs = {
"jre",
"lib",
};

public string HomePath {get;}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 36d7fee

Please sign in to comment.