use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class DeployHandler method getExtension.
public static Resource getExtension(Config config, ExtensionDefintion ed, Log log) {
// local
ExtensionDefintion ext = getLocalExtension(config, ed, null);
if (ext != null) {
try {
Resource src = ext.getSource();
if (src.exists()) {
Resource res = SystemUtil.getTempDirectory().getRealResource(ed.getId() + "-" + ed.getVersion() + ".lex");
ResourceUtil.touch(res);
IOUtil.copy(ext.getSource(), res);
return res;
}
} catch (Exception e) {
}
}
// remote
return downloadExtension(config, ed, log);
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class ExportImportHandler method export.
public static void export(PageContext pc, ConfigServer cs, short types, String target, boolean addOptionalArtifacts, String regularMappingFilter, String componentMappingFilter, String customtagMappingFilter) throws IOException, PageException, ConverterException {
Resource tmp = SystemUtil.getTempDirectory();
Resource dir;
// we need a new directory
do {
dir = tmp.getRealResource(CreateUniqueId.invoke());
} while (dir.isDirectory());
dir.createDirectory(true);
Resource configFile = dir.getRealResource("config.json");
try {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Resource> artifacts;
artifacts = new HashMap<String, Resource>();
map.put("artifacts", artifacts);
// server
map.put("server", _export((ConfigImpl) cs, types, dir.getRealResource("server"), "/server", addOptionalArtifacts, regularMappingFilter, componentMappingFilter, customtagMappingFilter));
// webs
Resource websDir = dir.getRealResource("webs");
List<Map<String, Object>> webs = new ArrayList<Map<String, Object>>();
map.put("webs", webs);
String id;
for (ConfigWeb cw : cs.getConfigWebs()) {
id = cw.getIdentification().getId();
webs.add(_export((ConfigImpl) cw, types, websDir.getRealResource(id), "/webs/" + id, addOptionalArtifacts, regularMappingFilter, componentMappingFilter, customtagMappingFilter));
}
// store config
IOUtil.copy(toIS(JSONConverter.serialize(pc, map)), configFile, true);
// zip everything
CompressUtil.compress(CompressUtil.FORMAT_ZIP, dir, ResourceUtil.toResourceNotExisting(pc, target), false, -1);
} finally {
dir.delete();
}
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class ExportImportHandler method _export.
private static Map<String, Object> _export(ConfigImpl config, short types, Resource dir, String pathAppendix, boolean addOptionalArtifacts, String regularMappingFilter, String componentMappingFilter, String customtagMappingFilter) throws IOException {
Map<String, Object> map = new HashMap<String, Object>();
// Core
if ((types & TYPE_CONFIGURATION) > 0) {
}
// Extension
if ((types & TYPE_EXTENSION) > 0) {
Resource extDir = dir.getRealResource("extensions");
extDir.mkdirs();
List<Object> extensions = new ArrayList<Object>();
map.put("extensions", extensions);
Map<String, String> m;
for (RHExtension ext : config.getRHExtensions()) {
m = new HashMap<String, String>();
extensions.add(m);
m.put("id", ext.getId());
m.put("version", ext.getVersion());
if (dir != null) {
m.put("artifact", pathAppendix + "/extensions/" + ext.getExtensionFile().getName());
if (addOptionalArtifacts)
IOUtil.copy(ext.getExtensionFile(), extDir.getRealResource(ext.getExtensionFile().getName()));
}
}
}
// Core
if ((types & TYPE_CORE) > 0 && config instanceof ConfigServer) {
map.put("core", CFMLEngineFactory.getInstance().getInfo().getVersion().toString());
}
// Files
if ((types & TYPE_FILES) > 0) {
Resource mapDir = dir.getRealResource("mappings");
HashMap<String, Object> mappings = new HashMap<String, Object>();
map.put("mappings", mappings);
mappings.put("regular", exportMapping(config.getMappings(), mapDir.getRealResource("regular"), pathAppendix + "/mappings/regular/", regularMappingFilter));
mappings.put("component", exportMapping(config.getComponentMappings(), mapDir.getRealResource("component"), pathAppendix + "/mappings/component/", componentMappingFilter));
mappings.put("customtag", exportMapping(config.getCustomTagMappings(), mapDir.getRealResource("customtag"), pathAppendix + "/mappings/customtag/", customtagMappingFilter));
}
return map;
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class ResourceSupport method list.
@Override
public String[] list(ResourceFilter filter) {
String[] files = list();
if (files == null)
return null;
List list = new ArrayList();
Resource res;
for (int i = 0; i < files.length; i++) {
res = getRealResource(files[i]);
if (filter.accept(res))
list.add(files[i]);
}
return (String[]) list.toArray(new String[list.size()]);
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class ResourceSupport method listResources.
@Override
public Resource[] listResources(ResourceFilter filter) {
String[] files = list();
if (files == null)
return null;
List list = new ArrayList();
Resource res;
for (int i = 0; i < files.length; i++) {
res = this.getRealResource(files[i]);
if (filter.accept(res))
list.add(res);
}
return (Resource[]) list.toArray(new Resource[list.size()]);
}
Aggregations