Skip to content

Commit

Permalink
[Xamarin.Android.Tools.AndroidSdk] Add JdkInfo.GetSupportedJdkInfos() (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
tondat committed Oct 27, 2021
1 parent 34e98e2 commit fc976d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static void DetectAndSetPreferredJavaSdkPathToLatest (Action<TraceLevel,

logger = logger ?? DefaultConsoleLogger;

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

Expand Down
8 changes: 5 additions & 3 deletions src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
Expand Down Expand Up @@ -280,7 +280,7 @@ static bool AnySystemJavasInstalled ()
return props;
}

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

// Keep ordering in sync w/ GetKnownSystemJdkInfos
internal static IEnumerable<JdkInfo> GetPreferredJdkInfos (Action<TraceLevel, string> logger)
public static IEnumerable<JdkInfo> GetSupportedJdkInfos (Action<TraceLevel, string>? logger = null)
{
logger = logger ?? AndroidSdkInfo.DefaultConsoleLogger;

return MicrosoftOpenJdkLocations.GetMicrosoftOpenJdks (logger)
.Concat (EclipseAdoptiumJdkLocations.GetEclipseAdoptiumJdks (logger))
.Concat (MicrosoftDistJdkLocations.GetMicrosoftDistJdks (logger))
Expand Down

0 comments on commit fc976d8

Please sign in to comment.