Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Tools.AndroidSdk] JdkInfo + JDK11 + Windows #88

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
namespace Xamarin.Android.Tools
{
public class JdkInfo {
static readonly string[] JdkLibraryTopDirs = {
"jre",
"lib",
};

public string HomePath {get;}

Expand Down Expand Up @@ -58,27 +54,14 @@ public JdkInfo (string homePath)
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 (topDir!, "jli").FirstOrDefault ()
: FindLibrariesInDirectory (topDir!, "jvm").FirstOrDefault ();
string? jdkJvmPath = GetJdkJvmPath ();

ValidateFile ("jar", JarPath);
ValidateFile ("java", JavaPath);
ValidateFile ("javac", JavacPath);
ValidateFile ("jvm", JdkJvmPath);
ValidateFile ("jvm", jdkJvmPath);

JdkJvmPath = jdkJvmPath!;

var includes = new List<string> ();
var jdkInclude = Path.Combine (HomePath, "include");
Expand Down Expand Up @@ -132,6 +115,24 @@ public bool GetJavaSettingsPropertyValue (string key, [NotNullWhen (true)] out s
return false;
}

string? GetJdkJvmPath ()
{
string jreDir = Path.Combine (HomePath, "jre");
string libDir = Path.Combine (HomePath, "lib");

if (OS.IsMac) {
return FindLibrariesInDirectory (jreDir, "jli").FirstOrDefault () ??
FindLibrariesInDirectory (libDir, "jli").FirstOrDefault ();
}
if (OS.IsWindows) {
string binServerDir = Path.Combine (HomePath, "bin", "server");
return FindLibrariesInDirectory (jreDir, "jvm").FirstOrDefault () ??
FindLibrariesInDirectory (binServerDir, "jvm").FirstOrDefault ();
}
return FindLibrariesInDirectory (jreDir, "jvm").FirstOrDefault () ??
FindLibrariesInDirectory (libDir, "jvm").FirstOrDefault ();
}

static IEnumerable<string> FindLibrariesInDirectory (string dir, string libraryName)
{
if (!Directory.Exists (dir))
Expand All @@ -140,7 +141,7 @@ static IEnumerable<string> FindLibrariesInDirectory (string dir, string libraryN
return Directory.EnumerateFiles (dir, library, SearchOption.AllDirectories);
}

void ValidateFile (string name, string path)
void ValidateFile (string name, string? path)
{
if (path == null || !File.Exists (path))
throw new ArgumentException ($"Could not find required file `{name}` within `{HomePath}`; is this a valid JDK?", "homePath");
Expand Down