Skip to content

Commit

Permalink
🔨 chore: small reorganization
Browse files Browse the repository at this point in the history
Signed-off-by: xtrm <oss@xtrm.me>
  • Loading branch information
xtrm-en committed Jun 22, 2024
1 parent ad86824 commit 200c365
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 54 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}
}
}
}
}
}
12 changes: 11 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -26,20 +22,22 @@ 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
@Override
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);
Expand All @@ -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);
}
}
}
}
}
}

0 comments on commit 200c365

Please sign in to comment.