Search in sources :

Example 1 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class OSGiUtil method getBundleFile.

/**
 * this should be used when you not want to load a Bundle to the system
 * @param name
 * @param version
 * @param id only necessray if downloadIfNecessary is set to true
 * @param downloadIfNecessary
 * @return
 * @throws BundleException
 */
public static BundleFile getBundleFile(String name, Version version, Identification id, boolean downloadIfNecessary) throws BundleException {
    name = name.trim();
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    StringBuilder versionsFound = new StringBuilder();
    // is it in jar directory but not loaded
    BundleFile bf = _getBundleFile(factory, name, version, versionsFound);
    if (bf != null)
        return bf;
    // if not found try to download
    if (downloadIfNecessary && version != null) {
        try {
            bf = new BundleFile(factory.downloadBundle(name, version.toString(), id));
            if (bf.isBundle())
                return bf;
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    }
    if (versionsFound.length() > 0)
        throw new BundleException("The OSGi Bundle with name [" + name + "] is not available in version [" + version + "] locally or from the update provider, the following versions are available locally [" + versionsFound + "].");
    if (version != null)
        throw new BundleException("The OSGi Bundle with name [" + name + "] in version [" + version + "] is not available locally or from the update provider.");
    throw new BundleException("The OSGi Bundle with name [" + name + "] is not available locally or from the update provider.");
}
Also used : CFMLEngine(lucee.loader.engine.CFMLEngine) BundleException(org.osgi.framework.BundleException) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 2 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class OSGiUtil method loadBundleFromLocal.

public static Bundle loadBundleFromLocal(BundleContext bc, String name, Version version, boolean loadIfNecessary, Bundle defaultValue) {
    name = name.trim();
    Bundle[] bundles = bc.getBundles();
    for (Bundle b : bundles) {
        if (name.equalsIgnoreCase(b.getSymbolicName())) {
            if (version == null || version.equals(b.getVersion())) {
                return b;
            }
        }
    }
    if (!loadIfNecessary)
        return defaultValue;
    // is it in jar directory but not loaded
    CFMLEngine engine = ConfigWebUtil.getEngine(ThreadLocalPageContext.getConfig());
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    BundleFile bf = _getBundleFile(factory, name, version, null);
    if (bf != null) {
        try {
            return _loadBundle(bc, bf.getFile());
        } catch (Exception e) {
        }
    }
    return defaultValue;
}
Also used : Bundle(org.osgi.framework.Bundle) CFMLEngine(lucee.loader.engine.CFMLEngine) PageException(lucee.runtime.exp.PageException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 3 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class Admin method doGetBundle.

private void doGetBundle() throws PageException {
    String symbolicName = getString("admin", "getBundle", "symbolicName", true);
    Version version = OSGiUtil.toVersion(getString("version", null), null);
    BundleDefinition bd;
    BundleFile bf = null;
    Bundle b = OSGiUtil.getBundleLoaded(symbolicName, version, null);
    if (b != null) {
        bd = new BundleDefinition(b);
    } else {
        try {
            bf = OSGiUtil.getBundleFile(symbolicName, version, null, false);
            bd = bf.toBundleDefinition();
            b = bd.getLoadedBundle();
        } catch (BundleException e) {
            throw Caster.toPageException(e);
        }
    }
    CFMLEngine engine = ConfigWebUtil.getEngine(config);
    BundleCollection coreBundles = engine.getBundleCollection();
    java.util.Collection<BundleDefinition> extBundles = config.getAllExtensionBundleDefintions();
    Struct sct = new StructImpl();
    pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
    sct.set(SYMBOLIC_NAME, bd.getName());
    sct.set(KeyConstants._title, bd.getName());
    sct.set(KeyConstants._version, bd.getVersionAsString());
    sct.set(USED_BY, _usedBy(bd.getName(), bd.getVersion(), coreBundles, extBundles));
    try {
        if (b != null) {
            sct.set(PATH, b.getLocation());
        } else {
            if (bf == null)
                bf = bd.getBundleFile(false);
            sct.set(PATH, bf.getFile());
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    Map<String, Object> headers = null;
    if (b != null) {
        sct.set(KeyConstants._version, bd.getVersion().toString());
        sct.set(KeyConstants._id, b.getBundleId());
        sct.set(KeyConstants._state, OSGiUtil.toState(b.getState(), null));
        sct.set(FRAGMENT, OSGiUtil.isFragment(b));
        headers = OSGiUtil.getHeaders(b);
    } else {
        sct.set(KeyConstants._state, "notinstalled");
        try {
            if (bf == null)
                bf = bd.getBundleFile(false);
            sct.set(KeyConstants._version, bf.getVersionAsString());
            sct.set(FRAGMENT, OSGiUtil.isFragment(bf));
            headers = bf.getHeaders();
        } catch (BundleException e) {
        }
    }
    if (headers != null) {
        Struct h = Caster.toStruct(headers, false);
        sct.set(HEADERS, h);
        // title
        String str = Caster.toString(h.get("Bundle-Title", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Implementation-Title", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Specification-Title", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Bundle-Name", null), null);
        if (!StringUtil.isEmpty(str))
            sct.set(KeyConstants._title, str);
        // description
        str = Caster.toString(h.get("Bundle-Description", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Implementation-Description", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Specification-Description", null), null);
        if (!StringUtil.isEmpty(str))
            sct.set(KeyConstants._description, str);
        // Vendor
        str = Caster.toString(h.get("Bundle-Vendor", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Implementation-Vendor", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Specification-Vendor", null), null);
        if (!StringUtil.isEmpty(str))
            sct.set(VENDOR, str);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Struct(lucee.runtime.type.Struct) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) BundleCollection(lucee.loader.osgi.BundleCollection) StructImpl(lucee.runtime.type.StructImpl) Version(org.osgi.framework.Version) BundleException(org.osgi.framework.BundleException) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleFile(lucee.runtime.osgi.BundleFile)

Example 4 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class RamCache method init.

@Override
public void init(Config config, String cacheName, Struct arguments) throws IOException {
    // RamCache is also used without calling init, because of that we have this test in constructor and here
    if (controller == null) {
        CFMLEngine engine = ConfigWebUtil.getEngine(config);
        if (engine instanceof CFMLEngineImpl) {
            controller = new Controler((CFMLEngineImpl) engine, this);
            controller.start();
        }
    }
    if (controller == null)
        throw new IOException("was not able to start controller");
    // until
    long until = Caster.toLongValue(arguments.get("timeToLiveSeconds", Constants.LONG_ZERO), Constants.LONG_ZERO) * 1000;
    long idleTime = Caster.toLongValue(arguments.get("timeToIdleSeconds", Constants.LONG_ZERO), Constants.LONG_ZERO) * 1000;
    Object ci = arguments.get("controlIntervall", null);
    if (ci == null)
        ci = arguments.get("controlInterval", null);
    int intervalInSeconds = Caster.toIntValue(ci, DEFAULT_CONTROL_INTERVAL);
    init(until, idleTime, intervalInSeconds);
}
Also used : CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) CFMLEngine(lucee.loader.engine.CFMLEngine) IOException(java.io.IOException)

Example 5 with CFMLEngine

use of lucee.loader.engine.CFMLEngine 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

CFMLEngine (lucee.loader.engine.CFMLEngine)31 File (java.io.File)10 IOException (java.io.IOException)9 CFMLEngineFactory (lucee.loader.engine.CFMLEngineFactory)9 Bundle (org.osgi.framework.Bundle)9 Resource (lucee.commons.io.res.Resource)6 BundleFile (lucee.runtime.osgi.BundleFile)5 BundleException (org.osgi.framework.BundleException)5 ServletException (javax.servlet.ServletException)4 BundleContext (org.osgi.framework.BundleContext)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Reader (java.io.Reader)3 BundleCollection (lucee.loader.osgi.BundleCollection)3 PageContext (lucee.runtime.PageContext)3 Struct (lucee.runtime.type.Struct)3 OutputStream (java.io.OutputStream)2 StringReader (java.io.StringReader)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2