BundleLoader

Entry point for discovering and loading KSLModelBundle instances.

Three sources are supported:

  • loadJar — a single JAR file

  • loadDirectory — every .jar file directly inside a directory

  • loadFromClasspath — bundles already visible to a ClassLoader on the running JVM's classpath

Discovery uses the standard java.util.ServiceLoader mechanism against META-INF/services/ksl.app.bundle.KSLModelBundle. JARs without a services registration are not bundles; loadJar returns an empty list for them. Pre-bundle JARs holding bare ksl.simulation.ModelBuilderIfc classes are loaded through the separate ksl.utilities.io.JARModelBuilder API instead.

loadJar and loadDirectory create a fresh URLClassLoader per JAR and hand it to each discovered LoadedBundle; the bundles' close releases it. If a single JAR declares multiple bundles, all returned LoadedBundles share that classloader and should be closed as a group.

Functions

Link copied to clipboard

Default parent classloader: the one that loaded KSLCore.

Link copied to clipboard
fun isJar(path: Path): Boolean

Convenience predicate, useful in tests and tooling.

Link copied to clipboard
fun loadDirectory(dir: Path, parent: ClassLoader = defaultParent(), cache: BundleDescriptorCache = BundleDescriptorCache()): List<LoadedBundle>

Loads bundles from every .jar file directly inside dir (non-recursive). Empty list if the directory is missing or contains no JARs. JARs whose loadJar throws are skipped with a warning so one bad bundle never breaks startup discovery.

Link copied to clipboard
fun loadFromClasspath(classLoader: ClassLoader = defaultParent(), cache: BundleDescriptorCache = BundleDescriptorCache()): List<LoadedBundle>

Loads bundles already visible to classLoader (default: the loader that holds KSLCore). Used to surface in-process bundled examples that ship as part of the application's classpath rather than as separate JAR files. Returned bundles have sourceJar == null and bypass the on-disk cache; in-JAR descriptors are still consulted via getResourceAsStream.

Link copied to clipboard
fun loadJar(jarPath: Path, parent: ClassLoader = defaultParent(), cache: BundleDescriptorCache = BundleDescriptorCache()): List<LoadedBundle>

Loads every bundle declared in jarPath via ServiceLoader. Each returned LoadedBundle owns the freshly-created classloader; if the JAR declares multiple bundles they share the loader.