Search in sources :

Example 1 with ResourceClassLoader

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));
}
Also used : Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) BundleBuilderFactory(lucee.runtime.osgi.BundleBuilderFactory) ResourceClassLoader(lucee.commons.io.res.util.ResourceClassLoader) ResourceClassLoader(lucee.commons.io.res.util.ResourceClassLoader) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleFile(lucee.runtime.osgi.BundleFile) BundleContext(org.osgi.framework.BundleContext)

Aggregations

ArrayList (java.util.ArrayList)1 Log (lucee.commons.io.log.Log)1 Resource (lucee.commons.io.res.Resource)1 ResourceClassLoader (lucee.commons.io.res.util.ResourceClassLoader)1 CFMLEngine (lucee.loader.engine.CFMLEngine)1 BundleBuilderFactory (lucee.runtime.osgi.BundleBuilderFactory)1 BundleFile (lucee.runtime.osgi.BundleFile)1 BundleContext (org.osgi.framework.BundleContext)1