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.");
}
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;
}
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);
}
}
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);
}
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));
}
Aggregations