Skip to content

Commit ad6c171

Browse files
committed
icanhaz Zulu support?
1 parent 237642c commit ad6c171

9 files changed

Lines changed: 189 additions & 2 deletions

File tree

Xamarin.Android.Tools.sln

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio Version 16
33
VisualStudioVersion = 16.0.30709.64
44
MinimumVisualStudioVersion = 10.0.40219.1
@@ -10,6 +10,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Android.Build.Bas
1010
EndProject
1111
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Android.Build.BaseTasks-Tests", "tests\Microsoft.Android.Build.BaseTasks-Tests\Microsoft.Android.Build.BaseTasks-Tests.csproj", "{4F5FD01C-B5A6-4F9F-91CE-3E78B3F942AC}"
1212
EndProject
13+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{19FE1B44-DB71-4F97-A07E-085888690DAE}"
14+
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ls-jdks", "tools\ls-jdks\ls-jdks.csproj", "{3D2ADF77-62C7-4E0E-AB29-BDD266B7D56D}"
16+
EndProject
1317
Global
1418
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1519
Debug|Any CPU = Debug|Any CPU
@@ -32,11 +36,18 @@ Global
3236
{4F5FD01C-B5A6-4F9F-91CE-3E78B3F942AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
3337
{4F5FD01C-B5A6-4F9F-91CE-3E78B3F942AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
3438
{4F5FD01C-B5A6-4F9F-91CE-3E78B3F942AC}.Release|Any CPU.Build.0 = Release|Any CPU
39+
{3D2ADF77-62C7-4E0E-AB29-BDD266B7D56D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{3D2ADF77-62C7-4E0E-AB29-BDD266B7D56D}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{3D2ADF77-62C7-4E0E-AB29-BDD266B7D56D}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{3D2ADF77-62C7-4E0E-AB29-BDD266B7D56D}.Release|Any CPU.Build.0 = Release|Any CPU
3543
EndGlobalSection
3644
GlobalSection(SolutionProperties) = preSolution
3745
HideSolutionNode = FALSE
3846
EndGlobalSection
3947
GlobalSection(ExtensibilityGlobals) = postSolution
4048
SolutionGuid = {BA1CD771-F00B-4DE8-93EE-7690D81F6A5A}
4149
EndGlobalSection
50+
GlobalSection(NestedProjects) = preSolution
51+
{3D2ADF77-62C7-4E0E-AB29-BDD266B7D56D} = {19FE1B44-DB71-4F97-A07E-085888690DAE}
52+
EndGlobalSection
4253
EndGlobal

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ public static IEnumerable<JdkInfo> GetKnownSystemJdkInfos (Action<TraceLevel, st
288288
.Concat (GetWindowsJdks (logger))
289289
.Concat (GetConfiguredJdks (logger))
290290
.Concat (GetMacOSMicrosoftOpenJdks (logger))
291+
.Concat (MicrosoftOpenJdkLocations.GetMicrosoftOpenJdks (logger))
292+
.Concat (AzulJdkLocations.GetAzulJdks (logger))
291293
.Concat (GetEnvironmentVariableJdks ("JAVA_HOME", logger))
292294
.Concat (GetPathEnvironmentJdks (logger))
293295
.Concat (GetLibexecJdks (logger))
@@ -356,7 +358,7 @@ static IEnumerable<string> GetMacOSMicrosoftOpenJdkPaths ()
356358
}
357359
}
358360

359-
static JdkInfo? TryGetJdkInfo (string path, Action<TraceLevel, string> logger, string locator)
361+
internal static JdkInfo? TryGetJdkInfo (string path, Action<TraceLevel, string> logger, string locator)
360362
{
361363
JdkInfo? jdk = null;
362364
try {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace Xamarin.Android.Tools {
9+
10+
class AzulJdkLocations : JdkLocations {
11+
12+
internal static IEnumerable<JdkInfo> GetAzulJdks (Action<TraceLevel, string> logger)
13+
{
14+
return GetMacOSSystemJdks ("zulu-*.jdk", logger)
15+
.Concat (GetWindowsFileSystemJdks (Path.Combine ("Zulu", "zulu-*"), logger))
16+
.OrderByDescending (jdk => jdk, JdkInfoVersionComparer.Default);
17+
}
18+
}
19+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
7+
namespace Xamarin.Android.Tools {
8+
9+
partial class JdkLocations {
10+
11+
const string MacOSJavaVirtualMachinesRoot = "/Library/Java/JavaVirtualMachines";
12+
13+
protected static IEnumerable<JdkInfo> GetMacOSSystemJdks (string pattern, Action<TraceLevel, string> logger, string? locator = null)
14+
{
15+
if (!OS.IsMac) {
16+
return Array.Empty<JdkInfo>();
17+
}
18+
locator = locator ?? Path.Combine (MacOSJavaVirtualMachinesRoot, pattern);
19+
return FromPaths (GetMacOSSystemJvmPaths (pattern), logger, locator);
20+
}
21+
22+
static IEnumerable<string> GetMacOSSystemJvmPaths (string pattern)
23+
{
24+
var root = MacOSJavaVirtualMachinesRoot;
25+
var toHome = Path.Combine ("Contents", "Home");
26+
var jdks = AppDomain.CurrentDomain.GetData ($"GetMacOSMicrosoftJdkPaths jdks override! {typeof (JdkInfo).AssemblyQualifiedName}")
27+
?.ToString ();
28+
if (jdks != null) {
29+
root = jdks;
30+
toHome = "";
31+
pattern = "*";
32+
}
33+
if (!Directory.Exists (root)) {
34+
yield break;
35+
}
36+
foreach (var dir in Directory.EnumerateDirectories (root, pattern)) {
37+
var home = Path.Combine (dir, toHome);
38+
if (!Directory.Exists (home))
39+
continue;
40+
yield return home;
41+
}
42+
}
43+
}
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
7+
namespace Xamarin.Android.Tools {
8+
9+
partial class JdkLocations {
10+
11+
protected static IEnumerable<JdkInfo> GetWindowsFileSystemJdks (string pattern, Action<TraceLevel, string> logger, string? locator = null)
12+
{
13+
if (!OS.IsWindows) {
14+
yield break;
15+
}
16+
17+
var roots = new List<string>() {
18+
// "Compatibility" with existing codebases; should probably be avoided…
19+
Environment.ExpandEnvironmentVariables ("%ProgramW6432%"),
20+
Environment.GetFolderPath (Environment.SpecialFolder.ProgramFiles),
21+
Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86),
22+
};
23+
foreach (var root in roots) {
24+
if (!Directory.Exists (root))
25+
continue;
26+
foreach (var home in Directory.EnumerateDirectories (root, pattern)) {
27+
if (!File.Exists (Path.Combine (home, "bin", "jarsigner.exe")))
28+
continue;
29+
var loc = locator ?? $"{pattern} via {root}";
30+
var jdk = JdkInfo.TryGetJdkInfo (home, logger, loc);
31+
if (jdk == null)
32+
continue;
33+
yield return jdk;
34+
}
35+
}
36+
}
37+
38+
protected static IEnumerable<JdkInfo> GetWindowsRegistryJdks (Action<TraceLevel, string> logger, string? locator = null)
39+
{
40+
yield break;
41+
}
42+
}
43+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
7+
namespace Xamarin.Android.Tools {
8+
9+
partial class JdkLocations {
10+
11+
protected static IEnumerable<JdkInfo> FromPaths (IEnumerable<string> paths, Action<TraceLevel, string> logger, string locator)
12+
{
13+
return paths
14+
.Select (p => JdkInfo.TryGetJdkInfo (p, logger, locator))
15+
.Where (jdk => jdk != null)
16+
.Select (jdk => jdk!);
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace Xamarin.Android.Tools {
9+
10+
class MicrosoftOpenJdkLocations : JdkLocations {
11+
12+
internal static IEnumerable<JdkInfo> GetMicrosoftOpenJdks (Action<TraceLevel, string> logger)
13+
{
14+
return GetMacOSSystemJdks ("microsoft-*.jdk", logger)
15+
.Concat (GetWindowsFileSystemJdks (Path.Combine ("Microsoft", "jdk-*"), logger))
16+
.OrderByDescending (jdk => jdk, JdkInfoVersionComparer.Default);
17+
}
18+
}
19+
}

tools/ls-jdks/App.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace Xamarin.Android.Tools
4+
{
5+
class App
6+
{
7+
static void Main(string[] args)
8+
{
9+
foreach (var jdk in JdkInfo.GetKnownSystemJdkInfos ()) {
10+
Console.WriteLine ($"Found JDK: {jdk.HomePath}");
11+
Console.WriteLine ($" Locator: {jdk.Locator}");
12+
}
13+
}
14+
}
15+
}

tools/ls-jdks/ls-jdks.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
6+
<RootNamespace>Xamarin.Android.Tools</RootNamespace>
7+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
8+
<OutputPath>$(ToolOutputFullPath)</OutputPath>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

0 commit comments

Comments
 (0)