Attempt to add launchwrapper, replacing manual forceload library injection

This commit is contained in:
Johannes Frohnmeyer 2022-09-18 19:28:26 +02:00
parent d2c0979d16
commit 67bb89abe7
Signed by: Johannes
GPG Key ID: E76429612C2929F4
10 changed files with 84 additions and 14 deletions

View File

@ -23,8 +23,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class Updater { public class Updater {
private static final long PROJECT_ID = 30862253L;
private static final String PROJECT_MAVEN = "https://gitlab.com/api/v4/projects/" + PROJECT_ID + "/packages/maven/";
public static UpdateMetadata getUpdate() { public static UpdateMetadata getUpdate() {
return Updater.check(InceptumConfig.channel, BuildMetadata.VERSION, channel -> { return Updater.check(InceptumConfig.channel, BuildMetadata.VERSION, channel -> {
@ -116,7 +114,7 @@ public class Updater {
private static DependencyNode downloadLibrary(Set<String> repositories, final String artifact, Set<String> libraries) throws IOException, URISyntaxException { private static DependencyNode downloadLibrary(Set<String> repositories, final String artifact, Set<String> libraries) throws IOException, URISyntaxException {
List<Exception> exceptions = new LinkedList<>(); List<Exception> exceptions = new LinkedList<>();
for (String repository : Stream.concat(Stream.of(PROJECT_MAVEN), repositories.stream()).toList()) { for (String repository : Stream.concat(Stream.of(GitlabApi.PROJECT_MAVEN), repositories.stream()).toList()) {
Pom pom; Pom pom;
try { try {
pom = MavenApi.getPom(repository, artifact); pom = MavenApi.getPom(repository, artifact);
@ -149,7 +147,7 @@ public class Updater {
public static @Nullable UpdateMetadata check(UpdateChannel channel, ComparableVersion current, Consumer<UpdateChannel> channelInvalid) { public static @Nullable UpdateMetadata check(UpdateChannel channel, ComparableVersion current, Consumer<UpdateChannel> channelInvalid) {
try { try {
int jvm = Runtime.version().feature(); int jvm = Runtime.version().feature();
GitlabProject project = GitlabApi.getProject(PROJECT_ID); GitlabProject project = GitlabApi.getProject(GitlabApi.PROJECT_ID);
UpdateMetadata experimental = null; UpdateMetadata experimental = null;
UpdateMetadata stable = null; UpdateMetadata stable = null;
packageLoop:for (GitlabPackage info : GitlabApi.getPackages(project)) { packageLoop:for (GitlabPackage info : GitlabApi.getPackages(project)) {
@ -204,6 +202,6 @@ public class Updater {
} }
public static String getShadowJarUrl(UpdateMetadata metadata) { public static String getShadowJarUrl(UpdateMetadata metadata) {
return PROJECT_MAVEN + "io/gitlab/jfronny/inceptum/Inceptum/" + metadata.version + "/Inceptum-" + metadata.version + "-" + Utils.getCurrentFlavor() + ".jar"; return GitlabApi.PROJECT_MAVEN + "io/gitlab/jfronny/inceptum/Inceptum/" + metadata.version + "/Inceptum-" + metadata.version + "-" + Utils.getCurrentFlavor() + ".jar";
} }
} }

View File

@ -12,6 +12,10 @@ import java.util.function.Predicate;
public class GitlabApi { public class GitlabApi {
public static final String PROJECTS = "https://gitlab.com/api/v4/projects/"; public static final String PROJECTS = "https://gitlab.com/api/v4/projects/";
public static final long PROJECT_ID = 30862253L;
public static final String PROJECT_MAVEN = "https://gitlab.com/api/v4/projects/" + PROJECT_ID + "/packages/maven/";
private static final Type packageInfoListType = new TypeToken<List<GitlabPackage>>() {}.getType(); private static final Type packageInfoListType = new TypeToken<List<GitlabPackage>>() {}.getType();
private static final Type jobListType = new TypeToken<List<GitlabJob>>() {}.getType(); private static final Type jobListType = new TypeToken<List<GitlabJob>>() {}.getType();
private static final Type packageFileInfoListType = new TypeToken<List<GitlabPackageFile>>() {}.getType(); private static final Type packageFileInfoListType = new TypeToken<List<GitlabPackageFile>>() {}.getType();

View File

@ -25,6 +25,10 @@ It also adds additional, platform-specific commands to the CLI.
A shadowed build can be obtained as "Inceptum" from maven, a build with dependencies as "launcher-dist" A shadowed build can be obtained as "Inceptum" from maven, a build with dependencies as "launcher-dist"
Windows users can also obtain a binary built using fabric-installer-native-bootstrap. Windows users can also obtain a binary built using fabric-installer-native-bootstrap.
## launchwrapper
This module is added to the minecraft classpath and therefore independent of any other modules.
It handles loading forceload natives
## wrapper ## wrapper
This module serves the purpose of downloading the components necessary for executing Inceptum on the current platform. This module serves the purpose of downloading the components necessary for executing Inceptum on the current platform.
A build with shadowed dependencies can be obtained through the maven (with the suffix "all") or as a jar. A build with shadowed dependencies can be obtained through the maven (with the suffix "all") or as a jar.

View File

@ -2,7 +2,6 @@ package io.gitlab.jfronny.inceptum.launcher.system.export;
import java.util.List; import java.util.List;
//TODO modrinth export
public class Exporters { public class Exporters {
public static final int STEP_COUNT = 4; public static final int STEP_COUNT = 4;
public static final CurseForgeExporter CURSE_FORGE = new CurseForgeExporter(); public static final CurseForgeExporter CURSE_FORGE = new CurseForgeExporter();

View File

@ -1,12 +1,11 @@
package io.gitlab.jfronny.inceptum.launcher.system.install.steps; package io.gitlab.jfronny.inceptum.launcher.system.install.steps;
import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.inceptum.common.MetaHolder; import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.common.Net; import io.gitlab.jfronny.inceptum.common.Net;
import io.gitlab.jfronny.inceptum.launcher.model.mojang.*;
import io.gitlab.jfronny.inceptum.launcher.api.McApi; import io.gitlab.jfronny.inceptum.launcher.api.McApi;
import io.gitlab.jfronny.inceptum.launcher.system.install.Step; import io.gitlab.jfronny.inceptum.launcher.model.mojang.*;
import io.gitlab.jfronny.inceptum.launcher.system.install.SetupStepInfo; import io.gitlab.jfronny.inceptum.launcher.system.install.SetupStepInfo;
import io.gitlab.jfronny.inceptum.launcher.system.install.Step;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -42,7 +41,5 @@ public class DownloadJavaStep implements Step {
case "directory" -> Files.createDirectories(tPath); case "directory" -> Files.createDirectories(tPath);
} }
} }
//TODO link these in using a pre-launch class added to the launch classpath instead
JFiles.copyRecursive(MetaHolder.FORCE_LOAD_PATH, jvmDir.resolve("bin"));
} }
} }

View File

@ -2,6 +2,8 @@ package io.gitlab.jfronny.inceptum.launcher.system.install.steps;
import io.gitlab.jfronny.commons.io.JFiles; import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.inceptum.common.*; import io.gitlab.jfronny.inceptum.common.*;
import io.gitlab.jfronny.inceptum.common.api.GitlabApi;
import io.gitlab.jfronny.inceptum.common.api.MavenApi;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ArtifactInfo; import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ArtifactInfo;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta; import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.model.mojang.VersionInfo; import io.gitlab.jfronny.inceptum.launcher.model.mojang.VersionInfo;
@ -48,5 +50,18 @@ public class DownloadLibrariesStep implements Step {
} }
} }
} }
String artifact = getLaunchWrapperArtifact();
if (!Files.exists(MetaHolder.LIBRARIES_DIR.resolve(MavenApi.mavenNotationToJarPath(artifact)))) {
try {
MavenApi.downloadLibrary(GitlabApi.PROJECT_MAVEN, artifact);
} catch (URISyntaxException e) {
throw new IOException("Could not download launchwrapper", e);
}
}
}
public static String getLaunchWrapperArtifact() {
return "io.gitlab.jfronny.inceptum:launchwrapper:" + (BuildMetadata.IS_PUBLIC ? BuildMetadata.VERSION : Updater.getUpdate().version);
} }
} }

View File

@ -81,8 +81,10 @@ public class InstanceLauncher {
classPath.append(MetaHolder.LIBRARIES_DIR.resolve(artifact.path).toAbsolutePath()); classPath.append(MetaHolder.LIBRARIES_DIR.resolve(artifact.path).toAbsolutePath());
classPath.append(File.pathSeparatorChar); classPath.append(File.pathSeparatorChar);
} }
Path gameJar = MetaHolder.LIBRARIES_DIR.resolve("net/minecraft/" + launchType.name).resolve(versionDataSimple.id + ".jar").toAbsolutePath(); Path gameJar = MetaHolder.LIBRARIES_DIR.resolve("net/minecraft/" + launchType.name).resolve(versionDataSimple.id + ".jar");
classPath.append(gameJar); classPath.append(gameJar);
classPath.append(File.pathSeparatorChar);
classPath.append(MetaHolder.LIBRARIES_DIR.resolve(DownloadLibrariesStep.getLaunchWrapperArtifact()));
// JVM arguments // JVM arguments
if (launchType == LaunchType.Client && versionInfo.arguments != null) if (launchType == LaunchType.Client && versionInfo.arguments != null)
args.addAll(parse(versionInfo.arguments.jvm, versionInfo, instance, classPath.toString(), instancePath.toAbsolutePath().toString(), authInfo)); args.addAll(parse(versionInfo.arguments.jvm, versionInfo, instance, classPath.toString(), instancePath.toAbsolutePath().toString(), authInfo));
@ -90,7 +92,11 @@ public class InstanceLauncher {
if (instance.maxMem != null) args.add("-Xmx" + instance.maxMem); if (instance.maxMem != null) args.add("-Xmx" + instance.maxMem);
if (instance.arguments != null && instance.arguments.jvm != null) args.addAll(instance.arguments.jvm); if (instance.arguments != null && instance.arguments.jvm != null) args.addAll(instance.arguments.jvm);
// Native library path // Native library path
args.add("-Djava.library.path=" + MetaHolder.NATIVES_DIR.resolve(instance.getMinecraftVersion()).toAbsolutePath()); args.add("-Djava.library.path=" + MetaHolder.NATIVES_DIR.resolve(instance.getMinecraftVersion()));
// Forceload natives
if (Files.exists(MetaHolder.FORCE_LOAD_PATH)) {
args.add("-Dinceptum.forceloadNatives=" + MetaHolder.FORCE_LOAD_PATH);
}
// Fabric imods // Fabric imods
if (instance.isFabric()) { if (instance.isFabric()) {
StringBuilder fabricAddMods = new StringBuilder("-Dfabric.addMods="); StringBuilder fabricAddMods = new StringBuilder("-Dfabric.addMods=");
@ -114,6 +120,8 @@ public class InstanceLauncher {
// Add classpath to args // Add classpath to args
args.add("-cp"); args.add("-cp");
args.add(classPath.toString()); args.add(classPath.toString());
// Wrapper class (launched by vm, launches main class)
args.add("io.gitlab.jfronny.inceptum.launchwrapper.Main");
// Main class // Main class
args.add(resolveMainClass(instance, versionInfo, gameJar, launchType)); args.add(resolveMainClass(instance, versionInfo, gameJar, launchType));
// Game arguments // Game arguments

View File

@ -0,0 +1,11 @@
plugins {
id("inceptum.library-conventions")
}
java {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
}

View File

@ -0,0 +1,33 @@
package io.gitlab.jfronny.inceptum.launchwrapper;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.*;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
if (args.length == 0) throw new IllegalArgumentException("Missing class argument");
String forceloadNatives = System.getProperty("inceptum.forceloadNatives");
if (forceloadNatives != null) {
Path p = Paths.get(forceloadNatives);
if (Files.exists(p)) {
try (Stream<Path> paths = Files.list(p)) {
paths.forEach(Main::load);
}
} else {
throw new IllegalArgumentException("Could not find forceloadNatives path");
}
}
Class<?> mainClass = Class.forName(args[0]);
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, args.length - 1);
mainClass.getMethod("main", String[].class).invoke(null, new Object[] {newArgs});
}
private static void load(Path path) {
System.load(path.toAbsolutePath().normalize().toString());
}
}

View File

@ -5,4 +5,5 @@ include("wrapper")
include("launcher") include("launcher")
include("launcher-cli") include("launcher-cli")
include("launcher-imgui") include("launcher-imgui")
include("launcher-dist") include("launcher-dist")
include("launchwrapper")