Skip to content

Commit

Permalink
[Xamarin.Android.Tools.AndroidSdk] Support Microsoft Dist JDK (#117)
Browse files Browse the repository at this point in the history
Partially reverts commit 237642c.

The plan to remove support for the obsolete `microsoft_dist_openjdk_`
JDK distribution has hit a few "snags", and thus we cannot remove
support for the legacy `microsoft_dist_openjdk_` package as quickly
as we had hoped.

Re-introduce support for the `microsoft_dist_openjdk_` JDK
installation location.
  • Loading branch information
jonpryor committed Apr 26, 2021
1 parent 52ef989 commit c5732a0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public static IEnumerable<JdkInfo> GetKnownSystemJdkInfos (Action<TraceLevel, st
.Concat (AzulJdkLocations.GetAzulJdks (logger))
.Concat (OracleJdkLocations.GetOracleJdks (logger))
.Concat (VSAndroidJdkLocations.GetVSAndroidJdks (logger))
.Concat (MicrosoftDistJdkLocations.GetMicrosoftDistJdks (logger))
.Concat (GetEnvironmentVariableJdks ("JAVA_HOME", logger))
.Concat (GetPathEnvironmentJdks (logger))
.Concat (GetLibexecJdks (logger))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace Xamarin.Android.Tools {

class MicrosoftDistJdkLocations : JdkLocations {

internal static IEnumerable<JdkInfo> GetMicrosoftDistJdks (Action<TraceLevel, string> logger)
{
return FromPaths (GetMacOSMicrosoftDistJdkPaths (), logger, "$HOME/Library/Developer/Xamarin/jdk")
.Concat (GetWindowsFileSystemJdks (Path.Combine ("Android", "jdk", "microsoft_dist_openjdk_*"), logger, locator: "legacy microsoft_dist_openjdk"))
.OrderByDescending (jdk => jdk, JdkInfoVersionComparer.Default);
}

static IEnumerable<string> GetMacOSMicrosoftDistJdkPaths ()
{
var jdks = AppDomain.CurrentDomain.GetData ($"GetMacOSMicrosoftJdkPaths jdks override! {typeof (JdkInfo).AssemblyQualifiedName}")
?.ToString ();
if (jdks == null) {
var home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
jdks = Path.Combine (home, "Library", "Developer", "Xamarin", "jdk");
}
if (!Directory.Exists (jdks))
return Enumerable.Empty <string> ();

return Directory.EnumerateDirectories (jdks);
}
}
}

0 comments on commit c5732a0

Please sign in to comment.