use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class ConfigWebUtil method getFile.
/**
* touch a file object by the string definition
* @param config
* @param directory
* @param path
* @param type
* @return matching file
*/
public static Resource getFile(Config config, Resource directory, String path, short type) {
path = replacePlaceholder(path, config);
if (!StringUtil.isEmpty(path, true)) {
Resource file = getFile(directory.getRealResource(path), type);
if (file != null)
return file;
file = getFile(config.getResource(path), type);
if (file != null)
return file;
}
return null;
}
use of lucee.commons.io.res.Resource 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.commons.io.res.Resource in project Lucee by lucee.
the class ConfigWebUtil method getFile.
/**
* generate a file object by the string definition
* @param rootDir
* @param strDir
* @param defaultDir
* @param configDir
* @param type
* @param config
* @return file
*/
static Resource getFile(Resource rootDir, String strDir, String defaultDir, Resource configDir, short type, ConfigImpl config) {
strDir = replacePlaceholder(strDir, config);
if (!StringUtil.isEmpty(strDir, true)) {
Resource res;
if (strDir.indexOf("://") != -1) {
// TODO better impl.
res = getFile(config.getResource(strDir), type);
if (res != null)
return res;
}
res = getFile(rootDir.getRealResource(strDir), type);
if (res != null)
return res;
res = getFile(config.getResource(strDir), type);
if (res != null)
return res;
}
if (defaultDir == null)
return null;
Resource file = getFile(configDir.getRealResource(defaultDir), type);
return file;
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class ConfigWebUtil method deployWebContext.
/**
* deploys all content in "web-context-deployment" to a web context, used for new context mostly or update existings
* @param cs
* @param cw
* @param throwError
* @throws IOException
*/
public static void deployWebContext(ConfigServer cs, ConfigWeb cw, boolean throwError) throws IOException {
Resource deploy = cs.getConfigDir().getRealResource("web-context-deployment"), trg;
if (!deploy.isDirectory())
return;
trg = cw.getConfigDir().getRealResource("context");
try {
_deploy(cw, deploy, trg);
} catch (IOException ioe) {
if (throwError)
throw ioe;
SystemOut.printDate(cw.getErrWriter(), ExceptionUtil.getStacktrace(ioe, true));
}
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class DeployHandler method downloadExtension.
public static Resource downloadExtension(Config config, ExtensionDefintion ed, Log log) {
String apiKey = config.getIdentification().getApiKey();
URL url;
RHExtensionProvider[] providers = ((ConfigImpl) config).getRHExtensionProviders();
for (int i = 0; i < providers.length; i++) {
HTTPResponse rsp = null;
try {
url = providers[i].getURL();
StringBuilder qs = new StringBuilder();
addQueryParam(qs, "ioid", apiKey);
addQueryParam(qs, "version", ed.getVersion());
url = new URL(url, "/rest/extension/provider/full/" + ed.getId() + qs);
rsp = HTTPEngine.get(url, null, null, -1, false, "UTF-8", "", null, new Header[] { new HeaderImpl("accept", "application/cfml") });
if (rsp.getStatusCode() != 200)
throw new IOException("failed to load extension: " + ed);
// copy it locally
Resource res = SystemUtil.getTempDirectory().getRealResource(ed.getId() + "-" + ed.getVersion() + ".lex");
ResourceUtil.touch(res);
IOUtil.copy(rsp.getContentAsStream(), res, true);
return res;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (log != null)
log.error("extension", t);
} finally {
HTTPEngine.closeEL(rsp);
}
}
return null;
}
Aggregations