From a09a76daf02ac336fb827bac0bede39d8573d59d Mon Sep 17 00:00:00 2001 From: Colin Sharples Date: Sat, 26 Sep 2026 13:02:09 +1200 Subject: [PATCH] Give IconLibrary a name, and the server a way to report it (#111) Since #93 the server names no library: it runs against whichever one is on its classpath, which is what lets one build serve Standard, Hallux or BattleOrder. That left nothing able to say which one it got. With an instance per library planned, each on its own subdomain, "which library is this" has to be answerable from outside rather than inferred from which symbol sets happen to turn up in a listing. So IconLibrary declares getName(), the generator's template emits it from the library prefix it was generated with, and a new /info/library endpoint returns it alongside the symbol set count. Deliberately not getVersion(): getVersions() already means something else on this interface - an APP-6 edition, SIDC positions 1-2 - and the two would read as a pair. The generated libraries were regenerated rather than hand-patched; the only change in either was the new method. Co-Authored-By: Claude Opus 5 --- .../io/github/ctgnz/jmsfx/IconLibrary.java | 13 +++++++++++++ .../github/ctgnz/jmsfx/icon/TestFixtures.java | 6 ++++++ .../jmsfx/icon/editor/DynamicIconLibrary.java | 9 +++++++++ .../main/resources/templates/IconLibrary.ftl | 6 ++++++ .../ctgnz/jmsfx/hallux/HalluxIconLibrary.java | 6 ++++++ .../server/icon/IconGeneratorController.java | 6 ++++++ .../jmsfx/server/icon/LibrarySummary.java | 19 +++++++++++++++++++ .../jmsfx/standard/StandardIconLibrary.java | 6 ++++++ 8 files changed, 71 insertions(+) create mode 100644 jmsfx-server/src/main/java/io/github/ctgnz/jmsfx/server/icon/LibrarySummary.java diff --git a/jmsfx-core/src/main/java/io/github/ctgnz/jmsfx/IconLibrary.java b/jmsfx-core/src/main/java/io/github/ctgnz/jmsfx/IconLibrary.java index 69103740..7c491cfd 100644 --- a/jmsfx-core/src/main/java/io/github/ctgnz/jmsfx/IconLibrary.java +++ b/jmsfx-core/src/main/java/io/github/ctgnz/jmsfx/IconLibrary.java @@ -27,6 +27,19 @@ static IconLibrary discover() { return IconLibraries.discover(); } + /** + * Which library this is - {@code Standard}, {@code Hallux}, {@code BattleOrder}. + *

+ * An application built against jmsfx-core names no library and discovers whichever one is on its classpath, so without this it cannot report what it is running, and a + * deployment cannot be checked from outside beyond inferring it from which symbol sets appear. That is answerable while there is one library and awkward once there are three, + * each deployed to its own subdomain. See jmsfx#111. + *

+ * Deliberately not {@code getVersion()}: {@link #getVersions()} already means something else here - an APP-6 edition, SIDC positions 1-2 - and two methods a character apart + * meaning different things is a trap. The library's own artifact version is a separate question, and one the generated source cannot answer, since it has no idea what version + * it will be published as. + */ + String getName(); + ObservableList getAmplifiers(); ObservableList getCommonSectorOneModifiers(); diff --git a/jmsfx-core/src/test/java/io/github/ctgnz/jmsfx/icon/TestFixtures.java b/jmsfx-core/src/test/java/io/github/ctgnz/jmsfx/icon/TestFixtures.java index 412f21c6..4b469ddb 100644 --- a/jmsfx-core/src/test/java/io/github/ctgnz/jmsfx/icon/TestFixtures.java +++ b/jmsfx-core/src/test/java/io/github/ctgnz/jmsfx/icon/TestFixtures.java @@ -458,6 +458,12 @@ public String getLabel() { * {@code IconLibrary} implementations' documented behaviour of never returning null. */ static class FakeIconLibrary implements IconLibrary { + + @Override + public String getName() { + return "Fake"; + } + private StandardAmplifierItem defaultAmplifier = unknownAmplifier(); private Context defaultContext = realityContext(); private Entity defaultEntity = entity("00", "Unspecified"); diff --git a/jmsfx-editor/src/main/java/io/github/ctgnz/jmsfx/icon/editor/DynamicIconLibrary.java b/jmsfx-editor/src/main/java/io/github/ctgnz/jmsfx/icon/editor/DynamicIconLibrary.java index 2c783460..590ccdad 100644 --- a/jmsfx-editor/src/main/java/io/github/ctgnz/jmsfx/icon/editor/DynamicIconLibrary.java +++ b/jmsfx-editor/src/main/java/io/github/ctgnz/jmsfx/icon/editor/DynamicIconLibrary.java @@ -50,6 +50,15 @@ public class DynamicIconLibrary implements IconLibrary { public DynamicIconLibrary() { } + /** + * Not a generated library, so it has no prefix of its own. It is whatever model the editor currently holds, which is the honest answer and stops it being mistaken for one of + * the published libraries if it ever reaches something that reports a name. + */ + @Override + public String getName() { + return "Dynamic"; + } + @SuppressWarnings("this-escape") public DynamicIconLibrary(IconLibrary staticLibrary) { this.versions.setAll(Lists.transform(Lists.newArrayList(staticLibrary.getVersions()), VersionImpl::new)); diff --git a/jmsfx-generator/src/main/resources/templates/IconLibrary.ftl b/jmsfx-generator/src/main/resources/templates/IconLibrary.ftl index f0425e38..c49fc496 100644 --- a/jmsfx-generator/src/main/resources/templates/IconLibrary.ftl +++ b/jmsfx-generator/src/main/resources/templates/IconLibrary.ftl @@ -68,6 +68,12 @@ public class ${libraryPrefix}IconLibrary implements IconLibrary { public ${libraryPrefix}IconLibrary() { } + /** The library prefix this was generated with, which is what names the class too. */ + @Override + public String getName() { + return "${libraryPrefix}"; + } + @Override public ObservableList getAmplifiers() { return FXCollections.observableArrayList(AmplifierEnum.values()); diff --git a/jmsfx-hallux/src/main/java/io/github/ctgnz/jmsfx/hallux/HalluxIconLibrary.java b/jmsfx-hallux/src/main/java/io/github/ctgnz/jmsfx/hallux/HalluxIconLibrary.java index 7db3373b..2f0549b5 100644 --- a/jmsfx-hallux/src/main/java/io/github/ctgnz/jmsfx/hallux/HalluxIconLibrary.java +++ b/jmsfx-hallux/src/main/java/io/github/ctgnz/jmsfx/hallux/HalluxIconLibrary.java @@ -64,6 +64,12 @@ public static HalluxIconLibrary instance() { public HalluxIconLibrary() { } + /** The library prefix this was generated with, which is what names the class too. */ + @Override + public String getName() { + return "Hallux"; + } + @Override public ObservableList getAmplifiers() { return FXCollections.observableArrayList(AmplifierEnum.values()); diff --git a/jmsfx-server/src/main/java/io/github/ctgnz/jmsfx/server/icon/IconGeneratorController.java b/jmsfx-server/src/main/java/io/github/ctgnz/jmsfx/server/icon/IconGeneratorController.java index 5b1269ec..1cc46354 100644 --- a/jmsfx-server/src/main/java/io/github/ctgnz/jmsfx/server/icon/IconGeneratorController.java +++ b/jmsfx-server/src/main/java/io/github/ctgnz/jmsfx/server/icon/IconGeneratorController.java @@ -12,6 +12,12 @@ @RequestMapping("/info") public class IconGeneratorController { + /** Which library this instance is running. See jmsfx#111. */ + @GetMapping("/library") + public LibrarySummary getLibrary() { + return LibrarySummary.of(IconLibrary.discover()); + } + /** The symbol sets of whichever library is on the classpath, each carrying the path segment the icon API is reached at. */ @GetMapping("/symbols") public List getSupportedSymbolSets() { diff --git a/jmsfx-server/src/main/java/io/github/ctgnz/jmsfx/server/icon/LibrarySummary.java b/jmsfx-server/src/main/java/io/github/ctgnz/jmsfx/server/icon/LibrarySummary.java new file mode 100644 index 00000000..12eae891 --- /dev/null +++ b/jmsfx-server/src/main/java/io/github/ctgnz/jmsfx/server/icon/LibrarySummary.java @@ -0,0 +1,19 @@ +package io.github.ctgnz.jmsfx.server.icon; + +import io.github.ctgnz.jmsfx.IconLibrary; + +/** + * What this instance can say about itself: which symbology library it discovered, and how many symbol sets that library offers. + *

+ * Since jmsfx#93 the server names no library and runs against whichever one is on its classpath, so the answer is not a property of the build anyone can read off. With an instance + * per library planned, each on its own subdomain, "which library is this one running" needs to be answerable from outside rather than inferred from which symbol sets happen to + * appear in a listing. See jmsfx#111. + */ +public record LibrarySummary(String name, int symbolSets) { + + public static LibrarySummary of(IconLibrary library) { + return new LibrarySummary(library.getName(), library.getSymbolSets() + .size()); + } + +} diff --git a/jmsfx-standard/src/main/java/io/github/ctgnz/jmsfx/standard/StandardIconLibrary.java b/jmsfx-standard/src/main/java/io/github/ctgnz/jmsfx/standard/StandardIconLibrary.java index fbb5c2df..76ed9355 100644 --- a/jmsfx-standard/src/main/java/io/github/ctgnz/jmsfx/standard/StandardIconLibrary.java +++ b/jmsfx-standard/src/main/java/io/github/ctgnz/jmsfx/standard/StandardIconLibrary.java @@ -64,6 +64,12 @@ public static StandardIconLibrary instance() { public StandardIconLibrary() { } + /** The library prefix this was generated with, which is what names the class too. */ + @Override + public String getName() { + return "Standard"; + } + @Override public ObservableList getAmplifiers() { return FXCollections.observableArrayList(AmplifierEnum.values());