Skip to content

Commit 0658bc6

Browse files
authored
[Xamarin.Android.Tools.AndroidSdk] OS-specific dirs are OS-specific (#250)
OS-specific JDK locators should only be attempted on the OS that they're intended for: macOS-specific JDK probe mechanisms such as `/usr/libexec/java_home -X` should only be used on macOS, and Linux-specific JDK probe mechanisms such as looking at `/usr/lib/jvm/*` should only be done on Linux.
1 parent ac8d0ee commit 0658bc6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ static IEnumerable<JdkInfo> GetLibexecJdks (Action<TraceLevel, string> logger)
383383

384384
static IEnumerable<string> GetLibexecJdkPaths (Action<TraceLevel, string> logger)
385385
{
386+
if (!OS.IsMac) {
387+
yield break;
388+
}
389+
386390
var java_home = Path.GetFullPath ("/usr/libexec/java_home");
387391
if (!File.Exists (java_home)) {
388392
yield break;
@@ -429,6 +433,10 @@ static IEnumerable<JdkInfo> GetJavaAlternativesJdks (Action<TraceLevel, string>
429433

430434
static IEnumerable<string> GetJavaAlternativesJdkPaths ()
431435
{
436+
if (!OS.IsLinux) {
437+
return Enumerable.Empty<string> ();
438+
}
439+
432440
var alternatives = Path.GetFullPath ("/usr/sbin/update-java-alternatives");
433441
if (!File.Exists (alternatives))
434442
return Enumerable.Empty<string> ();
@@ -464,6 +472,10 @@ static IEnumerable<JdkInfo> GetLibJvmJdks (Action<TraceLevel, string> logger)
464472

465473
static IEnumerable<string> GetLibJvmJdkPaths ()
466474
{
475+
if (!OS.IsLinux) {
476+
yield break;
477+
}
478+
467479
var jvm = "/usr/lib/jvm";
468480
if (!Directory.Exists (jvm))
469481
yield break;

src/Xamarin.Android.Tools.AndroidSdk/Jdks/MicrosoftDistJdkLocations.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ internal static IEnumerable<JdkInfo> GetMicrosoftDistJdks (Action<TraceLevel, st
1818

1919
static IEnumerable<string> GetMacOSMicrosoftDistJdkPaths ()
2020
{
21+
if (!OS.IsMac) {
22+
return Array.Empty<string> ();
23+
}
24+
2125
var jdks = AppDomain.CurrentDomain.GetData ($"GetMacOSMicrosoftJdkPaths jdks override! {typeof (JdkInfo).AssemblyQualifiedName}")
2226
?.ToString ();
2327
if (jdks == null) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class OS
1111
{
1212
public readonly static bool IsWindows;
1313
public readonly static bool IsMac;
14+
public readonly static bool IsLinux;
1415

1516
internal readonly static string? ProgramFilesX86;
1617

@@ -20,6 +21,7 @@ static OS ()
2021
{
2122
IsWindows = Path.DirectorySeparatorChar == '\\';
2223
IsMac = !IsWindows && IsRunningOnMac ();
24+
IsLinux = !IsWindows && !IsMac;
2325

2426
if (IsWindows) {
2527
ProgramFilesX86 = GetProgramFilesX86 ();
@@ -29,7 +31,7 @@ static OS ()
2931
NativeLibraryFormat = "{0}.dll";
3032
if (IsMac)
3133
NativeLibraryFormat = "lib{0}.dylib";
32-
if (!IsWindows && !IsMac)
34+
if (IsLinux)
3335
NativeLibraryFormat = "lib{0}.so";
3436
}
3537

0 commit comments

Comments
 (0)