Write some tests #33
@ -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"],
|
||||||
|
@ -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() {
|
||||||
|
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