Attempt to fix 2

This commit is contained in:
Johannes Frohnmeyer 2022-09-06 13:28:28 +02:00
parent be41e8d60d
commit 3dd66de0a7
Signed by: Johannes
GPG Key ID: E76429612C2929F4
10 changed files with 63 additions and 48 deletions

View File

@ -56,7 +56,7 @@ portable:
- mv "$main" "$dir/${main##*/}"
- curl -L "https://github.com/pal1000/mesa-dist-win/releases/download/21.2.5/mesa3d-21.2.5-release-msvc.7z" --output mesa.7z
- 7z e mesa.7z -oportable/run/natives/forceload x64/dxil.dll x64/libglapi.dll x64/opengl32.dll
- curl -L "https://api.adoptium.net/v3/binary/latest/17/ga/windows/x64/jdk/hotspot/normal/eclipse?project=jdk" --output jvm.zip
- curl -L "https://api.adoptium.net/v3/binary/latest/18/ga/windows/x64/jre/hotspot/normal/eclipse?project=jdk" --output jvm.zip
- 7z x jvm.zip -oportable/
- mv portable/jdk*/* portable/jvm/
- rm -r portable/jdk*

View File

@ -23,16 +23,6 @@ public class ConfigHolder {
}
}
CONFIG = JFiles.readObject(MetaHolder.CONFIG_PATH, Config.class);
boolean changed = false;
if (CONFIG.git == null) {
CONFIG.git = new Config.GitConfig();
changed = true;
}
if (CONFIG.git.instanceAuths == null) {
CONFIG.git.instanceAuths = new HashMap<>();
changed = true;
}
if (changed) saveConfig();
}
public static void saveConfig() {

View File

@ -13,11 +13,11 @@ public class MetaHolder {
static {
if (System.getProperty("inceptum.base") == null) {
Path runDir = getRunDir();
BASE_PATH = BuildMetadata.IS_RELEASE && !Files.exists(runDir)
BASE_PATH = (BuildMetadata.IS_RELEASE && !Files.exists(runDir)
? getConfigPath().resolve("Inceptum")
: runDir;
: runDir).toAbsolutePath();
} else {
BASE_PATH = Paths.get(System.getProperty("inceptum.base"));
BASE_PATH = Paths.get(System.getProperty("inceptum.base")).toAbsolutePath();
}
}

View File

@ -4,6 +4,7 @@ import io.gitlab.jfronny.commons.HttpUtils;
import io.gitlab.jfronny.inceptum.common.*;
import io.gitlab.jfronny.inceptum.common.model.maven.MavenDependency;
import io.gitlab.jfronny.inceptum.common.model.maven.Pom;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
@ -44,12 +45,32 @@ public class MavenApi {
boolean hasArtifactId = false;
boolean hasVersion = false;
for (Node node : iterable(doc.getDocumentElement().getChildNodes())) {
if (isWhitespace(node)) continue;
switch (node.getNodeName()) {
case "modelVersion" -> {
hasModelVersion = true;
result.modelVersion = node.getTextContent();
}
case "parent" -> {
// Dirty hack to get slf4j working: simply assume the groupId and version of the parent is also the groupId of this
if (!hasGroupId) {
for (Node child : iterable(node.getChildNodes())) {
switch (child.getNodeName()) {
case "groupId" -> {
if (!hasGroupId) {
hasGroupId = true;
result.groupId = node.getTextContent();
}
}
case "version" -> {
if (!hasVersion) {
hasVersion = true;
result.version = node.getTextContent();
}
}
}
}
}
}
case "groupId" -> {
hasGroupId = true;
result.groupId = node.getTextContent();
@ -66,8 +87,10 @@ public class MavenApi {
case "dependencies" -> {
result.dependencies = new LinkedList<>();
for (Node dep : iterable(node.getChildNodes())) {
if (isWhitespace(dep)) continue;
result.dependencies.add(parseDependency(dep));
MavenDependency resolved = parseDependency(dep);
if (resolved != null) {
result.dependencies.add(resolved);
}
}
}
default -> {}
@ -81,18 +104,13 @@ public class MavenApi {
}
}
private static boolean isWhitespace(Node node) {
return node.getNodeType() == Node.TEXT_NODE && node.getTextContent().isBlank();
}
private static MavenDependency parseDependency(Node doc) throws IOException {
private static @Nullable MavenDependency parseDependency(Node doc) throws IOException {
MavenDependency result = new MavenDependency();
boolean hasGroupId = false;
boolean hasArtifactId = false;
boolean hasVersion = false;
boolean hasScope = false;
for (Node node : iterable(doc.getChildNodes())) {
if (isWhitespace(node)) continue;
switch (node.getNodeName()) {
case "groupId" -> {
hasGroupId = true;
@ -109,22 +127,40 @@ public class MavenApi {
case "scope" -> {
hasScope = true;
result.scope = node.getTextContent();
if (!result.scope.equals("runtime")) return null;
}
case "optional" -> {
if (node.getTextContent().equals("true")) return null;
}
}
}
if (!hasGroupId) throw new IOException("Pom lacks groupId");
if (!hasArtifactId) throw new IOException("Pom lacks artifactId");
if (!hasVersion) throw new IOException("Pom lacks version");
if (!hasVersion) {
if (result.groupId.equals("org.lwjgl")) {
// Lwjgl uses a shared bom for versions which I don't want to support
// The required modules are explicit dependencies of launcher-imgui anyway
return null;
}
throw new IOException("Pom lacks version");
}
if (!hasScope) throw new IOException("Pom lacks scope");
return result;
}
private static boolean isWhitespace(Node node) {
return node.getNodeType() == Node.TEXT_NODE && node.getTextContent().isBlank();
}
private static Iterable<Node> iterable(NodeList list) {
return () -> new Iterator<>() {
int index = 0;
@Override
public boolean hasNext() {
return index < list.getLength() - 1;
while (index < list.getLength() && isWhitespace(list.item(index))) {
index++;
}
return index < list.getLength();
}
@Override

View File

@ -9,17 +9,5 @@ public class Config {
public String lastAccount;
public String offlineAccountLastName = null;
public UpdateChannel channel = UpdateChannel.Stable;
public GitConfig git = new GitConfig();
public static class GitConfig {
public Map<String, GitAuth> instanceAuths;
public String commitUsername = "Inceptum";
public String commitMail = "inceptum@jfronny.gitlab.io";
public Boolean signCommits = false;
public static class GitAuth {
public String username;
public String password;
}
}
public String authorName = "Inceptum";
}

View File

@ -20,8 +20,7 @@ tasks.shadowJar {
exclude("META-INF/**")
}
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
(components["java"] as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
skip()
}

View File

@ -20,7 +20,7 @@ public class LauncherEnv {
private static EnvBackend backend;
public static void checkClassLoaderState() {
if (Utils.class.getClassLoader() != LauncherEnv.class.getClassLoader()) {
if (MetaHolder.class.getClassLoader() != LauncherEnv.class.getClassLoader()) {
throw new IllegalStateException("Mismatching classloader between two classes. Something is wrong here");
}
}

View File

@ -46,7 +46,7 @@ public class InstanceExporter {
manifest.manifestVersion = 1;
manifest.name = instanceDir.getFileName().toString();
manifest.version = version;
manifest.author = ConfigHolder.CONFIG.git.commitUsername;
manifest.author = ConfigHolder.CONFIG.authorName;
manifest.overrides = OVERRIDES_DIR_DEFAULT;
Path overrides = fs.getPath(OVERRIDES_DIR_DEFAULT);
Files.createDirectories(overrides);

View File

@ -5,21 +5,25 @@ import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.inceptum.common.*;
import io.gitlab.jfronny.inceptum.common.model.inceptum.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
public class Wrapper {
public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, URISyntaxException {
Utils.setSystemLoader(WrapperStrap.SYSTEM_LOADER);
MetaHolder.setWrapperFlag();
System.out.println("Inceptum Wrapper v" + BuildMetadata.VERSION);
System.out.println("Loading from " + MetaHolder.BASE_PATH);
InceptumEnvironmentInitializer.initialize();
List<Path> classpath = getClasspath();
if (!BuildMetadata.IS_RELEASE) {
System.out.println("Using classpath: " + classpath.stream().map(Path::toString).collect(Collectors.joining("" + File.pathSeparator)));
}
String[] newArgs = new String[args.length + 1];
newArgs[0] = "wrapper";
System.arraycopy(args, 0, newArgs, 1, args.length);

View File

@ -1,19 +1,17 @@
package io.gitlab.jfronny.inceptum;
import io.gitlab.jfronny.inceptum.common.Utils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.*;
import java.util.Set;
public class WrapperStrap {
public static final ClassLoader SYSTEM_LOADER = ClassLoader.getSystemClassLoader();
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException, URISyntaxException {
Utils.LOGGER.info("Starting Inceptum Wrapper ClassLoader");
System.out.println("Starting Inceptum Wrapper ClassLoader");
bootstrap(Set.of(new File(WrapperStrap.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath()),
"io.gitlab.jfronny.inceptum.Wrapper",
args);