mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
A module whose bundled library references optional integrations got a
WARNING on every pack load, with no way to say the classes are expected
to be absent. ModuleInfo now carries optionalPackages, set with
withOptionalPackages("org.slf4j", ...); ModuleInfo.of(id, name, version)
still declares none. Each package covers its subpackages.
Missing classes of a jar inside its own module's optional packages are
dropped from the warning and from PackModules.missingClasses(); other
jars are unaffected. The declaration comes from info(), so it is applied
after the entry classes exist. Load errors (hidden Iris classes, classes
missing from exposed packages) are decided before that and never depend
on it.
Package-name validation and whole-package matching move from
ExposedPackages to a new API value, PackageName, used by both.
73 lines
2.9 KiB
Java
73 lines
2.9 KiB
Java
package com.volmit.host;
|
|
|
|
import com.volmit.IrisModule;
|
|
import com.volmit.PackageName;
|
|
import java.util.Collection;
|
|
import java.util.Comparator;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.TreeSet;
|
|
|
|
/** The host packages pack modules may use: always the Iris API, plus whatever the host adds, such
|
|
* as the packages of built-in modules whose stages packs may require. A package is exposed with
|
|
* all its subpackages, and only whole package names match: {@code com.volmit} does not expose
|
|
* {@code com.volmitx}.
|
|
*/
|
|
final class ExposedPackages {
|
|
/** The root package of the Iris API. Module classes must not use it. */
|
|
static final String API_PACKAGE = IrisModule.class.getPackageName();
|
|
private static final PackageName API = new PackageName(API_PACKAGE);
|
|
private static final char PACKAGE_SEPARATOR = '.';
|
|
private static final char PATH_SEPARATOR = '/';
|
|
|
|
private final List<PackageName> packages;
|
|
|
|
private ExposedPackages(List<PackageName> packages) {
|
|
this.packages = List.copyOf(packages);
|
|
}
|
|
|
|
static ExposedPackages apiOnly() {
|
|
return apiAnd(List.of());
|
|
}
|
|
|
|
/** The API plus {@code hostPackages}. A trailing dot is accepted; anything that is not a package
|
|
* name, such as a blank string or a wildcard, is rejected.
|
|
*/
|
|
static ExposedPackages apiAnd(Collection<String> hostPackages) {
|
|
Objects.requireNonNull(hostPackages, "hostPackages");
|
|
var packages = new TreeSet<PackageName>();
|
|
packages.add(API);
|
|
hostPackages.forEach(name -> packages.add(requirePackageName(name)));
|
|
return new ExposedPackages(List.copyOf(packages));
|
|
}
|
|
|
|
static boolean isApiClass(String binaryName) {
|
|
return API.contains(binaryName);
|
|
}
|
|
|
|
boolean exposes(String binaryName) {
|
|
return packages.stream().anyMatch(name -> name.contains(binaryName));
|
|
}
|
|
|
|
/** Whether a resource path, such as {@code com/volmit/IrisModule.class}, lies in an exposed package. */
|
|
boolean exposesResource(String path) {
|
|
return exposes(path.replace(PATH_SEPARATOR, PACKAGE_SEPARATOR));
|
|
}
|
|
|
|
/** The exposed package a class is in; the most specific one when exposed packages nest. */
|
|
String packageOf(String binaryName) {
|
|
return packages.stream()
|
|
.filter(name -> name.contains(binaryName))
|
|
.map(PackageName::name)
|
|
.max(Comparator.comparingInt(String::length))
|
|
.orElseThrow(() -> new IllegalArgumentException(binaryName + " is not in an exposed package"));
|
|
}
|
|
|
|
private static PackageName requirePackageName(String name) {
|
|
Objects.requireNonNull(name, "exposed package");
|
|
return PackageName.tryParse(name).orElseThrow(() -> new IllegalArgumentException("Exposed package '" + name
|
|
+ "' is not a package name; name a package such as art.arcane.iris.engine, which exposes that package"
|
|
+ " and its subpackages"));
|
|
}
|
|
}
|