Skip to content

Commit

Permalink
chore: Adjust java lookup, required workloads filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Nov 27, 2023
1 parent 42eff59 commit fae286b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion UnoCheck/CheckCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, CheckSettin

private async Task<bool> NeedsToolUpdateAsync(CheckSettings settings)
{
if (settings.Manifest is not null && !settings.CI)
if ( (settings.Manifest is not null && !settings.CI) || Debugger.IsAttached)
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions UnoCheck/Checkups/DotNetWorkloadsCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DotNetWorkloadsCheckup(SharedState sharedState, string sdkVersion, Manife

SdkRoot = dotnet.DotNetSdkLocation.FullName;
SdkVersion = sdkVersion;
RequiredWorkloads = requiredWorkloads;
RequiredWorkloads = requiredWorkloads.Where(w => w.SupportedPlatforms?.Contains(Util.Platform) ?? false).ToArray();
NuGetPackageSources = nugetPackageSources;
}

Expand Down Expand Up @@ -68,7 +68,7 @@ public override async Task<DiagnosticResult> Examine(SharedState history)

var missingWorkloads = new List<Manifest.DotNetWorkload>();

foreach (var rp in RequiredWorkloads.Where(w => w.SupportedPlatforms?.Contains(Util.Platform) ?? false))
foreach (var rp in RequiredWorkloads)
{
var versionParts = rp.Version.Split("/", StringSplitOptions.None);
var workloadVersion = versionParts.First();
Expand Down
50 changes: 42 additions & 8 deletions UnoCheck/Checkups/OpenJdkCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Xamarin.Android.Tools;
Expand Down Expand Up @@ -43,7 +44,7 @@ public bool RequireExact
static string PlatformJavaCExtension => Util.IsWindows ? ".exe" : string.Empty;

public override bool IsPlatformSupported(Platform platform)
=> platform == Platform.OSX || platform == Platform.Windows;
=> platform == Platform.OSX || platform == Platform.Windows || platform == Platform.Linux;

public override bool ShouldExamine(SharedState history)
=> Manifest?.Check?.OpenJdk != null;
Expand Down Expand Up @@ -87,7 +88,8 @@ public override Task<DiagnosticResult> Examine(SharedState history)
{
Environment.SetEnvironmentVariable("JAVA_HOME", jdk.Directory.FullName, EnvironmentVariableTarget.Machine);
ReportStatus($"Set Environment Variable: JAVA_HOME={jdk.Directory.FullName}", Status.Ok);
} catch { }
}
catch { }
}
}
else
Expand All @@ -97,10 +99,18 @@ public override Task<DiagnosticResult> Examine(SharedState history)
if (ok)
return Task.FromResult(DiagnosticResult.Ok(this));

var url = Manifest?.Check?.OpenJdk?.Url;
return Task.FromResult(new DiagnosticResult(Status.Error, this,
new Suggestion("Install OpenJDK11",
new BootsSolution(url, "Download and Install Microsoft OpenJDK 11"))));
if (Util.IsLinux)
{
return Task.FromResult(new DiagnosticResult(Status.Error, this,
new Suggestion("Install OpenJDK11", "OpenJDK 11 is missing, follow the installation instructions here: https://learn.microsoft.com/en-us/java/openjdk/install#install-on-ubuntu")));
}
else
{
var url = Manifest?.Check?.OpenJdk?.Url;
return Task.FromResult(new DiagnosticResult(Status.Error, this,
new Suggestion("Install OpenJDK11",
new BootsSolution(url, "Download and Install Microsoft OpenJDK 11"))));
}
}

IEnumerable<OpenJdkInfo> FindJdks()
Expand Down Expand Up @@ -130,7 +140,8 @@ IEnumerable<OpenJdkInfo> FindJdks()

SearchDirectoryForJdks(paths,
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Microsoft", "Jdk"), true);
} else if (Util.IsMac)
}
else if (Util.IsMac)
{
var ms11Dir = Path.Combine("/Library", "Java", "JavaVirtualMachines", "microsoft-11.jdk", "Contents", "Home");
SearchDirectoryForJdks(paths, ms11Dir, true);
Expand Down Expand Up @@ -163,14 +174,37 @@ IEnumerable<OpenJdkInfo> FindJdks()
SearchDirectoryForJdks(paths, Environment.GetEnvironmentVariable("JAVA_HOME") ?? string.Empty, true);
SearchDirectoryForJdks(paths, Environment.GetEnvironmentVariable("JDK_HOME") ?? string.Empty, true);

var environmentPaths = Environment.GetEnvironmentVariable("PATH")?.Split(';') ?? Array.Empty<string>();
var environmentPaths = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) ?? Array.Empty<string>();

foreach (var envPath in environmentPaths)
{
if (envPath.Contains("java", StringComparison.OrdinalIgnoreCase) || envPath.Contains("jdk", StringComparison.OrdinalIgnoreCase))
SearchDirectoryForJdks(paths, envPath, true);
}

if (Util.IsLinux)
{
var r = ShellProcessRunner.Run("whereis", "-b javac");

if (
r.Success
&& r.StandardOutput.Count > 0
&& r.StandardOutput[0].Split(" ").Skip(1).FirstOrDefault() is { } javacBinPath)
{
var readlinkResult = ShellProcessRunner.Run("readlink", "-f " + javacBinPath);

if (
readlinkResult.Success
&& r.StandardOutput.Count > 0)
{
if (TryGetJavaJdkInfo(readlinkResult.StandardOutput[0], out var jdkInfo))
{
paths.Add(jdkInfo);
}
}
}
}

return paths
.GroupBy(i => i.JavaC.FullName)
.Select(g => g.First());
Expand Down
4 changes: 2 additions & 2 deletions UnoCheck/DotNet/DotNetWorkloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public async Task Install(Manifest.DotNetWorkload[] workloads)

string WriteRollbackFile(Manifest.DotNetWorkload[] workloads)
{
var workloadRolback = GetInstalledWorkloadManifestIdsAndVersions();
var workloadRollback = GetInstalledWorkloadManifestIdsAndVersions();

foreach (var workload in workloads)
workloadRolback[workload.WorkloadManifestId] = workload.Version;
workloadRollback[workload.WorkloadManifestId] = workload.Version;

var json = new StringBuilder();
json.AppendLine("{");
Expand Down
7 changes: 6 additions & 1 deletion UnoCheck/Manifest/Urls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public partial class Urls
[JsonProperty("linux", NullValueHandling = NullValueHandling.Ignore)]
public Uri Linux { get; set; }

[JsonProperty("linuxArm64", NullValueHandling = NullValueHandling.Ignore)]
public Uri LinuxArm64 { get; set; }

public Uri Get(string version, Platform? platform = default)
{
var uri = For(platform ?? Util.Platform)?.ToString();
Expand All @@ -49,7 +52,9 @@ Uri For(Platform platform)
: (Util.Is64
? Win64 ?? Win
: Win),
Platform.Linux => Linux,
Platform.Linux => Util.IsArm64
? (LinuxArm64 ?? Linux)
: Linux,
_ => Win
};
}
Expand Down
5 changes: 4 additions & 1 deletion manifests/uno.ui.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
"openjdk": {
"version": "11.0",
"urls": {
// Sources https://learn.microsoft.com/en-us/java/openjdk/download#openjdk-11
"win64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-windows-x64.msi",
"winArm64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-windows-aarch64.msi",
"osx": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-macos-x64.pkg",
"osxArm64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-macos-aarch64.pkg"
"osxArm64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-macos-aarch64.pkg",
"linux": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-linux-x64.tar.gz",
"linuxArm64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-linux-aarch64.tar.gz"
}
},
"xcode": {
Expand Down

0 comments on commit fae286b

Please sign in to comment.