Fixed bug with service providers under JPMS

Modules that are service providers are not required by any other modules, this causes them to be ignored by
`Configuration.resolve` and not included in the module layer
This commit is contained in:
2022-09-01 13:07:08 +08:00
parent 0b4b2882b0
commit bbd6251bb2

View File

@@ -2,7 +2,9 @@ package net.woggioni.envelope;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ResolvedModule;
import java.lang.module.ModuleReference;
@@ -55,7 +57,14 @@ class MainRunner {
ModuleLayer bootLayer = ModuleLayer.boot();
Configuration bootConfiguration = bootLayer.configuration();
JarFileModuleFinder jarFileModuleFinder = new JarFileModuleFinder(classpath);
Configuration cfg = bootConfiguration.resolve(jarFileModuleFinder, ModuleFinder.of(), Collections.singletonList(mainModuleName));
List<String> moduleNames = Collections.unmodifiableList(
jarFileModuleFinder.findAll()
.stream()
.map(ModuleReference::descriptor)
.map(ModuleDescriptor::name)
.collect(Collectors.toList())
);
Configuration cfg = bootConfiguration.resolve(jarFileModuleFinder, ModuleFinder.of(), moduleNames);
Map<String, ClassLoader> packageMap = new TreeMap<>();
ModuleLayer.Controller controller =
ModuleLayer.defineModules(cfg, Collections.singletonList(ModuleLayer.boot()), moduleName -> {