don't use JSON for parsing metadata
This commit is contained in:
parent
7a13b032f8
commit
24d0cb73b6
@ -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"],
|
||||
|
@ -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() {
|
||||
|
3
common/src/main/resources/metadata
Normal file
3
common/src/main/resources/metadata
Normal file
@ -0,0 +1,3 @@
|
||||
version: ${version}
|
||||
name: ${name}
|
||||
author: TopchetoEU
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "${version}",
|
||||
"name": "${name}",
|
||||
"author": "TopchetoEU"
|
||||
}
|
Loading…
Reference in New Issue
Block a user