Search in sources :

Example 11 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class XMLConfigWebFactory method loadExtensionBundles.

/**
 * loads the bundles defined in the extensions
 * @param cs
 * @param config
 * @param doc
 * @param log
 */
private static void loadExtensionBundles(ConfigServerImpl cs, ConfigImpl config, Document doc, Log log) {
    Element parent = getChildByName(doc.getDocumentElement(), "extensions");
    Element[] children = getChildren(parent, "rhextension");
    String strBundles;
    List<RHExtension> extensions = new ArrayList<RHExtension>();
    RHExtension rhe;
    for (Element child : children) {
        BundleInfo[] bfsq;
        try {
            rhe = new RHExtension(config, child);
            if (rhe.getStartBundles())
                rhe.deployBundles(config);
            extensions.add(rhe);
        } catch (Exception e) {
            log.error("load-extension", e);
            continue;
        }
    }
    config.setExtensions(extensions.toArray(new RHExtension[extensions.size()]));
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) BundleInfo(lucee.runtime.osgi.BundleInfo) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) ClassException(lucee.commons.lang.ClassException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 12 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class CFMLEngineImpl method deployBundledExtensionZip.

private void deployBundledExtensionZip(ConfigServerImpl cs) {
    Resource dir = cs.getLocalExtensionProviderDirectory();
    List<ExtensionDefintion> existing = DeployHandler.getLocalExtensions(cs);
    String sub = "extensions/";
    // MUST this does not work on windows! we need to add an index
    ZipEntry entry;
    ZipInputStream zis = null;
    try {
        CodeSource src = CFMLEngineFactory.class.getProtectionDomain().getCodeSource();
        if (src == null)
            return;
        URL loc = src.getLocation();
        zis = new ZipInputStream(loc.openStream());
        String path, name;
        int index;
        Resource temp;
        RHExtension rhe;
        Iterator<ExtensionDefintion> it;
        ExtensionDefintion exist;
        while ((entry = zis.getNextEntry()) != null) {
            path = entry.getName();
            if (path.startsWith(sub) && path.endsWith(".lex")) {
                // ignore non lex files or file from else where
                index = path.lastIndexOf('/') + 1;
                if (index == sub.length()) {
                    // ignore sub directories
                    name = path.substring(index);
                    temp = null;
                    try {
                        temp = SystemUtil.getTempDirectory().getRealResource(name);
                        ResourceUtil.touch(temp);
                        Util.copy(zis, temp.getOutputStream(), false, true);
                        rhe = new RHExtension(cs, temp, false);
                        boolean alreadyExists = false;
                        it = existing.iterator();
                        while (it.hasNext()) {
                            exist = it.next();
                            if (exist.equals(rhe)) {
                                alreadyExists = true;
                                break;
                            }
                        }
                        if (!alreadyExists) {
                            temp.moveTo(dir.getRealResource(name));
                        }
                    } finally {
                        if (temp != null && temp.exists())
                            temp.delete();
                    }
                }
            }
            zis.closeEntry();
        }
    } catch (Throwable t) {
        // TODO log this
        ExceptionUtil.rethrowIfNecessary(t);
    } finally {
        Util.closeEL(zis);
    }
    return;
}
Also used : ZipEntry(java.util.zip.ZipEntry) Resource(lucee.commons.io.res.Resource) CodeSource(java.security.CodeSource) URL(java.net.URL) RHExtension(lucee.runtime.extension.RHExtension) ZipInputStream(java.util.zip.ZipInputStream) ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 13 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class XMLConfigAdmin method getRHExtension.

private RHExtension getRHExtension(ConfigImpl config, String id, RHExtension defaultValue) {
    Element extensions = _getRootElement("extensions");
    // LuceeHandledExtensions
    Element[] children = XMLConfigWebFactory.getChildren(extensions, "rhextension");
    if (children != null)
        for (int i = 0; i < children.length; i++) {
            if (!id.equals(children[i].getAttribute("id")))
                continue;
            try {
                return new RHExtension(config, children[i]);
            } catch (Exception e) {
                return defaultValue;
            }
        }
    return defaultValue;
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) Element(org.w3c.dom.Element) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) ConverterException(lucee.runtime.converter.ConverterException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CFXTagException(lucee.runtime.cfx.CFXTagException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClassException(lucee.commons.lang.ClassException) DOMException(org.w3c.dom.DOMException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) HTTPException(lucee.runtime.exp.HTTPException)

Example 14 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class XMLConfigAdmin method cleanBundles.

public static void cleanBundles(RHExtension rhe, ConfigImpl config, BundleDefinition[] candiatesToRemove) throws BundleException, ApplicationException, IOException {
    if (ArrayUtil.isEmpty(candiatesToRemove))
        return;
    BundleCollection coreBundles = ConfigWebUtil.getEngine(config).getBundleCollection();
    // core master
    _cleanBundles(candiatesToRemove, coreBundles.core.getSymbolicName(), coreBundles.core.getVersion());
    // core slaves
    Iterator<Bundle> it = coreBundles.getSlaves();
    Bundle b;
    while (it.hasNext()) {
        b = it.next();
        _cleanBundles(candiatesToRemove, b.getSymbolicName(), b.getVersion());
    }
    // all extension
    Iterator<RHExtension> itt = config.getAllRHExtensions().iterator();
    RHExtension _rhe;
    while (itt.hasNext()) {
        _rhe = itt.next();
        if (rhe != null && rhe.equals(_rhe))
            continue;
        BundleInfo[] bundles = _rhe.getBundles();
        for (BundleInfo bi : bundles) {
            _cleanBundles(candiatesToRemove, bi.getSymbolicName(), bi.getVersion());
        }
    }
    // now we only have BundlesDefs in the array no longer used
    for (BundleDefinition ctr : candiatesToRemove) {
        if (ctr != null)
            OSGiUtil.removeLocalBundleSilently(ctr.getName(), ctr.getVersion(), true);
    }
}
Also used : BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) BundleCollection(lucee.loader.osgi.BundleCollection) RHExtension(lucee.runtime.extension.RHExtension) BundleInfo(lucee.runtime.osgi.BundleInfo) Bundle(org.osgi.framework.Bundle)

Example 15 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class ConfigImpl method getExtensionBundleDefintions.

public Collection<BundleDefinition> getExtensionBundleDefintions() {
    if (this.extensionBundles == null) {
        RHExtension[] rhes = getRHExtensions();
        Map<String, BundleDefinition> extensionBundles = new HashMap<String, BundleDefinition>();
        for (RHExtension rhe : rhes) {
            BundleInfo[] bis;
            try {
                bis = rhe.getBundles();
            } catch (Exception e) {
                continue;
            }
            if (bis != null)
                for (BundleInfo bi : bis) {
                    extensionBundles.put(bi.getSymbolicName() + "|" + bi.getVersionAsString(), bi.toBundleDefinition());
                }
        }
        this.extensionBundles = extensionBundles;
    }
    return extensionBundles.values();
}
Also used : BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) RHExtension(lucee.runtime.extension.RHExtension) BundleInfo(lucee.runtime.osgi.BundleInfo) HashMap(java.util.HashMap) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) IOException(java.io.IOException) DatabaseException(lucee.runtime.exp.DatabaseException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) TemplateException(lucee.runtime.exp.TemplateException) ClassException(lucee.commons.lang.ClassException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Aggregations

RHExtension (lucee.runtime.extension.RHExtension)15 ApplicationException (lucee.runtime.exp.ApplicationException)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Resource (lucee.commons.io.res.Resource)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 PageException (lucee.runtime.exp.PageException)5 FunctionLibException (lucee.transformer.library.function.FunctionLibException)5 TagLibException (lucee.transformer.library.tag.TagLibException)5 MalformedURLException (java.net.MalformedURLException)4 ClassException (lucee.commons.lang.ClassException)4 SecurityException (lucee.runtime.exp.SecurityException)4 ExtensionDefintion (lucee.runtime.extension.ExtensionDefintion)4 BundleInfo (lucee.runtime.osgi.BundleInfo)4 BundleException (org.osgi.framework.BundleException)4 Element (org.w3c.dom.Element)4 ZipInputStream (java.util.zip.ZipInputStream)3 BundleDefinition (lucee.runtime.osgi.OSGiUtil.BundleDefinition)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 UnknownHostException (java.net.UnknownHostException)2