use of lucee.runtime.osgi.BundleFile in project Lucee by lucee.
the class XMLConfigAdmin method updateJar.
public static void updateJar(Config config, Resource resJar, boolean reloadWhenClassicJar) throws IOException, BundleException {
BundleFile bf = new BundleFile(resJar);
// resJar is a bundle
if (bf.isBundle()) {
bf = installBundle(config, bf);
OSGiUtil.loadBundle(bf);
return;
}
Resource lib = ((ConfigImpl) config).getLibraryDirectory();
if (!lib.exists())
lib.mkdir();
Resource fileLib = lib.getRealResource(resJar.getName());
// if there is a existing, has the file changed?
if (fileLib.length() != resJar.length()) {
IOUtil.closeEL(config.getClassLoader());
ResourceUtil.copy(resJar, fileLib);
if (reloadWhenClassicJar)
ConfigWebUtil.reloadLib(config);
}
}
use of lucee.runtime.osgi.BundleFile in project Lucee by lucee.
the class RHExtension method deployBundles.
public void deployBundles(Config config) throws IOException, BundleException {
// no we read the content of the zip
ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(extensionFile.getInputStream()));
ZipEntry entry;
String path;
String fileName;
try {
while ((entry = zis.getNextEntry()) != null) {
path = entry.getName();
fileName = fileName(entry);
// jars
if (!entry.isDirectory() && (startsWith(path, type, "jars") || startsWith(path, type, "jar") || startsWith(path, type, "bundles") || startsWith(path, type, "bundle") || startsWith(path, type, "lib") || startsWith(path, type, "libs")) && StringUtil.endsWithIgnoreCase(path, ".jar")) {
Object obj = XMLConfigAdmin.installBundle(config, zis, fileName, version, false, false);
// jar is not a bundle, only a regular jar
if (!(obj instanceof BundleFile)) {
Resource tmp = (Resource) obj;
Resource tmpJar = tmp.getParentResource().getRealResource(ListUtil.last(path, "\\/"));
tmp.moveTo(tmpJar);
XMLConfigAdmin.updateJar(config, tmpJar, false);
}
}
zis.closeEntry();
}
} finally {
IOUtil.closeEL(zis);
}
}
use of lucee.runtime.osgi.BundleFile in project Lucee by lucee.
the class RHExtension method toBundleDefinition.
private static BundleDefinition toBundleDefinition(InputStream is, String name, String extensionVersion, boolean closeStream) throws IOException, BundleException, ApplicationException {
Resource tmp = SystemUtil.getTempDirectory().getRealResource(name);
try {
IOUtil.copy(is, tmp, closeStream);
BundleFile bf = new BundleFile(tmp);
if (bf.isBundle())
throw new ApplicationException("Jar [" + name + "] is not a valid OSGi Bundle");
return new BundleDefinition(bf.getSymbolicName(), bf.getVersion());
} finally {
tmp.delete();
}
}
use of lucee.runtime.osgi.BundleFile 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));
}
use of lucee.runtime.osgi.BundleFile in project Lucee by lucee.
the class Admin method doGetJars.
private void doGetJars() throws PageException {
Resource lib = config.getLibraryDirectory();
lucee.runtime.type.Query qry = new QueryImpl(new Key[] { KeyConstants._name, KeyConstants._source, KeyConstants._info }, new String[] { "varchar", "varchar", "varchar" }, 0, "jars");
if (lib.isDirectory()) {
Resource[] children = lib.listResources(new ExtensionResourceFilter(new String[] { ".jar", ".zip" }, false, true));
for (int i = 0; i < children.length; i++) {
qry.addRow();
qry.setAt(KeyConstants._name, i + 1, children[i].getName());
qry.setAt(KeyConstants._source, i + 1, children[i].getAbsolutePath());
try {
qry.setAt(KeyConstants._info, i + 1, new BundleFile(children[i]).info());
} catch (Exception e) {
}
}
}
pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Aggregations