Skip to content

Commit

Permalink
add launcher subproject and dummy fabric.mod.json
Browse files Browse the repository at this point in the history
This lets us show an error message if the software is launched with an outdated version of Java
  • Loading branch information
UpcraftLP committed May 26, 2024
1 parent 2095de3 commit 1cb9ab6
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
33 changes: 33 additions & 0 deletions Launcher/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id 'java-library'
}

repositories {
mavenCentral()
}

dependencies {
compileOnly 'org.slf4j:slf4j-api:2.0.13'
}

configurations {
exports {
canBeConsumed = true
canBeResolved = false
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
vendor.set(JvmVendorSpec.ADOPTIUM)
}
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}

artifacts {
exports(jar)
}
41 changes: 41 additions & 0 deletions Launcher/src/main/java/dev/upcraft/axiompatcher/LauncherMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.upcraft.axiompatcher;

import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;

public class LauncherMain {

public static void main(String[] args) {
String javaVersion = System.getProperty("java.version");
int javaVersionNumber;
String[] split = javaVersion.split("\\.", 3);
if (javaVersion.startsWith("1.")) {
javaVersionNumber = Integer.parseInt(split[1]);
} else {
javaVersionNumber = Integer.parseInt(split[0]);
}

if (javaVersionNumber < 17) {
System.out.println("ERROR: You need to have Java 17 or higher installed to run this application.");
JOptionPane.showMessageDialog(null, "You need to have Java 17 or higher installed to run this application.", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
} else {
try {
Class.forName("dev.upcraft.axiompatcher.Main").getDeclaredMethod("main", String[].class).invoke(null, (Object) args);
} catch (Exception e) {
throw new RuntimeException("Unable to launch Axiom Patcher UI", e);
}
}
}

@SuppressWarnings("unused")
public static void notAMinecraftMod() {
LoggerFactory.getLogger(LauncherMain.class).error("AxiomPatcher is not a Minecraft mod, it must be run as standalone application.");
if(!GraphicsEnvironment.isHeadless()) {
JOptionPane.showMessageDialog(null, "AxiomPatcher is not a Minecraft mod, it must be run as standalone application.", "Error", JOptionPane.ERROR_MESSAGE);
}
System.exit(1);
}
}
16 changes: 15 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ javafx {
]
}

mainClassName = 'dev.upcraft.axiompatcher.Main'
mainClassName = 'dev.upcraft.axiompatcher.LauncherMain'
application {
mainClass.set(mainClassName)
}
Expand All @@ -47,6 +47,18 @@ java {
}
}

processResources {
inputs.property("version", version)
filesMatching('*.mod.json') {
expand(version: version)
}
}

tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

repositories {
mavenCentral()

Expand All @@ -65,6 +77,8 @@ dependencies {

testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'

runtimeOnly project(path: ':Launcher', configuration: 'exports')
}

test {
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ plugins {
}

rootProject.name = 'AxiomPatcher'

include 'Launcher'
14 changes: 14 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"schemaVersion": 1,
"id": "axiom-patcher",
"name": "Axiom Patcher",
"version": "${version}",
"authors": [
"Up"
],
"entrypoints": {
"preLaunch": [
"dev.upcraft.axiompatcher.LauncherMain::notAMinecraftMod"
]
}
}

0 comments on commit 1cb9ab6

Please sign in to comment.