diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 2cb7307..0416b61 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -5,7 +5,7 @@ plugins { description = "A collection of utils and structures for the rest of the project"; tasks.processResources { - filesMatching("metadata.json", { + filesMatching("metadata", { expand( "version" to properties["project_version"], "name" to properties["project_name"], diff --git a/common/src/main/java/me/topchetoeu/j2s/common/Metadata.java b/common/src/main/java/me/topchetoeu/j2s/common/Metadata.java index 3e13e0a..2fdeba1 100644 --- a/common/src/main/java/me/topchetoeu/j2s/common/Metadata.java +++ b/common/src/main/java/me/topchetoeu/j2s/common/Metadata.java @@ -1,18 +1,46 @@ package me.topchetoeu.j2s.common; -import me.topchetoeu.j2s.common.json.JSON; -import me.topchetoeu.j2s.common.parsing.Filename; - public class Metadata { - private static final String VERSION; - private static final String AUTHOR; - private static final String NAME; + private static String VERSION; + private static String AUTHOR; + private static String NAME; static { - var data = JSON.parse(new Filename("internal", "metadata.json"), Reading.resourceToString("metadata.json")).map(); - VERSION = data.string("version"); - AUTHOR = data.string("author"); - NAME = data.string("name"); + var raw = Reading.resourceToString("metadata").split("\n"); + var line = 0; + var file = "internal://metadata"; + + for (var el : raw) { + line++; + + el = el.trim(); + if (el.startsWith("#")) continue; + if (el.isEmpty()) continue; + + var i = el.indexOf(":"); + if (i < 0) throw new RuntimeException(String.format("%s:%s: Expected colon on line", file, line)); + + var name = el.substring(0, i).trim(); + var value = el.substring(i + 1).trim(); + + switch (name) { + case "version": + VERSION = value; + break; + case "author": + AUTHOR = value; + break; + case "name": + NAME = name; + break; + default: + throw new RuntimeException(String.format("%s:%s: Unexpected metadata key '%s'", file, line, name)); + } + } + + if (VERSION == null) throw new RuntimeException(String.format("%s:%s: No version specified", file, line)); + if (AUTHOR == null) throw new RuntimeException(String.format("%s:%s: No author specified", file, line)); + if (NAME == null) throw new RuntimeException(String.format("%s:%s: No name specified", file, line)); } public static String version() { diff --git a/common/src/main/resources/metadata b/common/src/main/resources/metadata new file mode 100644 index 0000000..8ce993c --- /dev/null +++ b/common/src/main/resources/metadata @@ -0,0 +1,3 @@ +version: ${version} +name: ${name} +author: TopchetoEU diff --git a/common/src/main/resources/metadata.json b/common/src/main/resources/metadata.json deleted file mode 100644 index 42ba55f..0000000 --- a/common/src/main/resources/metadata.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": "${version}", - "name": "${name}", - "author": "TopchetoEU" -} \ No newline at end of file