Major JDK version number is verified before using local JAVA_HOME
This commit is contained in:
Родитель
5474916e91
Коммит
f9392183f7
|
@ -1,17 +1,18 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Bee.BuildTools;
|
using Bee.BuildTools;
|
||||||
using Bee.Core;
|
using Bee.Core;
|
||||||
using Bee.Core.Stevedore;
|
using Bee.Core.Stevedore;
|
||||||
using Bee.NativeProgramSupport;
|
using Bee.NativeProgramSupport;
|
||||||
|
using Bee.ProjectGeneration.VisualStudio;
|
||||||
using Bee.Toolchain.Android;
|
using Bee.Toolchain.Android;
|
||||||
using Bee.Toolchain.GNU;
|
using Bee.Toolchain.GNU;
|
||||||
using Bee.Tools;
|
using Bee.Tools;
|
||||||
using NiceIO;
|
|
||||||
using Bee.ProjectGeneration.VisualStudio;
|
|
||||||
using Bee.VisualStudioSolution;
|
using Bee.VisualStudioSolution;
|
||||||
using System.Linq;
|
using NiceIO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required environment variables:
|
* Required environment variables:
|
||||||
|
@ -186,8 +187,12 @@ class JniBridge
|
||||||
static Jdk SetupJava()
|
static Jdk SetupJava()
|
||||||
{
|
{
|
||||||
var jdk = Jdk.UserDefault;
|
var jdk = Jdk.UserDefault;
|
||||||
if (jdk != null)
|
if (jdk != null && IsValidJdkVersion(jdk.JavaHome.ToString(), out var version))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Using Java version {version} from {jdk.JavaHome}");
|
||||||
return jdk;
|
return jdk;
|
||||||
|
}
|
||||||
|
|
||||||
var openJdk = StevedoreArtifact.UnityInternal(HostPlatform.Pick(
|
var openJdk = StevedoreArtifact.UnityInternal(HostPlatform.Pick(
|
||||||
linux: "open-jdk-linux-x64/jdk17.0.9-9_8d1cbcce56285f3146cf7761353a643fe573b39e45bd94f35590dca39277f667.zip",
|
linux: "open-jdk-linux-x64/jdk17.0.9-9_8d1cbcce56285f3146cf7761353a643fe573b39e45bd94f35590dca39277f667.zip",
|
||||||
mac: "open-jdk-mac-x64/jdk17.0.9-9_388f7edd2524a9235650fa7cf531302e4676b80526b2d6a0fa199d030779169d.zip",
|
mac: "open-jdk-mac-x64/jdk17.0.9-9_388f7edd2524a9235650fa7cf531302e4676b80526b2d6a0fa199d030779169d.zip",
|
||||||
|
@ -196,6 +201,26 @@ class JniBridge
|
||||||
return new Jdk(openJdk.Path.ResolveWithFileSystem());
|
return new Jdk(openJdk.Path.ResolveWithFileSystem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsValidJdkVersion(string javaHomePath, out string version)
|
||||||
|
{
|
||||||
|
var versionFilePath = Path.Combine(javaHomePath, "version.txt");
|
||||||
|
if (File.Exists(versionFilePath))
|
||||||
|
{
|
||||||
|
version = File.ReadAllText(versionFilePath).Trim();
|
||||||
|
var firstDotIndex = version.IndexOf('.');
|
||||||
|
var majorVersion = firstDotIndex != -1 ? version.Substring(0, firstDotIndex) : version;
|
||||||
|
if (majorVersion == kJavaVersion) return true;
|
||||||
|
else Console.WriteLine($"Found Java version {majorVersion}, but required version is {kJavaVersion}. JDK from Stevedore will be used.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{versionFilePath} file not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
version = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static NPath SetupAndroidSdk()
|
static NPath SetupAndroidSdk()
|
||||||
{
|
{
|
||||||
var sdk = Environment.GetEnvironmentVariable("ANDROID_SDK_ROOT");
|
var sdk = Environment.GetEnvironmentVariable("ANDROID_SDK_ROOT");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче