From 022f5d503a390b2920299745cee1309a22402afb Mon Sep 17 00:00:00 2001
From: Jonathan Pryor <jonpryor@vt.edu>
Date: Tue, 17 Aug 2021 17:02:38 -0400
Subject: [PATCH] [Xamarin.Android.Tools.AndroidSdk] Eclipse Adoptium support

Context: https://blog.adoptopenjdk.net/2021/03/transition-to-eclipse-an-update/
Context: https://projects.eclipse.org/projects/adoptium

AdoptOpenJDK has moved to the Eclipse foundation, and made two name
changes in the process:

 1. The project is now known as Eclipse Adoptium.
 2. The macOS installation directory now matches the file glob
    `temurin-*.jdk`, not `adoptopenjdk-*.jdk`.
 3. The Windows installation directory now installs into e.g.
    `%ProgramFiles%\Eclipse Foundation\jdk-*`.

Rename `AdoptOpenJdkLocations.cs` to `EclipseAdoptiumJdkLocations.cs`,
and check for *both* the "legacy" AdoptOpenJDK and new EclipseAdoptium
paths.
---
 .../JdkInfo.cs                                |  3 ++-
 .../Jdks/AdoptOpenJdkLocations.cs             | 20 ----------------
 .../Jdks/EclipseAdoptiumJdkLocations.cs       | 23 +++++++++++++++++++
 3 files changed, 25 insertions(+), 21 deletions(-)
 delete mode 100644 src/Xamarin.Android.Tools.AndroidSdk/Jdks/AdoptOpenJdkLocations.cs
 create mode 100644 src/Xamarin.Android.Tools.AndroidSdk/Jdks/EclipseAdoptiumJdkLocations.cs

diff --git a/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs b/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs
index 00a0f9fd..19c32535 100644
--- a/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs
+++ b/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs
@@ -289,7 +289,7 @@ public static IEnumerable<JdkInfo> GetKnownSystemJdkInfos (Action<TraceLevel, st
 				.Concat (JdkLocations.GetPreferredJdks (logger))
 				.Concat (XAPrepareJdkLocations.GetXAPrepareJdks (logger))
 				.Concat (MicrosoftOpenJdkLocations.GetMicrosoftOpenJdks (logger))
-				.Concat (AdoptOpenJdkLocations.GetAdoptOpenJdks (logger))
+				.Concat (EclipseAdoptiumJdkLocations.GetEclipseAdoptiumJdks (logger))
 				.Concat (AzulJdkLocations.GetAzulJdks (logger))
 				.Concat (OracleJdkLocations.GetOracleJdks (logger))
 				.Concat (VSAndroidJdkLocations.GetVSAndroidJdks (logger))
@@ -305,6 +305,7 @@ public static IEnumerable<JdkInfo> GetKnownSystemJdkInfos (Action<TraceLevel, st
 		internal static IEnumerable<JdkInfo> GetPreferredJdkInfos (Action<TraceLevel, string> logger)
 		{
 			return MicrosoftOpenJdkLocations.GetMicrosoftOpenJdks (logger)
+				.Concat (EclipseAdoptiumJdkLocations.GetEclipseAdoptiumJdks (logger))
 				.Concat (MicrosoftDistJdkLocations.GetMicrosoftDistJdks (logger))
 				;
 		}
diff --git a/src/Xamarin.Android.Tools.AndroidSdk/Jdks/AdoptOpenJdkLocations.cs b/src/Xamarin.Android.Tools.AndroidSdk/Jdks/AdoptOpenJdkLocations.cs
deleted file mode 100644
index 581033da..00000000
--- a/src/Xamarin.Android.Tools.AndroidSdk/Jdks/AdoptOpenJdkLocations.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Text;
-
-namespace Xamarin.Android.Tools {
-
-	class AdoptOpenJdkLocations : JdkLocations {
-
-		internal static IEnumerable<JdkInfo> GetAdoptOpenJdks (Action<TraceLevel, string> logger)
-		{
-			return GetMacOSSystemJdks ("adoptopenjdk-*.jdk", logger)
-				.Concat (GetWindowsFileSystemJdks (Path.Combine ("AdoptOpenJDK", "jdk-*"), logger))
-				.Concat (GetWindowsRegistryJdks (logger, @"SOFTWARE\AdoptOpenJDK\JDK", "*", @"hotspot\MSI", "Path"))
-				.OrderByDescending (jdk => jdk, JdkInfoVersionComparer.Default);
-		}
-	}
-}
diff --git a/src/Xamarin.Android.Tools.AndroidSdk/Jdks/EclipseAdoptiumJdkLocations.cs b/src/Xamarin.Android.Tools.AndroidSdk/Jdks/EclipseAdoptiumJdkLocations.cs
new file mode 100644
index 00000000..d9d9b75c
--- /dev/null
+++ b/src/Xamarin.Android.Tools.AndroidSdk/Jdks/EclipseAdoptiumJdkLocations.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace Xamarin.Android.Tools {
+
+	class EclipseAdoptiumJdkLocations : JdkLocations {
+
+		internal static IEnumerable<JdkInfo> GetEclipseAdoptiumJdks (Action<TraceLevel, string> logger)
+		{
+			return GetMacOSSystemJdks ("temurin-*.jdk", logger)
+				.Concat (GetMacOSSystemJdks ("adoptopenjdk-*.jdk", logger))
+				.Concat (GetWindowsFileSystemJdks (Path.Combine ("AdoptOpenJDK", "jdk-*"), logger))
+				.Concat (GetWindowsRegistryJdks (logger, @"SOFTWARE\AdoptOpenJDK\JDK", "*", @"hotspot\MSI", "Path"))
+				.Concat (GetWindowsFileSystemJdks (Path.Combine ("Eclipse Foundation", "jdk-*"), logger))
+				.Concat (GetWindowsRegistryJdks (logger, @"SOFTWARE\Eclipse Foundation\JDK", "*", @"hotspot\MSI", "Path"))
+				.OrderByDescending (jdk => jdk, JdkInfoVersionComparer.Default);
+		}
+	}
+}
