use of lucee.commons.io.res.util.ResourceClassLoader in project Lucee by lucee.
the class ConfigWebUtil method loadLib.
static void loadLib(ConfigServerImpl configServer, ConfigImpl config) throws IOException {
// get lib and classes resources
Resource lib = config.getLibraryDirectory();
Resource[] libs = lib.listResources(ExtensionResourceFilter.EXTENSION_JAR_NO_DIR);
// get resources from server config and merge
if (configServer != null) {
ResourceClassLoader rcl = configServer.getResourceClassLoader();
libs = ResourceUtil.merge(libs, rcl.getResources());
}
CFMLEngine engine = ConfigWebUtil.getEngine(config);
BundleContext bc = engine.getBundleContext();
Log log = config.getLog("application");
BundleFile bf;
List<Resource> list = new ArrayList<Resource>();
for (int i = 0; i < libs.length; i++) {
try {
bf = BundleFile.newInstance(libs[i]);
// jar is not a bundle
if (bf == null) {
// convert to a bundle
BundleBuilderFactory factory = new BundleBuilderFactory(libs[i]);
factory.setVersion("0.0.0.0");
Resource tmp = SystemUtil.getTempFile("jar", false);
factory.build(tmp);
IOUtil.copy(tmp, libs[i]);
bf = BundleFile.newInstance(libs[i]);
}
OSGiUtil.start(OSGiUtil.installBundle(bc, libs[i], true));
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
list.add(libs[i]);
log.log(Log.LEVEL_ERROR, "OSGi", t);
}
}
// set classloader
ClassLoader parent = SystemUtil.getCoreClassLoader();
config.setResourceClassLoader(new ResourceClassLoader(list.toArray(new Resource[list.size()]), parent));
}
Aggregations