diff --git a/CHANGELOG.md b/CHANGELOG.md index 5268ec3..6d3dfeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Written for Consumers: what a mod building against Example Module can use, or wi ## Unreleased +- `libworks-plugin` 0.4.5: `checkPlaysAlone` knows A Touch Of's Pillars as `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`. The shelved `atouchofcold` is retired, so no Pillar or FactoryWorks Module may name it (A Touch Of #5, #6). A Pillar may add entries to another Pillar's tag with a file under `data//tags/` whose `replace` is absent or false and whose every entry is `{"id": "", "required": false}`. Any other file in that namespace still fails, and the failure says why (ADR 0014, A Touch Of ADR-0002). FactoryWorks Modules get no such exception. Forbidding `atouchofcold` and `atouchofwickedness` tightens the check, but no Module ships either, so it is a patch, as 0.4.4 was (ADR 0001). A Module edits nothing. - `libworks-plugin` 0.4.4: `checkPlaysAlone` also checks a Module against every other suite's Modules, bases included (ADR 0013): a Pillar may not name a FactoryWorks Module, Groundworks included, and a FactoryWorks Module may not name a Pillar or A Touch Of's Runtime, `atouchof`. 0.4.3 let a Pillar name a FactoryWorks Module and the reverse. A mod no suite lists is still checked against every suite's Modules but Groundworks and `atouchof`. A Module edits nothing: none names the other suite. - `libworks-plugin` 0.4.3: `checkPlaysAlone` checks a Module against its own suite's Modules, which its `mod_id` picks (ADR 0013). A Touch Of's Pillars, `atouchofcold`, `atouchofdarkness` and `atouchofmadness`, are checked against one another and may name their Runtime, `atouchof`, and no longer against FactoryWorks' Modules. A FactoryWorks Module's check is unchanged. A mod no suite lists is checked against every suite's Modules but Groundworks and `atouchof`. A Module edits nothing. - `libworks-runtime` 0.1.12: libworks-gametest's `GalleryCheck.MAX_SCENES` is 24, up from 16, so `builds` and `withPack` take a gallery of up to 24 scenes. diff --git a/docs/adr/0013-each-suite-has-its-own-module-list-found-by-mod-id.md b/docs/adr/0013-each-suite-has-its-own-module-list-found-by-mod-id.md index 45c5965..a05f6f7 100644 --- a/docs/adr/0013-each-suite-has-its-own-module-list-found-by-mod-id.md +++ b/docs/adr/0013-each-suite-has-its-own-module-list-found-by-mod-id.md @@ -32,3 +32,7 @@ template's own build would need an exception. **Amended 2026-10-25 (plugin 0.4.4).** Plugin 0.4.3 checked a Module only against its own suite, so a Pillar could name any FactoryWorks Module and a FactoryWorks Module any Pillar, which neither suite's rule allows. 0.4.4 adds every other suite's Modules, bases included, as above. + +**Amended 2026-10-27 (plugin 0.4.5, ADR 0014).** A Touch Of's Pillars are `atouchofdarkness`, `atouchofmadness` and +`atouchofwickedness` (A Touch Of #6). `atouchofcold` is shelved in favour of Tough As Nails (A Touch Of #5) and +retired, so none may name it. A Pillar may add optional entries to another Pillar's tag (ADR 0014). diff --git a/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md b/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md new file mode 100644 index 0000000..899aa32 --- /dev/null +++ b/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md @@ -0,0 +1,40 @@ +--- +status: accepted +--- + +# A Pillar may add optional entries to another Pillar's tag + +A Touch Of ADR-0002, as amended by A Touch Of #6, lets one Pillar add an entry to another Pillar's +tag. It does this with a vanilla tag file that has `replace: false` and marks every entry +`required: false`. Without the other Pillar the tag is never read, so neither Pillar requires the +other. The first use is A Touch of Wickedness shipping +`data/atouchofmadness/tags/entity_type/unsettling.json`, which adds its Bailiff. `checkPlaysAlone` +(ADR 0005, ADR 0013) failed any `data/` folder in another Pillar's namespace, so that file +failed. + +**Decision.** Each suite states what a Module may ship in another Module's tags: A Touch Of takes +optional entries, and FactoryWorks takes none, since FactoryWorks ADR-0127 allows none. In a suite +that takes them, a Module other than the base may ship files under another Module's +`data//tags//`. Each must be a tag whose `replace` is absent or false, with no +NeoForge `remove` list, which would take entries out of the other tag, and whose every entry is an +object with `"required": false` naming one of the Module's own ids or tags. The scan reads that +namespace's data folder file by file, and reports each file that fails with why: outside `tags/`, +not a tag or not valid JSON, a bare or required entry, an entry with no id, a `replace` that is +true or not a boolean, a `remove`, or an id that is not the Module's own. The exception does not +cover an `assets/` folder, the base, a retired id such as the shelved `atouchofcold`, or +another suite's namespace. + +`atouchofcold` is retired while A Touch of Cold is shelved (A Touch Of #5), so its own build would +fail: no suite lists it, and its ids are forbidden. Reviving it means a patch release that moves it +from the suite's retired ids back to its Pillars. + +**Versioning.** Forbidding `atouchofcold` and `atouchofwickedness` tightens the check, but no +Module ships either, so none has to edit its build, and the release is a patch (ADR 0001), as +0.4.4's tightening was (ADR 0013). + +**Considered.** Allowing any id an optional entry names, such as `minecraft:zombie`: a Pillar +could then retune another Pillar's tag with vanilla content, which goes further than ADR-0002's +"adds an entry" allows. The exception in every suite: FactoryWorks has not asked for it, and its +ADR-0127 forbids it. A list of allowed files in the plugin: narrower, but every new use would need +a plugin release. A Module declaring its tag files in `libworks { }`: every Module would carry a +line, and the plugin would still need the rule to check it. diff --git a/docs/plugin.md b/docs/plugin.md index 88b5de5..6eb3883 100644 --- a/docs/plugin.md +++ b/docs/plugin.md @@ -31,7 +31,7 @@ The plugin adds a `gametest` source set to the mod, which the dev runs load and `buildGametestStructures` writes the default `gametest/platform.nbt` into `src/gametest/resources/data//structure/`, leaves an identical one alone, and fails naming the file when the Module has committed a different one: a Module needing another structure commits it (ADR 0003). -`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofcold`, `atouchofdarkness` and `atouchofmadness`: every one but the Pillar built and the Runtime is forbidden. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. +`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013, ADR 0014): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`: every one but the Pillar built and the Runtime is forbidden, and the shelved `atouchofcold` (A Touch Of #5). A Pillar may still ship a tag file under another Pillar's `data//tags/`, to add entries to that Pillar's tag, when `replace` is absent or false and every entry is an object with `"required": false` naming one of its own ids or tags, such as Wickedness's `data/atouchofmadness/tags/entity_type/unsettling.json` holding `{"id": "atouchofwickedness:bailiff", "required": false}` (A Touch Of ADR-0002, ADR 0014). Each other file in that folder is reported, with why: outside `tags/`, not a tag or not valid JSON, a bare or required entry, an entry with no id, a `replace` that is true or not a boolean, a NeoForge `remove` list, or an id not its own. While `atouchofcold` is retired its own build would fail, so reviving it means a patch release moving it back to the Pillars. FactoryWorks has no such exception, nor does the Runtime, the shelved `atouchofcold` or another suite's namespace. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. ### Moving to 0.4.0 diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy new file mode 100644 index 0000000..b26528f --- /dev/null +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2026 5thlayer +// SPDX-License-Identifier: MIT + +package io.github._5thlayer.libworks.plugin + +import groovy.json.JsonOutput +import groovy.json.JsonSlurper + +import java.nio.file.Path + +/** + * A file a Module ships in another Module's data folder, which passes only as a tag of optional entries of the Module's own ids that keeps + * the tag's other entries (libworks ADR 0014, A Touch Of ADR-0002). + */ +final class OptionalTagFile { + + private OptionalTagFile() { + } + + /** Why {@code file}, under the other Module's {@code namespace} folder and shown as {@code name}, is not such a tag; empty when it is. */ + static List findings(Path namespace, Path file, String name, String modId, List forbidden) { + def tags = namespace.resolve('tags') + if (!file.startsWith(tags)) return ["$name is outside tags/".toString()] + // A tag file sits in its registry's folder, tags//; vanilla reads none directly under tags/. + if (file.parent == tags || !file.toString().endsWith('.json')) return ["$name is not a tag".toString()] + def tag + try { + tag = new JsonSlurper().parse(file.toFile()) + } catch (Exception ignored) { + return ["$name is not valid JSON".toString()] + } + if (!(tag instanceof Map)) return ["$name is not a tag".toString()] + def found = [] + // NeoForge reads a tag's "remove" list too, which would take entries out of the other Module's tag. + if (tag.containsKey('remove')) found << "$name removes from the tag".toString() + if (!(tag.values instanceof List)) return found ?: ["$name is not a tag".toString()] + if (tag.replace == true) found << "$name replaces the tag".toString() + else if (tag.containsKey('replace') && tag.replace != false) found << "$name sets replace to ${JsonOutput.toJson(tag.replace)}, not a boolean".toString() + tag.values.each { entry -> + def id = entry instanceof Map ? entry.id : entry + if (!(id instanceof String)) { + found << "$name has an entry with no id".toString() + return + } + // A bare id, or an entry with no "required", is required: the tag fails to load without it. + if (!(entry instanceof Map) || entry.required != false) { + found << "$name requires $id".toString() + return + } + def tagRef = id.startsWith('#') ? '#' : '' + def path = id - ~/^#/ + // Vanilla reads an id with no namespace as minecraft's. + def full = path.contains(':') ? path : "minecraft:$path" + def namespaceOf = full.split(':')[0] + // An id in a forbidden namespace is already named by PlaysAlone.ids. + if (namespaceOf != modId && !forbidden.contains(namespaceOf)) found << "$name adds $tagRef$full, not $modId's own".toString() + } + found + } +} diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy index 174bd33..c556144 100644 --- a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy @@ -16,20 +16,33 @@ import java.util.zip.GZIPInputStream */ final class PlaysAlone { - /** One suite: what it calls its Modules, the ADR that has them play alone, its Modules, the base among them that every one may require, and the retired ids none may name. */ + /** What a suite lets a Module ship in another Module's tags (ADR 0014). */ + static enum OtherModulesTags { + /** Nothing: another Module's data folder is forbidden whole. */ + NONE, + /** A tag of optional entries of the Module's own ids, which keeps the tag's other entries. */ + OPTIONAL_ENTRIES + } + + /** + * One suite: what it calls its Modules, the ADR that has them play alone, its Modules, the base among them that every one may require, + * the retired ids none may name, and what a Module may ship in another Module's tags (ADR 0014). + */ static final class Suite { final String term final String rule final String base final List modules final List retired + final OtherModulesTags otherModulesTags - Suite(String term, String rule, String base, List modules, List retired) { + Suite(String term, String rule, String base, List modules, List retired, OtherModulesTags otherModulesTags) { this.term = term this.rule = rule this.base = base this.modules = modules this.retired = retired + this.otherModulesTags = otherModulesTags } /** Every Module but {@code modId} and the base, and the retired ids. */ @@ -37,6 +50,11 @@ final class PlaysAlone { modules.findAll { it != modId && it != base } + retired } + /** Whether {@code modId} may add optional entries to {@code namespace}'s tags: another Module of this suite, the base never adding (ADR 0014). */ + boolean takesOptionalTagEntries(String modId, String namespace) { + otherModulesTags == OtherModulesTags.OPTIONAL_ENTRIES && modId != base && namespace in modules + } + /** Every Module, the base included, and the retired ids: what a Module of another suite may not name. */ List forbiddenToOtherSuites() { modules + retired @@ -45,13 +63,14 @@ final class PlaysAlone { /** * Every suite. FactoryWorks Core retired (FactoryWorks ADR-0128), so no Module may name {@code factoryworks}; - * the A Touch Of Runtime, {@code atouchof}, is the base every Pillar nests (A Touch Of ADR-0002). + * the A Touch Of Runtime, {@code atouchof}, is the base every Pillar nests (A Touch Of ADR-0002), and + * {@code atouchofcold} is shelved in favour of Tough As Nails, so no Pillar may come to depend on it (A Touch Of #5). */ static final List SUITES = [ new Suite('Module', 'FactoryWorks ADR-0127', 'groundworks', - ['beltworks', 'craftworks', 'fieldworks', 'gearworks', 'groundworks', 'pipeworks', 'voidworks', 'wireworks'], ['factoryworks']), + ['beltworks', 'craftworks', 'fieldworks', 'gearworks', 'groundworks', 'pipeworks', 'voidworks', 'wireworks'], ['factoryworks'], OtherModulesTags.NONE), new Suite('Pillar', 'A Touch Of ADR-0002', 'atouchof', - ['atouchof', 'atouchofcold', 'atouchofdarkness', 'atouchofmadness'], []), + ['atouchof', 'atouchofdarkness', 'atouchofmadness', 'atouchofwickedness'], ['atouchofcold'], OtherModulesTags.OPTIONAL_ENTRIES), ] private static final Pattern DEPENDENCY_MOD_ID = ~/(?m)^\s*modId\s*=\s*"([^"]+)"/ @@ -60,6 +79,9 @@ final class PlaysAlone { /** The suite whose Modules hold {@code modId}, or null for a mod no suite lists, such as the template's own. */ final Suite suite + /** The Module built, whose own ids alone an optional entry in another Module's tag may name (ADR 0014). */ + final String modId + /** * The namespaces {@code modId} may not name: its suite's but its base, and every other suite's, bases * included; or for a mod no suite lists every suite's but their bases, as its suite is not known (ADR 0013). @@ -67,6 +89,7 @@ final class PlaysAlone { final List forbidden PlaysAlone(String modId) { + this.modId = modId suite = SUITES.find { modId in it.modules } forbidden = (suite ? suite.forbiddenTo(modId) + (SUITES - suite).collectMany { it.forbiddenToOtherSuites() } @@ -78,9 +101,9 @@ final class PlaysAlone { suite ? "another ${suite.term} or another suite's Module (${suite.rule}, libworks ADR 0013)" : 'another Module (libworks ADR 0013)' } - /** What the processed resources under {@code resources} ship against the rules: ids, namespace folders and required mods. */ + /** What the processed resources under {@code resources} ship against the rules: ids, namespace folders, other Modules' tags and required mods. */ List resources(Path resources) { - ids(resources) + namespaces(resources) + required(resources) + ids(resources) + namespaces(resources) + otherTags(resources) + required(resources) } /** What the Java source under {@code code} names against the rules: ids and namespace strings. */ @@ -100,20 +123,37 @@ final class PlaysAlone { found } - /** Each {@code assets/} or {@code data/} folder under {@code resources} that is forbidden. */ + /** + * Each {@code assets/} or {@code data/} folder under {@code resources} that is forbidden, but the data folders of + * Modules whose tags this one may add optional entries to, which {@link #otherTags} reads (ADR 0014). + */ List namespaces(Path resources) { def found = [] ['assets', 'data'].each { kind -> - def dir = resources.resolve(kind) - if (!Files.isDirectory(dir)) return - Files.list(dir).withCloseable { namespaces -> - namespaces.map { it.fileName.toString() }.filter { forbidden.contains(it) }.sorted() - .forEach { found << "$kind/$it".toString() } - } + forbiddenFolders(resources, kind).findAll { kind != 'data' || !suite?.takesOptionalTagEntries(modId, it) }.each { found << "$kind/$it".toString() } } found } + /** + * What this Module ships under the data folders of Modules whose tags it may add optional entries to, beyond optional entries of its + * own ids (ADR 0014): each file outside {@code tags//} or not a tag, and in a tag each entry that is required or not its own, + * a {@code replace} and a {@code remove}. + */ + List otherTags(Path resources) { + forbiddenFolders(resources, 'data').findAll { suite?.takesOptionalTagEntries(modId, it) }.collectMany { tagFindings(resources, resources.resolve("data/$it")) } + } + + private List forbiddenFolders(Path resources, String kind) { + def dir = resources.resolve(kind) + if (!Files.isDirectory(dir)) return [] + Files.list(dir).withCloseable { it.map { it.fileName.toString() }.filter { forbidden.contains(it) }.sorted().toList() } + } + + private List tagFindings(Path resources, Path namespace) { + files(namespace).collectMany { OptionalTagFile.findings(namespace, it, relative(resources, it), modId, forbidden) } + } + /** Each string in the Java source under {@code code} that is a forbidden namespace, as an id built in code names it. */ List namespaceStrings(Path code) { def namespaces = Pattern.compile("\"(${forbidden.join('|')})\"") diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/ModulePluginTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/ModulePluginTest.java index 6b96dff..f1b00ae 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/ModulePluginTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/ModulePluginTest.java @@ -456,11 +456,23 @@ void checkPlaysAloneChecksAPillarAgainstTheOtherPillarsAndFactoryWorks() throws write("src/main/java/dark/Dark.java", "package dark; class Dark { String sanity = \"atouchofmadness:sanity\"; String meter = \"atouchof:meter\"; String pipe = \"pipeworks:pipe\"; }\n"); String out = fail("checkPlaysAlone").getOutput(); assertTrue(out.contains("atouchofdarkness ships what names another Pillar or another suite's Module (A Touch Of ADR-0002, libworks ADR 0013), whose namespaces are " - + "atouchofcold, atouchofmadness, beltworks, craftworks, factoryworks, fieldworks, gearworks, groundworks, pipeworks, voidworks, wireworks:\n" + + "atouchofcold, atouchofmadness, atouchofwickedness, beltworks, craftworks, factoryworks, fieldworks, gearworks, groundworks, pipeworks, voidworks, wireworks:\n" + " src/main/java/dark/Dark.java names atouchofmadness:sanity\n" + " src/main/java/dark/Dark.java names pipeworks:pipe\n"), out); } + @Test + void checkPlaysAloneLetsAPillarAddOnlyOptionalEntriesToAnotherPillarsTag() throws IOException { + Files.writeString(module.resolve("gradle.properties"), Files.readString(module.resolve("gradle.properties")).replace("mod_id = beltworks", "mod_id = atouchofwickedness")); + buildScript(""); + write("src/main/resources/data/atouchofmadness/tags/entity_type/unsettling.json", + "{\"replace\": false, \"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}\n"); + build("checkPlaysAlone"); + write("src/main/resources/data/atouchofmadness/tags/entity_type/unsettling.json", "{\"values\": [\"atouchofwickedness:bailiff\"]}\n"); + String out = fail("checkPlaysAlone").getOutput(); + assertTrue(out.contains(" build/resources/main/data/atouchofmadness/tags/entity_type/unsettling.json requires atouchofwickedness:bailiff\n"), out); + } + @Test void checkPlaysAlonePassesAModuleWithNoResources() throws IOException { buildScript(""); diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java index 3dc52f7..fa754f0 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java @@ -18,21 +18,24 @@ /** Each rule of the plays-alone scan, on files written for it: Beltworks is the Module scanned unless a test names another. */ class PlaysAloneTest { private final PlaysAlone belt = new PlaysAlone("beltworks"); + private final PlaysAlone wicked = new PlaysAlone("atouchofwickedness"); @Test void forbidsEveryModuleButItselfAndGroundworksAndTheRetiredPackAndEveryPillar() { - assertEquals(List.of("atouchof", "atouchofcold", "atouchofdarkness", "atouchofmadness", "craftworks", "factoryworks", "fieldworks", - "gearworks", "pipeworks", "voidworks", "wireworks"), belt.getForbidden()); - assertEquals(List.of("atouchof", "atouchofcold", "atouchofdarkness", "atouchofmadness", "beltworks", "craftworks", "factoryworks", - "fieldworks", "gearworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("groundworks").getForbidden()); + assertEquals(List.of("atouchof", "atouchofcold", "atouchofdarkness", "atouchofmadness", "atouchofwickedness", "craftworks", "factoryworks", + "fieldworks", "gearworks", "pipeworks", "voidworks", "wireworks"), belt.getForbidden()); + assertEquals(List.of("atouchof", "atouchofcold", "atouchofdarkness", "atouchofmadness", "atouchofwickedness", "beltworks", "craftworks", + "factoryworks", "fieldworks", "gearworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("groundworks").getForbidden()); } @Test - void aPillarForbidsTheOtherPillarsAndEveryFactoryWorksModuleGroundworksIncluded() { - assertEquals(List.of("atouchofcold", "atouchofmadness", "beltworks", "craftworks", "factoryworks", "fieldworks", "gearworks", - "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchofdarkness").getForbidden()); + void aPillarForbidsTheOtherPillarsTheShelvedColdAndEveryFactoryWorksModuleGroundworksIncluded() { + assertEquals(List.of("atouchofcold", "atouchofmadness", "atouchofwickedness", "beltworks", "craftworks", "factoryworks", "fieldworks", + "gearworks", "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchofdarkness").getForbidden()); assertEquals(List.of("atouchofcold", "atouchofdarkness", "atouchofmadness", "beltworks", "craftworks", "factoryworks", "fieldworks", - "gearworks", "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchof").getForbidden()); + "gearworks", "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchofwickedness").getForbidden()); + assertEquals(List.of("atouchofcold", "atouchofdarkness", "atouchofmadness", "atouchofwickedness", "beltworks", "craftworks", "factoryworks", + "fieldworks", "gearworks", "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchof").getForbidden()); } @Test @@ -52,8 +55,8 @@ void aFactoryWorksModuleMayNameNoPillarNorTheRuntime(@TempDir Path resources) th @Test void aModNoSuiteListsForbidsEverySuitesModulesButTheirBases() { - assertEquals(List.of("atouchofcold", "atouchofdarkness", "atouchofmadness", "beltworks", "craftworks", "factoryworks", "fieldworks", - "gearworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("examplelib").getForbidden()); + assertEquals(List.of("atouchofcold", "atouchofdarkness", "atouchofmadness", "atouchofwickedness", "beltworks", "craftworks", "factoryworks", + "fieldworks", "gearworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("examplelib").getForbidden()); } @Test @@ -65,6 +68,111 @@ void aDataOrAssetFolderInAnotherModulesNamespaceIsReported(@TempDir Path resourc assertEquals(List.of("assets/voidworks", "data/fieldworks"), belt.namespaces(resources)); } + @Test + void aPillarMayAddItsOwnOptionalEntriesToAnotherPillarsTag(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/unsettling.json"), + "{\"replace\": false, \"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + write(resources.resolve("data/atouchofdarkness/tags/item/x.json"), "{\"values\": [{\"id\": \"#atouchofwickedness:seals\", \"required\": false}]}"); + assertEquals(List.of(), wicked.namespaces(resources)); + assertEquals(List.of(), wicked.otherTags(resources)); + } + + @Test + void anOptionalTagFileThatRequiresReplacesOrAddsAnotherIdIsReported(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/a.json"), "{\"values\": [\"atouchofwickedness:bailiff\"]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/b.json"), "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\"}]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/c.json"), + "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": true}]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/d.json"), + "{\"replace\": true, \"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/e.json"), "{\"values\": [{\"id\": \"minecraft:zombie\", \"required\": false}]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/f.json"), "[]"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/g.json"), "{\"values\": [], \"remove\": [\"atouchofmadness:x\"]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/i.json"), "{\"values\": [], \"remove\": []}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/j.txt"), "atouchofwickedness:bailiff"); + write(resources.resolve("data/atouchofmadness/tags/h.json"), "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + assertEquals(List.of("data/atouchofmadness/tags/entity_type/a.json requires atouchofwickedness:bailiff", + "data/atouchofmadness/tags/entity_type/b.json requires atouchofwickedness:bailiff", + "data/atouchofmadness/tags/entity_type/c.json requires atouchofwickedness:bailiff", + "data/atouchofmadness/tags/entity_type/d.json replaces the tag", + "data/atouchofmadness/tags/entity_type/e.json adds minecraft:zombie, not atouchofwickedness's own", + "data/atouchofmadness/tags/entity_type/f.json is not a tag", + "data/atouchofmadness/tags/entity_type/g.json removes from the tag", + "data/atouchofmadness/tags/entity_type/i.json removes from the tag", + "data/atouchofmadness/tags/entity_type/j.txt is not a tag", + "data/atouchofmadness/tags/h.json is not a tag"), wicked.otherTags(resources)); + } + + @Test + void aTagInASubfolderOfItsRegistryIsATag(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/sub/x.json"), + "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + assertEquals(List.of(), wicked.otherTags(resources)); + } + + @Test + void aFileThatIsNoTagOrHasAMalformedFieldSaysWhy(@TempDir Path resources) throws IOException { + Path tags = resources.resolve("data/atouchofmadness/tags/entity_type"); + write(tags.resolve("a.json"), "{\"values\": ["); + write(tags.resolve("b.json"), ""); + write(tags.resolve("c.json"), "{}"); + write(tags.resolve("d.json"), "{\"replace\": \"false\", \"values\": []}"); + write(tags.resolve("e.json"), "{\"remove\": [\"atouchofmadness:x\"]}"); + write(tags.resolve("f.json"), "{\"values\": [{\"required\": false}, {\"id\": null, \"required\": false}, {\"id\": 3, \"required\": false}]}"); + write(tags.resolve("g.json"), "{\"values\": [{}, {\"id\": 3}]}"); + write(tags.resolve("h.json"), "{\"values\": [{\"id\": \"atouchofwickedness\", \"required\": false}, {\"id\": \"#bailiffs\", \"required\": false}]}"); + assertEquals(List.of("data/atouchofmadness/tags/entity_type/a.json is not valid JSON", + "data/atouchofmadness/tags/entity_type/b.json is not valid JSON", + "data/atouchofmadness/tags/entity_type/c.json is not a tag", + "data/atouchofmadness/tags/entity_type/d.json sets replace to \"false\", not a boolean", + "data/atouchofmadness/tags/entity_type/e.json removes from the tag", + "data/atouchofmadness/tags/entity_type/f.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/f.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/f.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/g.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/g.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/h.json adds minecraft:atouchofwickedness, not atouchofwickedness's own", + "data/atouchofmadness/tags/entity_type/h.json adds #minecraft:bailiffs, not atouchofwickedness's own"), wicked.otherTags(resources)); + } + + @Test + void anOptionalEntryOfAnotherPillarsIdIsReportedOnce(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/x.json"), + "{\"values\": [{\"id\": \"atouchofdarkness:shade\", \"required\": false}]}"); + assertEquals(List.of("data/atouchofmadness/tags/entity_type/x.json names atouchofdarkness:shade"), wicked.resources(resources)); + } + + @Test + void anotherPillarsAssetsOrDataOutsideItsTagsAreReported(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/unsettling.json"), + "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + write(resources.resolve("data/atouchofmadness/recipe/x.json"), "{}"); + write(resources.resolve("assets/atouchofmadness/lang/en_us.json"), "{}"); + assertEquals(List.of("assets/atouchofmadness"), wicked.namespaces(resources)); + assertEquals(List.of("data/atouchofmadness/recipe/x.json is outside tags/"), wicked.otherTags(resources)); + } + + @Test + void theRuntimeMayAddNoEntryToAPillarsTag(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/item/x.json"), "{\"values\": [{\"id\": \"atouchof:x\", \"required\": false}]}"); + PlaysAlone runtime = new PlaysAlone("atouchof"); + assertEquals(List.of("data/atouchofmadness"), runtime.namespaces(resources)); + assertEquals(List.of(), runtime.otherTags(resources)); + } + + @Test + void optionalTagEntriesAreNoExceptionForTheShelvedColdAnotherSuiteOrFactoryWorks(@TempDir Path resources) throws IOException { + String optional = "{\"values\": [{\"id\": \"%s:x\", \"required\": false}]}"; + write(resources.resolve("data/atouchofcold/tags/item/x.json"), optional.formatted("atouchofwickedness")); + write(resources.resolve("data/pipeworks/tags/item/x.json"), optional.formatted("atouchofwickedness")); + assertEquals(List.of("data/atouchofcold", "data/pipeworks"), wicked.namespaces(resources)); + assertEquals(List.of(), wicked.otherTags(resources)); + write(resources.resolve("data/fieldworks/tags/item/x.json"), optional.formatted("beltworks")); + write(resources.resolve("data/atouchofmadness/tags/item/x.json"), optional.formatted("beltworks")); + assertEquals(List.of("data/atouchofcold", "data/atouchofmadness", "data/fieldworks", "data/pipeworks"), belt.namespaces(resources)); + assertEquals(List.of(), belt.otherTags(resources)); + } + @Test void anIdInDataIsReported(@TempDir Path resources) throws IOException { write(resources.resolve("data/beltworks/recipe/x.json"), "{\"key\":{\"a\":\"gearworks:gear\"}}");