don't use JSON for parsing metadata

This commit is contained in:
TopchetoEU 2025-01-11 15:21:14 +02:00
parent 7a13b032f8
commit 24d0cb73b6
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
4 changed files with 42 additions and 16 deletions

View File

@ -5,7 +5,7 @@ plugins {
description = "A collection of utils and structures for the rest of the project"; description = "A collection of utils and structures for the rest of the project";
tasks.processResources { tasks.processResources {
filesMatching("metadata.json", { filesMatching("metadata", {
expand( expand(
"version" to properties["project_version"], "version" to properties["project_version"],
"name" to properties["project_name"], "name" to properties["project_name"],

View File

@ -1,18 +1,46 @@
package me.topchetoeu.j2s.common; package me.topchetoeu.j2s.common;
import me.topchetoeu.j2s.common.json.JSON;
import me.topchetoeu.j2s.common.parsing.Filename;
public class Metadata { public class Metadata {
private static final String VERSION; private static String VERSION;
private static final String AUTHOR; private static String AUTHOR;
private static final String NAME; private static String NAME;
static { static {
var data = JSON.parse(new Filename("internal", "metadata.json"), Reading.resourceToString("metadata.json")).map(); var raw = Reading.resourceToString("metadata").split("\n");
VERSION = data.string("version"); var line = 0;
AUTHOR = data.string("author"); var file = "internal://metadata";
NAME = data.string("name");
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() { public static String version() {

View File

@ -0,0 +1,3 @@
version: ${version}
name: ${name}
author: TopchetoEU

View File

@ -1,5 +0,0 @@
{
"version": "${version}",
"name": "${name}",
"author": "TopchetoEU"
}