Search in sources :

Example 11 with BundleFile

use of lucee.runtime.osgi.BundleFile in project Lucee by lucee.

the class Admin method doGetBundles.

private void doGetBundles() throws PageException {
    CFMLEngine engine = ConfigWebUtil.getEngine(config);
    BundleCollection coreBundles = engine.getBundleCollection();
    java.util.Collection<BundleDefinition> extBundles = config.getAllExtensionBundleDefintions();
    List<BundleDefinition> bds = OSGiUtil.getBundleDefinitions(engine.getBundleContext());
    Iterator<BundleDefinition> it = bds.iterator();
    BundleDefinition bd;
    Bundle b;
    String str;
    Query qry = new QueryImpl(new Key[] { SYMBOLIC_NAME, KeyConstants._title, KeyConstants._description, KeyConstants._version, VENDOR, KeyConstants._state, PATH, USED_BY, KeyConstants._id, FRAGMENT, HEADERS }, bds.size(), "bundles");
    int row = 0;
    while (it.hasNext()) {
        row++;
        bd = it.next();
        b = bd.getLoadedBundle();
        qry.setAt(SYMBOLIC_NAME, row, bd.getName());
        qry.setAt(KeyConstants._title, row, bd.getName());
        qry.setAt(KeyConstants._version, row, bd.getVersionAsString());
        qry.setAt(USED_BY, row, _usedBy(bd.getName(), bd.getVersion(), coreBundles, extBundles));
        BundleFile bf = null;
        try {
            if (b != null) {
                qry.setAt(PATH, row, b.getLocation());
            } else {
                bf = bd.getBundleFile(false);
                qry.setAt(PATH, row, bf.getFile());
            }
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
        Map<String, Object> headers = null;
        if (b != null) {
            qry.setAt(KeyConstants._version, row, bd.getVersion().toString());
            qry.setAt(KeyConstants._id, row, b.getBundleId());
            qry.setAt(KeyConstants._state, row, OSGiUtil.toState(b.getState(), null));
            qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(b));
            headers = OSGiUtil.getHeaders(b);
        } else {
            qry.setAt(KeyConstants._state, row, "notinstalled");
            try {
                if (b != null) {
                    qry.setAt(KeyConstants._version, row, b.getVersion().toString());
                    qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(b));
                    Dictionary<String, String> dic = b.getHeaders();
                    Enumeration<String> keys = dic.keys();
                    headers = new HashMap<String, Object>();
                    String key;
                    while (keys.hasMoreElements()) {
                        key = keys.nextElement();
                        headers.put(key, dic.get(key));
                    }
                } else {
                    if (bf != null)
                        bf = bd.getBundleFile(false);
                    qry.setAt(KeyConstants._version, row, bf.getVersionAsString());
                    // qry.setAt(KeyConstants._id, row, bf.getBundleId());
                    qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(bf));
                    headers = bf.getHeaders();
                }
            } catch (BundleException e) {
            }
        }
        if (headers != null) {
            Struct h = Caster.toStruct(headers, false);
            qry.setAt(HEADERS, row, h);
            // title
            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))
                qry.setAt(KeyConstants._title, row, 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))
                qry.setAt(KeyConstants._description, row, 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))
                qry.setAt(VENDOR, row, str);
        // Specification-Vendor,Bundle-Vendor
        }
    }
    QuerySort.call(pageContext, qry, "title");
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : Query(lucee.runtime.type.Query) Bundle(org.osgi.framework.Bundle) Struct(lucee.runtime.type.Struct) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) BundleCollection(lucee.loader.osgi.BundleCollection) QueryImpl(lucee.runtime.type.QueryImpl) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleException(org.osgi.framework.BundleException) BundleFile(lucee.runtime.osgi.BundleFile)

Example 12 with BundleFile

use of lucee.runtime.osgi.BundleFile in project Lucee by lucee.

the class XMLConfigAdmin method updateBundle.

/**
 * @param config
 * @param is
 * @param name
 * @param extensionVersion if given jar is no bundle the extension version is used for the bundle created
 * @param closeStream
 * @return
 * @throws IOException
 * @throws BundleException
 */
static Bundle updateBundle(Config config, InputStream is, String name, String extensionVersion, boolean closeStream) throws IOException, BundleException {
    Object obj = installBundle(config, is, name, extensionVersion, closeStream, false);
    if (!(obj instanceof BundleFile))
        throw new BundleException("input is not an OSGi Bundle.");
    BundleFile bf = (BundleFile) obj;
    return OSGiUtil.loadBundle(bf);
}
Also used : CreateObject(lucee.runtime.functions.other.CreateObject) BundleException(org.osgi.framework.BundleException) BundleFile(lucee.runtime.osgi.BundleFile)

Example 13 with BundleFile

use of lucee.runtime.osgi.BundleFile in project Lucee by lucee.

the class XMLConfigAdmin method installBundle.

private static BundleFile installBundle(Config config, BundleFile bf) throws IOException, BundleException {
    // does this bundle already exists
    BundleFile _bf = OSGiUtil.getBundleFile(bf.getSymbolicName(), bf.getVersion(), null, false, null);
    if (_bf != null)
        return _bf;
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    // copy to jar directory
    File jar = new File(factory.getBundleDirectory(), bf.getSymbolicName() + "-" + bf.getVersion().toString() + (".jar"));
    InputStream is = bf.getInputStream();
    OutputStream os = new FileOutputStream(jar);
    try {
        IOUtil.copy(is, os, false, false);
    } finally {
        IOUtil.closeEL(is, os);
    }
    return new BundleFile(jar);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleFile(lucee.runtime.osgi.BundleFile) BundleFile(lucee.runtime.osgi.BundleFile) File(java.io.File) IsZipFile(lucee.runtime.functions.system.IsZipFile) ZipFile(java.util.zip.ZipFile) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Aggregations

BundleFile (lucee.runtime.osgi.BundleFile)13 Resource (lucee.commons.io.res.Resource)8 BundleException (org.osgi.framework.BundleException)5 CFMLEngine (lucee.loader.engine.CFMLEngine)4 BundleDefinition (lucee.runtime.osgi.OSGiUtil.BundleDefinition)4 Struct (lucee.runtime.type.Struct)4 ZipInputStream (java.util.zip.ZipInputStream)3 ApplicationException (lucee.runtime.exp.ApplicationException)3 StructImpl (lucee.runtime.type.StructImpl)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 ZipEntry (java.util.zip.ZipEntry)2 Log (lucee.commons.io.log.Log)2 BundleCollection (lucee.loader.osgi.BundleCollection)2 DeprecatedException (lucee.runtime.exp.DeprecatedException)2 PageException (lucee.runtime.exp.PageException)2 SecurityException (lucee.runtime.exp.SecurityException)2 CreateObject (lucee.runtime.functions.other.CreateObject)2 SMTPException (lucee.runtime.net.mail.SMTPException)2 BundleBuilderFactory (lucee.runtime.osgi.BundleBuilderFactory)2