Search in sources :

Example 6 with BundleFile

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

the class XMLConfigAdmin method updateJar.

public static void updateJar(Config config, Resource resJar, boolean reloadWhenClassicJar) throws IOException, BundleException {
    BundleFile bf = new BundleFile(resJar);
    // resJar is a bundle
    if (bf.isBundle()) {
        bf = installBundle(config, bf);
        OSGiUtil.loadBundle(bf);
        return;
    }
    Resource lib = ((ConfigImpl) config).getLibraryDirectory();
    if (!lib.exists())
        lib.mkdir();
    Resource fileLib = lib.getRealResource(resJar.getName());
    // if there is a existing, has the file changed?
    if (fileLib.length() != resJar.length()) {
        IOUtil.closeEL(config.getClassLoader());
        ResourceUtil.copy(resJar, fileLib);
        if (reloadWhenClassicJar)
            ConfigWebUtil.reloadLib(config);
    }
}
Also used : Resource(lucee.commons.io.res.Resource) BundleFile(lucee.runtime.osgi.BundleFile)

Example 7 with BundleFile

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

the class RHExtension method deployBundles.

public void deployBundles(Config config) throws IOException, BundleException {
    // no we read the content of the zip
    ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(extensionFile.getInputStream()));
    ZipEntry entry;
    String path;
    String fileName;
    try {
        while ((entry = zis.getNextEntry()) != null) {
            path = entry.getName();
            fileName = fileName(entry);
            // jars
            if (!entry.isDirectory() && (startsWith(path, type, "jars") || startsWith(path, type, "jar") || startsWith(path, type, "bundles") || startsWith(path, type, "bundle") || startsWith(path, type, "lib") || startsWith(path, type, "libs")) && StringUtil.endsWithIgnoreCase(path, ".jar")) {
                Object obj = XMLConfigAdmin.installBundle(config, zis, fileName, version, false, false);
                // jar is not a bundle, only a regular jar
                if (!(obj instanceof BundleFile)) {
                    Resource tmp = (Resource) obj;
                    Resource tmpJar = tmp.getParentResource().getRealResource(ListUtil.last(path, "\\/"));
                    tmp.moveTo(tmpJar);
                    XMLConfigAdmin.updateJar(config, tmpJar, false);
                }
            }
            zis.closeEntry();
        }
    } finally {
        IOUtil.closeEL(zis);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) Resource(lucee.commons.io.res.Resource) BundleFile(lucee.runtime.osgi.BundleFile)

Example 8 with BundleFile

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

the class RHExtension method toBundleDefinition.

private static BundleDefinition toBundleDefinition(InputStream is, String name, String extensionVersion, boolean closeStream) throws IOException, BundleException, ApplicationException {
    Resource tmp = SystemUtil.getTempDirectory().getRealResource(name);
    try {
        IOUtil.copy(is, tmp, closeStream);
        BundleFile bf = new BundleFile(tmp);
        if (bf.isBundle())
            throw new ApplicationException("Jar [" + name + "] is not a valid OSGi Bundle");
        return new BundleDefinition(bf.getSymbolicName(), bf.getVersion());
    } finally {
        tmp.delete();
    }
}
Also used : BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) ApplicationException(lucee.runtime.exp.ApplicationException) Resource(lucee.commons.io.res.Resource) BundleFile(lucee.runtime.osgi.BundleFile)

Example 9 with BundleFile

use of lucee.runtime.osgi.BundleFile 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)

Example 10 with BundleFile

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

the class Admin method doGetJars.

private void doGetJars() throws PageException {
    Resource lib = config.getLibraryDirectory();
    lucee.runtime.type.Query qry = new QueryImpl(new Key[] { KeyConstants._name, KeyConstants._source, KeyConstants._info }, new String[] { "varchar", "varchar", "varchar" }, 0, "jars");
    if (lib.isDirectory()) {
        Resource[] children = lib.listResources(new ExtensionResourceFilter(new String[] { ".jar", ".zip" }, false, true));
        for (int i = 0; i < children.length; i++) {
            qry.addRow();
            qry.setAt(KeyConstants._name, i + 1, children[i].getName());
            qry.setAt(KeyConstants._source, i + 1, children[i].getAbsolutePath());
            try {
                qry.setAt(KeyConstants._info, i + 1, new BundleFile(children[i]).info());
            } catch (Exception e) {
            }
        }
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) BundleFile(lucee.runtime.osgi.BundleFile) Query(lucee.runtime.type.Query) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) SMTPException(lucee.runtime.net.mail.SMTPException) ApplicationException(lucee.runtime.exp.ApplicationException)

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