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