Search in sources :

Example 1 with CFMLEngineFactory

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

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

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

the class XMLConfigAdmin method restart.

/*private Resource getPatchDirectory(CFMLEngine engine) throws IOException {
    	//File f=engine.getCFMLEngineFactory().getResourceRoot();
    	Resource res = ResourcesImpl.getFileResourceProvider().getResource(engine.getCFMLEngineFactory().getResourceRoot().getAbsolutePath());
    	Resource pd = res.getRealResource("patches");
        if(!pd.exists())pd.mkdirs();
        return pd;
    }*/
/**
 * run update from cfml engine
 * @throws PageException
 */
public void restart(Password password) throws PageException {
    checkWriteAccess();
    ConfigServerImpl cs = (ConfigServerImpl) ConfigImpl.getConfigServer(config, password);
    CFMLEngineFactory factory = cs.getCFMLEngine().getCFMLEngineFactory();
    synchronized (factory) {
        try {
            cleanUp(factory);
            factory.restart(cs.getPassword());
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
    }
}
Also used : 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) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 4 with CFMLEngineFactory

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

the class OSGiUtil method getBundleDefinitions.

public static List<BundleDefinition> getBundleDefinitions(BundleContext bc) {
    Set<String> set = new HashSet<>();
    List<BundleDefinition> list = new ArrayList<>();
    Bundle[] bundles = bc.getBundles();
    for (Bundle b : bundles) {
        list.add(new BundleDefinition(b));
        set.add(b.getSymbolicName() + ":" + b.getVersion());
    }
    // is it in jar directory but not loaded
    CFMLEngine engine = ConfigWebUtil.getEngine(ThreadLocalPageContext.getConfig());
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    try {
        File[] children = factory.getBundleDirectory().listFiles(JAR_EXT_FILTER);
        BundleFile bf;
        for (int i = 0; i < children.length; i++) {
            try {
                bf = new BundleFile(children[i]);
                if (bf.isBundle() && !set.contains(bf.getSymbolicName() + ":" + bf.getVersion()))
                    list.add(new BundleDefinition(bf.getSymbolicName(), bf.getVersion()));
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        }
    } catch (IOException ioe) {
    }
    return list;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CFMLEngine(lucee.loader.engine.CFMLEngine) File(java.io.File) HashSet(java.util.HashSet) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 5 with CFMLEngineFactory

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

the class OSGiUtil method removeLocalBundle.

/**
 * get local bundle, but does not download from update provider!
 * @param name
 * @param version
 * @return
 * @throws BundleException
 */
public static void removeLocalBundle(String name, Version version, boolean removePhysical, boolean doubleTap) throws BundleException {
    name = name.trim();
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    BundleFile bf = _getBundleFile(factory, name, version, null);
    if (bf != null) {
        BundleDefinition bd = bf.toBundleDefinition();
        if (bd != null) {
            Bundle b = bd.getLocalBundle();
            if (b != null) {
                stopIfNecessary(b);
                b.uninstall();
            }
        }
    }
    if (!removePhysical)
        return;
    // remove file
    if (bf != null) {
        if (!bf.getFile().delete() && doubleTap)
            bf.getFile().deleteOnExit();
    }
}
Also used : Bundle(org.osgi.framework.Bundle) CFMLEngine(lucee.loader.engine.CFMLEngine) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Aggregations

CFMLEngineFactory (lucee.loader.engine.CFMLEngineFactory)15 IOException (java.io.IOException)10 CFMLEngine (lucee.loader.engine.CFMLEngine)9 PageException (lucee.runtime.exp.PageException)8 BundleException (org.osgi.framework.BundleException)8 UnknownHostException (java.net.UnknownHostException)7 File (java.io.File)6 MalformedURLException (java.net.MalformedURLException)6 ApplicationException (lucee.runtime.exp.ApplicationException)6 Bundle (org.osgi.framework.Bundle)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ClassException (lucee.commons.lang.ClassException)5 CFXTagException (lucee.runtime.cfx.CFXTagException)5 ConverterException (lucee.runtime.converter.ConverterException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 HTTPException (lucee.runtime.exp.HTTPException)5 SecurityException (lucee.runtime.exp.SecurityException)5 FunctionLibException (lucee.transformer.library.function.FunctionLibException)5 TagLibException (lucee.transformer.library.tag.TagLibException)5 DOMException (org.w3c.dom.DOMException)5