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