Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read mc & java version from version.json #64

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ local.properties
.factorypath
.apt_generated/

# VSCode stuff
.vscode/
.classpath

# macOS
.DS_Store

Expand All @@ -42,4 +46,4 @@ ehthumbs_vista.db
.gradletasknamecache

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.ja
!gradle-wrapper.jar
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ subprojects {
val mainClass = "io.papermc.paperclip.Main"

tasks.jar {
val java6Jar = project(":java6").tasks.named("jar")
val java6Jar = project(":java6").tasks.named("shadowJar")
val java17Jar = project(":java17").tasks.named("shadowJar")
dependsOn(java6Jar, java17Jar)

Expand Down
19 changes: 19 additions & 0 deletions java6/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
plugins {
java
id("com.github.johnrengelman.shadow") version "8.1.1"
}

repositories {
mavenCentral()
}

dependencies {
implementation("com.eclipsesource.minimal-json:minimal-json:0.9.5")
}

java {
Expand All @@ -14,3 +23,13 @@ tasks.withType<JavaCompile>().configureEach {
options.release.set(6)
options.compilerArgs = listOf("-Xlint:-options")
}

tasks.shadowJar {
val prefix = "paperclip.libs"
listOf("com.eclipsesource").forEach { pack ->
relocate(pack, "$prefix.$pack")
}

exclude("META-INF/LICENSE.txt")
exclude("META-INF/NOTICE.txt")
}
38 changes: 35 additions & 3 deletions java6/src/main/java/io/papermc/paperclip/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,46 @@

package io.papermc.paperclip;

import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;

import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;

public final class Main {

private static final JsonObject VERSION = readJsonFile();

private static JsonObject readJsonFile() {
final JsonObject object;

InputStreamReader reader = null;

try {
reader = new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("version.json"), "UTF_8");
object = Json.parse(reader).asObject();
} catch (final IOException exc) {
throw new RuntimeException("Failed to read version.json", exc);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

return object;
}

public static void main(final String[] args) {
if (getJavaVersion() < 17) {
System.err.println("Minecraft 1.19 requires running the server with Java 17 or above. " +
"Download Java 17 (or above) from https://adoptium.net/");
final int javaVersion = VERSION.getInt("java_version", 17);
final String minecraftVersion = VERSION.getString("name", "Unknown");
if (getJavaVersion() < javaVersion) {
System.err.printf("Minecraft %s requires running the server with Java %s or above. " +
"Download Java %s (or above) from https://adoptium.net/", minecraftVersion, javaVersion, javaVersion);
System.exit(1);
}

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ plugins {
}

rootProject.name = "paperclip"
include("java6", "java17")
include("java6", "java17")