mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 12:56:53 -04:00
Improve the format of openjfx-dependencies.json
This commit is contained in:
parent
e0f7d9cd32
commit
05fdea3267
@ -45,17 +45,13 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import org.jackhuang.hmcl.util.io.ChecksumMismatchException;
|
import org.jackhuang.hmcl.util.io.ChecksumMismatchException;
|
||||||
import org.jackhuang.hmcl.util.io.IOUtils;
|
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||||
import org.jackhuang.hmcl.util.platform.Architecture;
|
import org.jackhuang.hmcl.util.platform.Platform;
|
||||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UncheckedIOException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -80,77 +76,37 @@ public final class SelfDependencyPatcher {
|
|||||||
static class DependencyDescriptor {
|
static class DependencyDescriptor {
|
||||||
|
|
||||||
private static final Path DEPENDENCIES_DIR_PATH = HMCL_DIRECTORY.resolve("dependencies");
|
private static final Path DEPENDENCIES_DIR_PATH = HMCL_DIRECTORY.resolve("dependencies");
|
||||||
public static final String CURRENT_ARCH_CLASSIFIER = currentArchClassifier();
|
|
||||||
public static final List<DependencyDescriptor> JFX_DEPENDENCIES = readDependencies();
|
public static final List<DependencyDescriptor> JFX_DEPENDENCIES = readDependencies();
|
||||||
|
|
||||||
private static List<DependencyDescriptor> readDependencies() {
|
private static List<DependencyDescriptor> readDependencies() {
|
||||||
String content;
|
//noinspection ConstantConditions
|
||||||
try (InputStream in = SelfDependencyPatcher.class.getResourceAsStream(DEPENDENCIES_LIST_FILE)) {
|
try (Reader reader = new InputStreamReader(SelfDependencyPatcher.class.getResourceAsStream(DEPENDENCIES_LIST_FILE), UTF_8)) {
|
||||||
content = IOUtils.readFullyAsString(in, UTF_8);
|
Map<String, List<DependencyDescriptor>> allDependencies =
|
||||||
|
new Gson().fromJson(reader, new TypeToken<Map<String, List<DependencyDescriptor>>>(){}.getType());
|
||||||
|
return allDependencies.get(Platform.getPlatform().toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
return new Gson().fromJson(content, TypeToken.getParameterized(List.class, DependencyDescriptor.class).getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String currentArchClassifier() {
|
|
||||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
|
|
||||||
switch (Architecture.CURRENT_ARCH) {
|
|
||||||
case X86_64:
|
|
||||||
return "linux";
|
|
||||||
case ARM32:
|
|
||||||
return "linux-arm32-monocle";
|
|
||||||
case ARM64:
|
|
||||||
return "linux-aarch64";
|
|
||||||
}
|
|
||||||
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX) {
|
|
||||||
switch (Architecture.CURRENT_ARCH) {
|
|
||||||
case X86_64:
|
|
||||||
return "mac";
|
|
||||||
case ARM64:
|
|
||||||
return "mac-aarch64";
|
|
||||||
}
|
|
||||||
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
|
|
||||||
switch (Architecture.CURRENT_ARCH) {
|
|
||||||
case X86_64:
|
|
||||||
return "win";
|
|
||||||
case X86:
|
|
||||||
return "win-x86";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String module;
|
public String module;
|
||||||
public String groupId;
|
public String groupId;
|
||||||
public String artifactId;
|
public String artifactId;
|
||||||
public String version;
|
public String version;
|
||||||
public Map<String, String> sha1;
|
public String classifier;
|
||||||
|
public String sha1;
|
||||||
|
|
||||||
public String filename() {
|
public String filename() {
|
||||||
if (CURRENT_ARCH_CLASSIFIER == null) {
|
return artifactId + "-" + version + "-" + classifier + ".jar";
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return artifactId + "-" + version + "-" + CURRENT_ARCH_CLASSIFIER + ".jar";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sha1() {
|
public String sha1() {
|
||||||
if (CURRENT_ARCH_CLASSIFIER == null) {
|
return sha1;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return sha1.get(CURRENT_ARCH_CLASSIFIER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path localPath() {
|
public Path localPath() {
|
||||||
if (CURRENT_ARCH_CLASSIFIER == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return DEPENDENCIES_DIR_PATH.resolve(filename());
|
return DEPENDENCIES_DIR_PATH.resolve(filename());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSupported() {
|
|
||||||
return CURRENT_ARCH_CLASSIFIER != null && sha1.containsKey(CURRENT_ARCH_CLASSIFIER);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Repository {
|
static final class Repository {
|
||||||
@ -222,7 +178,7 @@ public final class SelfDependencyPatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We can only self-patch JavaFX on specific platform.
|
// We can only self-patch JavaFX on specific platform.
|
||||||
if (DependencyDescriptor.CURRENT_ARCH_CLASSIFIER == null) {
|
if (JFX_DEPENDENCIES == null) {
|
||||||
throw new IncompatibleVersionException();
|
throw new IncompatibleVersionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,12 +253,10 @@ public final class SelfDependencyPatcher {
|
|||||||
LOG.info(" - Loading dependencies...");
|
LOG.info(" - Loading dependencies...");
|
||||||
|
|
||||||
Set<String> modules = JFX_DEPENDENCIES.stream()
|
Set<String> modules = JFX_DEPENDENCIES.stream()
|
||||||
.filter(DependencyDescriptor::isSupported)
|
|
||||||
.map(it -> it.module)
|
.map(it -> it.module)
|
||||||
.collect(toSet());
|
.collect(toSet());
|
||||||
|
|
||||||
Path[] jars = JFX_DEPENDENCIES.stream()
|
Path[] jars = JFX_DEPENDENCIES.stream()
|
||||||
.filter(DependencyDescriptor::isSupported)
|
|
||||||
.map(DependencyDescriptor::localPath)
|
.map(DependencyDescriptor::localPath)
|
||||||
.toArray(Path[]::new);
|
.toArray(Path[]::new);
|
||||||
|
|
||||||
@ -396,9 +350,6 @@ public final class SelfDependencyPatcher {
|
|||||||
List<DependencyDescriptor> missing = new ArrayList<>();
|
List<DependencyDescriptor> missing = new ArrayList<>();
|
||||||
|
|
||||||
for (DependencyDescriptor dependency : JFX_DEPENDENCIES) {
|
for (DependencyDescriptor dependency : JFX_DEPENDENCIES) {
|
||||||
if (!dependency.isSupported()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!Files.exists(dependency.localPath())) {
|
if (!Files.exists(dependency.localPath())) {
|
||||||
missing.add(dependency);
|
missing.add(dependency);
|
||||||
continue;
|
continue;
|
||||||
|
100
build.gradle.kts
100
build.gradle.kts
@ -104,24 +104,37 @@ tasks.create("checkTranslations") {
|
|||||||
|
|
||||||
defaultTasks("clean", "build")
|
defaultTasks("clean", "build")
|
||||||
|
|
||||||
|
data class Platform(
|
||||||
|
val name: String,
|
||||||
|
val classifier: String,
|
||||||
|
val groupId: String = "org.openjfx",
|
||||||
|
val unsupportedModules: List<String> = listOf()
|
||||||
|
) {
|
||||||
|
val modules: List<String> = jfxModules.filter { it !in unsupportedModules }
|
||||||
|
|
||||||
|
fun fileUrl(
|
||||||
|
module: String, classifier: String, ext: String,
|
||||||
|
repo: String = "https://repo1.maven.org/maven2"
|
||||||
|
): java.net.URL =
|
||||||
|
java.net.URL(
|
||||||
|
"$repo/${groupId.replace('.', '/')}/javafx-$module/$jfxVersion/javafx-$module-$jfxVersion-$classifier.$ext"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val jfxModules = listOf("base", "graphics", "controls", "fxml", "media", "web")
|
val jfxModules = listOf("base", "graphics", "controls", "fxml", "media", "web")
|
||||||
val jfxClassifier = listOf(
|
|
||||||
"linux", "linux-arm32-monocle", "linux-aarch64",
|
|
||||||
"mac", "mac-aarch64",
|
|
||||||
"win", "win-x86"
|
|
||||||
)
|
|
||||||
val jfxVersion = "17"
|
val jfxVersion = "17"
|
||||||
val jfxMirrorRepos = listOf("https://maven.aliyun.com/repository/central")
|
val jfxMirrorRepos = listOf("https://maven.aliyun.com/repository/central")
|
||||||
val jfxDependenciesFile = project("HMCL").buildDir.resolve("openjfx-dependencies.json")
|
val jfxDependenciesFile = project("HMCL").buildDir.resolve("openjfx-dependencies.json")
|
||||||
val jfxUnsupported = mapOf(
|
val jfxPlatforms = listOf(
|
||||||
"linux-arm32-monocle" to listOf("media", "web")
|
Platform("windows-x86", "win-x86"),
|
||||||
|
Platform("windows-x86_64", "win"),
|
||||||
|
Platform("osx-x86_64", "mac"),
|
||||||
|
Platform("osx-arm64", "mac-aarch64"),
|
||||||
|
Platform("linux-x86_64", "linux"),
|
||||||
|
Platform("linux-arm32", "linux-arm32-monocle", unsupportedModules = listOf("media", "web")),
|
||||||
|
Platform("linux-arm64", "linux-aarch64"),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun isSupported(module: String, classifier: String) = when (classifier) {
|
|
||||||
"linux-arm32-monocle" -> module != "media" && module != "web"
|
|
||||||
else -> true
|
|
||||||
}
|
|
||||||
|
|
||||||
val jfxInClasspath =
|
val jfxInClasspath =
|
||||||
try {
|
try {
|
||||||
Class.forName("javafx.application.Application", false, this.javaClass.classLoader)
|
Class.forName("javafx.application.Application", false, this.javaClass.classLoader)
|
||||||
@ -134,23 +147,28 @@ if (!jfxInClasspath && JavaVersion.current() >= JavaVersion.VERSION_11) {
|
|||||||
val os = System.getProperty("os.name").toLowerCase().let { osName ->
|
val os = System.getProperty("os.name").toLowerCase().let { osName ->
|
||||||
when {
|
when {
|
||||||
osName.contains("win") -> "win"
|
osName.contains("win") -> "win"
|
||||||
osName.contains("mac") -> "mac"
|
osName.contains("mac") -> "osx"
|
||||||
osName.contains("linux") || osName.contains("unix") -> "linux"
|
osName.contains("linux") || osName.contains("unix") -> "linux"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val classifier = if (os == null) null else when (System.getProperty("os.arch").toLowerCase()) {
|
val arch = when (System.getProperty("os.arch").toLowerCase()) {
|
||||||
"x86_64", "x86-64", "amd64", "ia32e", "em64t", "x64" -> os
|
"x86_64", "x86-64", "amd64", "ia32e", "em64t", "x64" -> "x86_64"
|
||||||
"x86", "x86_32", "x86-32", "i386", "i486", "i586", "i686", "i86pc", "ia32", "x32" -> "$os-x86"
|
"x86", "x86_32", "x86-32", "i386", "i486", "i586", "i686", "i86pc", "ia32", "x32" -> "x86"
|
||||||
"arm64", "aarch64", "armv8", "armv9" -> "$os-aarch64"
|
"arm64", "aarch64", "armv8", "armv9" -> "arm64"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classifier != null && classifier in jfxClassifier) {
|
if (os != null && arch != null) {
|
||||||
rootProject.subprojects {
|
val platform = jfxPlatforms.find { it.name == "$os-arch" }
|
||||||
for (module in jfxModules) {
|
if (platform != null) {
|
||||||
dependencies.add("compileOnly", "org.openjfx:javafx-$module:$jfxVersion:$classifier")
|
val groupId = platform.groupId
|
||||||
|
val classifier = platform.classifier
|
||||||
|
rootProject.subprojects {
|
||||||
|
for (module in jfxModules) {
|
||||||
|
dependencies.add("compileOnly", "$groupId:javafx-$module:$jfxVersion:$classifier")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,18 +178,17 @@ rootProject.tasks.create("generateOpenJFXDependencies") {
|
|||||||
outputs.file(jfxDependenciesFile)
|
outputs.file(jfxDependenciesFile)
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
val jfxDependencies = jfxModules.map { module ->
|
val jfxDependencies = jfxPlatforms.associate { platform ->
|
||||||
linkedMapOf(
|
platform.name to platform.modules.map { module ->
|
||||||
"module" to "javafx.$module",
|
mapOf(
|
||||||
"groupId" to "org.openjfx",
|
"module" to "javafx.$module",
|
||||||
"artifactId" to "javafx-$module",
|
"groupId" to platform.groupId,
|
||||||
"version" to jfxVersion,
|
"artifactId" to "javafx-$module",
|
||||||
"sha1" to jfxClassifier.filter { classifier -> isSupported(module, classifier) }
|
"version" to jfxVersion,
|
||||||
.associateWith { classifier ->
|
"classifier" to platform.classifier,
|
||||||
java.net.URL("https://repo1.maven.org/maven2/org/openjfx/javafx-$module/$jfxVersion/javafx-$module-$jfxVersion-$classifier.jar.sha1")
|
"sha1" to platform.fileUrl(module, platform.classifier, "jar.sha1").readText()
|
||||||
.readText()
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jfxDependenciesFile.parentFile.mkdirs()
|
jfxDependenciesFile.parentFile.mkdirs()
|
||||||
@ -185,16 +202,13 @@ rootProject.tasks.create("generateOpenJFXDependencies") {
|
|||||||
rootProject.tasks.create("preTouchOpenJFXDependencies") {
|
rootProject.tasks.create("preTouchOpenJFXDependencies") {
|
||||||
doLast {
|
doLast {
|
||||||
for (repo in jfxMirrorRepos) {
|
for (repo in jfxMirrorRepos) {
|
||||||
for (module in jfxModules) {
|
for (platform in jfxPlatforms) {
|
||||||
for (classifier in jfxClassifier) {
|
for (module in platform.modules) {
|
||||||
if (isSupported(module, classifier)) {
|
val url = platform.fileUrl(module, platform.classifier, "jar")
|
||||||
val jarUrl =
|
try {
|
||||||
java.net.URL("$repo/org/openjfx/javafx-$module/$jfxVersion/javafx-$module-$jfxVersion-$classifier.jar")
|
url.readBytes()
|
||||||
try {
|
} catch (e: Throwable) {
|
||||||
jarUrl.readBytes()
|
logger.warn("An exception occurred while pre touching $url", e)
|
||||||
} catch (e: Throwable) {
|
|
||||||
logger.warn("An exception occurred while pre touching $jarUrl", e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user