mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Let the host expose extra packages, such as built-in modules, to packs
A single API_PACKAGE_PREFIX made built-in modules in Iris packages (art.arcane.iris...) invisible, so pack jars could not require their stages. ExposedPackages now holds the packages packs may use: always the API (IrisModule's package), plus what the host passes to the new PackModules.load(packRoot, exposedHostPackages). Names must be package names (trailing dot accepted) and match whole packages only. ApiAndJdkClassLoader becomes ExposedHostClassLoader and routes classes and resources of every exposed package to the host loader. A jar that ships a class of any exposed package fails; the compileOnly API hint stays for the API, other packages get their own message. That check moves from ModuleJar to PackClassCheck. A reference missing from any exposed package is the "different build" error. Tests use a built-in module in example.builtin, outside com.volmit., which a pack jar can require only when that package is exposed.
This commit is contained in:
1 parent
98bd9a9c12
commit
13a9300ab4
11 files changed
+396
-121
No files matched your search
@@ -51,15 +51,13 @@ record ModuleJar(Path path, String origin, String entryClass, List<JarClass> cla
|
||||
}
|
||||
|
||||
/** Reads the single entry class a jar names and the classes it holds. The origin is the jar
|
||||
* path relative to its pack. Fails if the jar holds a class of the Iris API or a class file that
|
||||
* cannot be parsed.
|
||||
* path relative to its pack. Fails if a class file cannot be parsed.
|
||||
*/
|
||||
static ModuleJar read(Path packRoot, Path jar) {
|
||||
var origin = packRoot.relativize(jar).toString();
|
||||
try (var file = openAsClassLoaderSeesIt(jar)) {
|
||||
var entryClass = requireSingleEntryClass(origin, readEntryClasses(file));
|
||||
var classEntries = findClassEntries(file);
|
||||
requireNoApiClasses(origin, classEntries);
|
||||
return new ModuleJar(jar, origin, entryClass, readClasses(origin, file, classEntries));
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException("Module jar " + origin + " is not a readable jar", exception);
|
||||
@@ -140,22 +138,6 @@ record ModuleJar(Path path, String origin, String entryClass, List<JarClass> cla
|
||||
&& !entryName.startsWith(META_INF);
|
||||
}
|
||||
|
||||
/** The API package prefix is reserved for the API that Iris provides at runtime. The pack loader
|
||||
* asks the host for those classes first, so a packaged API class would be silently replaced by the
|
||||
* host's copy, and a module's own class there could be replaced by a later API class of that name.
|
||||
*/
|
||||
private static void requireNoApiClasses(String origin, List<JarEntry> classEntries) {
|
||||
var apiClasses = classEntries.stream()
|
||||
.map(entry -> toBinaryName(entry.getName()))
|
||||
.filter(ApiAndJdkClassLoader::isApiClass)
|
||||
.toList();
|
||||
if (apiClasses.isEmpty()) return;
|
||||
var others = apiClasses.size() == 1 ? "" : " and " + (apiClasses.size() - 1) + " more";
|
||||
throw new IllegalArgumentException("Module jar " + origin + " contains Iris API class " + apiClasses.getFirst()
|
||||
+ others + "; Iris provides the API at runtime, so mark the Iris API dependency compileOnly"
|
||||
+ " (Maven: provided) and keep module classes out of " + ApiAndJdkClassLoader.API_PACKAGE_PREFIX + "*");
|
||||
}
|
||||
|
||||
private static List<JarClass> readClasses(String origin, JarFile file, List<JarEntry> classEntries) throws IOException {
|
||||
var classes = new ArrayList<JarClass>(classEntries.size());
|
||||
for (var entry : classEntries) {
|
||||
|
||||
Reference in new issue
Block a user