Skip to content

Commit fc976d8

Browse files
authored
[Xamarin.Android.Tools.AndroidSdk] Add JdkInfo.GetSupportedJdkInfos() (#142)
Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1415418 Visual Studio needs to know the list of supported JDKs, so that it can appropriately compare and display them to the user as part of a "reset to defaults" experience. The list of "supported" JDKs was formerly provided by the *`internal`* `JdkInfo.GetPreferredJdkInfos()` method. Rename `JdkInfo.GetPreferredJdkInfos()` to `JdkInfo.GetSupportedJdkInfos()`, and make `public`. The rename is done to reduce ambiguity over what the "preferred" *means*, so that in public APIs it only means "whatever the user has previously selected, as per the Windows Registry/`monodroid-config.xml`/etc.
1 parent 34e98e2 commit fc976d8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static void DetectAndSetPreferredJavaSdkPathToLatest (Action<TraceLevel,
185185

186186
logger = logger ?? DefaultConsoleLogger;
187187

188-
var latestJdk = JdkInfo.GetPreferredJdkInfos (logger).FirstOrDefault ();
188+
var latestJdk = JdkInfo.GetSupportedJdkInfos (logger).FirstOrDefault ();
189189
if (latestJdk == null)
190190
throw new NotSupportedException ("No Microsoft OpenJDK could be found. Please re-run the Visual Studio installer or manually specify the JDK path in settings.");
191191

src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Diagnostics;
@@ -280,7 +280,7 @@ static Dictionary<string, List<string>> GetJavaProperties (string java)
280280
return props;
281281
}
282282

283-
// Keep ordering in sync w/ GetPreferredJdkInfos
283+
// Keep ordering in sync w/ GetSupportedJdkInfos
284284
public static IEnumerable<JdkInfo> GetKnownSystemJdkInfos (Action<TraceLevel, string>? logger = null)
285285
{
286286
logger = logger ?? AndroidSdkInfo.DefaultConsoleLogger;
@@ -302,8 +302,10 @@ public static IEnumerable<JdkInfo> GetKnownSystemJdkInfos (Action<TraceLevel, st
302302
}
303303

304304
// Keep ordering in sync w/ GetKnownSystemJdkInfos
305-
internal static IEnumerable<JdkInfo> GetPreferredJdkInfos (Action<TraceLevel, string> logger)
305+
public static IEnumerable<JdkInfo> GetSupportedJdkInfos (Action<TraceLevel, string>? logger = null)
306306
{
307+
logger = logger ?? AndroidSdkInfo.DefaultConsoleLogger;
308+
307309
return MicrosoftOpenJdkLocations.GetMicrosoftOpenJdks (logger)
308310
.Concat (EclipseAdoptiumJdkLocations.GetEclipseAdoptiumJdks (logger))
309311
.Concat (MicrosoftDistJdkLocations.GetMicrosoftDistJdks (logger))

0 commit comments

Comments
 (0)