mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Require object feature ids, mantle keys and settings ids to be the owning module's id or below it
Object feature ids and mantle keys a module registers must now equal its module id or start with it and '/', the rule stage ids already follow, instead of only sharing its namespace. A settings type named in when(...) needs a feature id that at least one module naming it owns in the same sense, so another module may still condition on it, as moss can on iris:snow. ModuleInfo.ownsId states the rule; stageIdPrefix becomes idPrefix since it now prefixes more than stages. Errors name the module and its origin and suggest an owned id.
This commit is contained in:
1 parent
77e4ab4710
commit
d5aad57ad9
10 files changed
+113
-61
No files matched your search
@@ -18,8 +18,8 @@ import java.util.Set;
|
||||
/** Reference host registry. Single-threaded registration ends with freeze(); the catalog is
|
||||
* immutable. IDs are unique across feature kinds; JSON fields are unique per attachment target.
|
||||
* Pass existing host JSON fields to reserve them before modules register. Modules register through
|
||||
* {@link #register(DiscoveredModule)}; object feature ids and mantle keys must use the registering
|
||||
* module's namespace. A failed registration leaves the registry unchanged. A failed module callback
|
||||
* {@link #register(DiscoveredModule)}; object feature ids and mantle keys must be the registering
|
||||
* module's id or start with it and '/' ({@link com.volmit.ModuleInfo#ownsId}). A failed registration leaves the registry unchanged. A failed module callback
|
||||
* invalidates the host's whole build. This does not decode JSON, discover modules or instantiate
|
||||
* settings.
|
||||
*/
|
||||
@@ -62,7 +62,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
ObjectGeneratorFactory<F> factory) {
|
||||
checkOpen();
|
||||
var descriptor = FeatureDescriptor.of(featureType);
|
||||
requireModuleNamespace("Object generator settings " + featureType.getName() + " with feature id", descriptor.id());
|
||||
requireOwnedId("Object generator settings " + featureType.getName() + " with feature id", descriptor.id());
|
||||
var registration = new ObjectRegistration<>(descriptor, factory);
|
||||
claim(descriptor);
|
||||
objects.put(featureType, registration);
|
||||
@@ -73,7 +73,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
checkOpen();
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(codec, "codec");
|
||||
requireModuleNamespace("Mantle layer", ResourceId.parse(key.id()));
|
||||
requireOwnedId("Mantle layer", ResourceId.parse(key.id()));
|
||||
|
||||
var registration = new MantleRegistration<>(key, lifetime, codec, codec.version());
|
||||
if (mantle.putIfAbsent(key.id(), registration) != null) {
|
||||
@@ -99,14 +99,14 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
private void requireModuleNamespace(String registration, ResourceId id) {
|
||||
private void requireOwnedId(String registration, ResourceId id) {
|
||||
if (registering == null) {
|
||||
throw new IllegalStateException(registration + " " + id + " registered outside IrisModule.register");
|
||||
}
|
||||
var namespace = registering.info().id().namespace();
|
||||
if (id.namespace().equals(namespace)) return;
|
||||
throw new IllegalArgumentException(registration + " " + id + " must use namespace '" + namespace
|
||||
+ "' of its registering module " + registering);
|
||||
var info = registering.info();
|
||||
if (info.ownsId(id)) return;
|
||||
throw new IllegalArgumentException(registration + " " + id + " must be " + info.id() + " or start with "
|
||||
+ info.idPrefix() + ", the id of its registering module " + registering);
|
||||
}
|
||||
|
||||
private void reserveHostFields(Map<FeatureAttachment.Target, Set<String>> reservedFields) {
|
||||
|
||||
@@ -26,7 +26,8 @@ import java.util.stream.Collectors;
|
||||
* discard the whole builder: it may hold a partial module. Errors about one module name its origin.
|
||||
*
|
||||
* <p>A module defines only stages whose ids start with its own id and '/', and a settings type
|
||||
* named in {@code when(...)} must have a feature id in the namespace of a module that names it.
|
||||
* named in {@code when(...)} must have a feature id that at least one module naming it owns: that
|
||||
* module's id, or one starting with it and '/'.
|
||||
*/
|
||||
public final class StageGraphBuilder implements StageGraph {
|
||||
private final Map<ResourceId, StageDeclaration> declarations = new HashMap<>();
|
||||
@@ -65,8 +66,8 @@ public final class StageGraphBuilder implements StageGraph {
|
||||
return GraphResolver.resolve(pipeline, declarations.values());
|
||||
}
|
||||
|
||||
/** Settings types named by when(...), ordered by feature id. Fails if a type's feature id is not
|
||||
* in the namespace of any module that names it: some module of that namespace must own it.
|
||||
/** Settings types named by when(...), ordered by feature id. Fails if no module that names a type
|
||||
* owns its feature id ({@link com.volmit.ModuleInfo#ownsId}).
|
||||
*/
|
||||
public List<Class<? extends IrisFeature>> settingsTypes() {
|
||||
var uses = settingsUses();
|
||||
@@ -104,17 +105,22 @@ public final class StageGraphBuilder implements StageGraph {
|
||||
|
||||
private void requireSettingsOwner(SettingsUse use) {
|
||||
var settings = use.settings();
|
||||
var namers = use.namers();
|
||||
var namespace = settings.id().namespace();
|
||||
if (namers.stream().anyMatch(module -> module.namespace().equals(namespace))) return;
|
||||
var namers = use.namers().stream().map(modules::get).toList();
|
||||
if (namers.stream().anyMatch(module -> module.info().ownsId(settings.id()))) return;
|
||||
var example = namers.getFirst().info();
|
||||
throw new IllegalArgumentException("Settings type " + settings.type().getName() + " has feature id "
|
||||
+ settings.id() + ", but no module of namespace '" + namespace + "' names it in when(...); it is named by "
|
||||
+ describeModules(namers) + ". A feature id uses the namespace of the module that owns the settings");
|
||||
+ settings.id() + ", which none of the modules naming it in when(...) owns: " + describeModules(namers)
|
||||
+ ". A feature id is the id of the module that owns the settings, such as " + example.id()
|
||||
+ ", or starts with it and '/', such as " + example.idPrefix() + lastSegment(settings.id()));
|
||||
}
|
||||
|
||||
private String describeModules(SortedSet<ResourceId> moduleIds) {
|
||||
return moduleIds.stream()
|
||||
.map(modules::get)
|
||||
private static String lastSegment(ResourceId id) {
|
||||
var path = id.path();
|
||||
return path.substring(path.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
private static String describeModules(List<DiscoveredModule> modules) {
|
||||
return modules.stream()
|
||||
.map(DiscoveredModule::toString)
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
@@ -144,7 +150,7 @@ public final class StageGraphBuilder implements StageGraph {
|
||||
private static void requireOwnedStageId(Stage<?> stage, DiscoveredModule discovered) {
|
||||
var info = discovered.info();
|
||||
if (info.ownsStage(stage.id())) return;
|
||||
throw new IllegalArgumentException("Stage " + stage + " must start with " + info.stageIdPrefix()
|
||||
throw new IllegalArgumentException("Stage " + stage + " must start with " + info.idPrefix()
|
||||
+ ", the id of its defining module " + discovered);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user