Skip to content

expose the api to get preferred jdk infos #142

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

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
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
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 Dictionary<string, List<string>> GetJavaProperties (string java)
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a file logger that can be used? What if the process doesn't have a console?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client is responsible to set the logger, in our case XamarinVS caller.

I have added it to be compatible with all the methods in this class that check the logger or assign the default if it is a null parameter


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