diff --git a/build.gradle.kts b/build.gradle.kts index a6ff467..107a6b5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,12 +3,12 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { - id("com.github.johnrengelman.shadow") version "8.1.1" apply false - id("io.freefair.lombok") version "8.6" apply false + id("com.github.johnrengelman.shadow") version "8.+" apply false + id("io.freefair.lombok") version "8.+" apply false } group = "cc.polyfrost.oneconfig" -version = "1.1.0-alpha.3" +version = "1.1.0-alpha.4" allprojects { apply(plugin = "maven-publish") diff --git a/common/src/main/java/org/polyfrost/oneconfig/loader/utils/IOUtils.java b/common/src/main/java/org/polyfrost/oneconfig/loader/utils/IOUtils.java index 66a4f99..9a06557 100644 --- a/common/src/main/java/org/polyfrost/oneconfig/loader/utils/IOUtils.java +++ b/common/src/main/java/org/polyfrost/oneconfig/loader/utils/IOUtils.java @@ -1,10 +1,14 @@ package org.polyfrost.oneconfig.loader.utils; +import org.jetbrains.annotations.NotNull; + import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.jar.Manifest; /** * Utility class for IO operations. @@ -93,4 +97,46 @@ public static byte[] readNBytes(InputStream inputStream, int len) throws IOExcep return result; } + + public static @NotNull String provideImplementationVersion( + Class clazz, String unknownVersion + ) { + String packageVersion = clazz.getPackage().getImplementationVersion(); + if (packageVersion != null) { + return packageVersion; + } + + // Fabric / old Quilt don't currently support this, so we'll parse the Manifest + URL manifestUrl = clazz.getResource("/META-INF/MANIFEST.MF"); + if (manifestUrl == null) { + return unknownVersion; + } + + Throwable error = null; + InputStream is = null; + try { + is = manifestUrl.openStream(); + Manifest manifest = new Manifest(is); + String version = manifest.getMainAttributes().getValue("Implementation-Version"); + if (version == null) { + return unknownVersion; + } + return version; + } catch (IOException e) { + error = e; + throw new RuntimeException("Error while reading Jar manifest file", e); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + if (error != null) { + error.addSuppressed(e); + } else { + throw new RuntimeException("Failed to close InputStream", e); + } + } + } + } + } } diff --git a/gradle.properties b/gradle.properties index 4fa5b63..51e4ffa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,13 @@ loom.platform=forge + +# Gradle properties +org.gradle.caching=true org.gradle.parallel=true -org.gradle.jvmargs=-Xmx4G +org.gradle.configureondemand=true +org.gradle.parallel.threads=4 +org.gradle.dependency.verification=strict +org.gradle.kotlin.dsl.allWarningsAsErrors=true +org.gradle.configuration-cache=true +org.gradle.jvmargs=-Xmx4G -Dfile.encoding=UTF-8 +org.gradle.kotlin.dsl.precompiled.accessors.strict=true +kotlin.code.style=official diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02..0d18421 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/stage0/src/main/java/org/polyfrost/oneconfig/loader/stage0/Stage0Loader.java b/stage0/src/main/java/org/polyfrost/oneconfig/loader/stage0/Stage0Loader.java index 00b9320..846b20b 100644 --- a/stage0/src/main/java/org/polyfrost/oneconfig/loader/stage0/Stage0Loader.java +++ b/stage0/src/main/java/org/polyfrost/oneconfig/loader/stage0/Stage0Loader.java @@ -1,15 +1,11 @@ package org.polyfrost.oneconfig.loader.stage0; import lombok.SneakyThrows; -import org.jetbrains.annotations.NotNull; import org.polyfrost.oneconfig.loader.LoaderBase; +import org.polyfrost.oneconfig.loader.utils.IOUtils; import javax.swing.*; import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.jar.Manifest; /** * The first stage of the OneConfig Loader. @@ -26,12 +22,14 @@ public class Stage0Loader extends LoaderBase { Stage0Loader(Capabilities capabilities) { super( "stage0", - provideImplementationVersion(), + IOUtils.provideImplementationVersion( + Stage0Loader.class, UNKNOWN_VERSION + ), capabilities ); } - private static final String FILE_PATH = + private static final String TEST_FILE_PATH = "/home/x/Work/Polyfrost/test/build/libs/test-1.0-SNAPSHOT.jar"; @SneakyThrows @@ -39,7 +37,7 @@ public class Stage0Loader extends LoaderBase { public void load() { capabilities.appendToClassPath( false, - new File(FILE_PATH).toURI().toURL() + new File(TEST_FILE_PATH).toURI().toURL() ); // Class testingClass = capabilities.getClassLoader().loadClass("me.xtrm.test.Testing2"); // testingClass.getMethod("hi").invoke(null); @@ -56,45 +54,4 @@ public void load() { // Delegate loading to stage1 logger.info("GO"); } - - private static @NotNull String provideImplementationVersion() { - String packageVersion = - Stage0Loader.class.getPackage().getImplementationVersion(); - if (packageVersion != null) { - return packageVersion; - } - - // Fabric / Quilt don't currently support this, so we'll parse the Manifest - URL manifestUrl = Stage0Loader.class.getResource("/META-INF/MANIFEST.MF"); - if (manifestUrl == null) { - return UNKNOWN_VERSION; - } - - Throwable error = null; - InputStream is = null; - try { - is = manifestUrl.openStream(); - Manifest manifest = new Manifest(is); - String version = manifest.getMainAttributes().getValue("Implementation-Version"); - if (version == null) { - return UNKNOWN_VERSION; - } - return version; - } catch (IOException e) { - error = e; - throw new RuntimeException("Error while reading Jar manifest file", e); - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - if (error != null) { - error.addSuppressed(e); - } else { - throw new RuntimeException("Failed to close InputStream", e); - } - } - } - } - } }