mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
ReservedNamespaces and ModuleHost.reservingNamespaces are gone: a pack module may use any namespace, iris included. A module id is still loaded once, and the duplicate error now names the origin and class of both modules, so two modules of one jar can be told apart. A jar lists one module class per line in META-INF/services/com.volmit.IrisModule and loads all of them in that order; each class must still be defined in the jar. A jar with several modules is excused by the optional packages of all of them. ModuleJarCheck runs the load's class checks on one jar without loading it.
80 lines
2.7 KiB
Java
80 lines
2.7 KiB
Java
package com.volmit.host;
|
|
|
|
import com.volmit.IrisModule;
|
|
import com.volmit.ModuleInfo;
|
|
import java.util.Objects;
|
|
|
|
/** A module, its identity and where the host found it. Load errors name the origin so the author
|
|
* knows which jar to fix.
|
|
*
|
|
* <p>{@link IrisModule#info()} is read once, when the module is discovered, and only that value is
|
|
* used afterwards. A module whose {@code info()} changes between calls cannot give the host
|
|
* inconsistent answers.
|
|
*/
|
|
public final class DiscoveredModule {
|
|
static final String HOST_CLASSPATH = "host classpath";
|
|
|
|
/** Where a module comes from: the host's classpath or a pack jar. */
|
|
enum Source { HOST, PACK }
|
|
|
|
private final IrisModule module;
|
|
private final ModuleInfo info;
|
|
private final String origin;
|
|
private final Source source;
|
|
|
|
private DiscoveredModule(IrisModule module, ModuleInfo info, String origin, Source source) {
|
|
this.module = Objects.requireNonNull(module, "module");
|
|
this.info = Objects.requireNonNull(info, "info");
|
|
this.origin = Objects.requireNonNull(origin, "origin");
|
|
this.source = Objects.requireNonNull(source, "source");
|
|
if (origin.isBlank()) {
|
|
throw new IllegalArgumentException("Blank module origin: " + module.getClass().getName());
|
|
}
|
|
}
|
|
|
|
/** A module that ships with the host instead of a pack. Reads its {@code info()}; a failure
|
|
* propagates unchanged.
|
|
*/
|
|
public static DiscoveredModule builtIn(IrisModule module) {
|
|
Objects.requireNonNull(module, "module");
|
|
return new DiscoveredModule(module, readInfo(module), HOST_CLASSPATH, Source.HOST);
|
|
}
|
|
|
|
/** A pack module whose {@code info()} the jar loader has already read and checked. */
|
|
static DiscoveredModule fromJar(IrisModule module, ModuleInfo info, String origin) {
|
|
return new DiscoveredModule(module, info, origin, Source.PACK);
|
|
}
|
|
|
|
private static ModuleInfo readInfo(IrisModule module) {
|
|
return Objects.requireNonNull(module.info(), () -> "info() of " + module.getClass().getName() + " returned null");
|
|
}
|
|
|
|
public IrisModule module() {
|
|
return module;
|
|
}
|
|
|
|
/** The module's identity, as {@code info()} returned it at discovery. */
|
|
public ModuleInfo info() {
|
|
return info;
|
|
}
|
|
|
|
/** The jar path relative to the pack, or "host classpath" for built-in modules. */
|
|
public String origin() {
|
|
return origin;
|
|
}
|
|
|
|
/** The origin and the module's class, which tells apart two modules of one jar. */
|
|
String locationWithClass() {
|
|
return origin + " (" + module.getClass().getName() + ")";
|
|
}
|
|
|
|
Source source() {
|
|
return source;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return info.id() + " from " + origin;
|
|
}
|
|
}
|