use of lucee.runtime.extension.ExtensionDefintion in project Lucee by lucee.
the class CFMLEngineImpl method deployBundledExtension.
private void deployBundledExtension(ConfigServerImpl cs) {
Resource dir = cs.getLocalExtensionProviderDirectory();
List<ExtensionDefintion> existing = DeployHandler.getLocalExtensions(cs);
Map<String, ExtensionDefintion> existingMap = new HashMap<String, ExtensionDefintion>();
{
Iterator<ExtensionDefintion> it = existing.iterator();
ExtensionDefintion ed;
while (it.hasNext()) {
ed = it.next();
try {
existingMap.put(ed.getSource().getName(), ed);
} catch (ApplicationException e) {
}
}
}
Log log = cs.getLog("deploy");
// get the index
ClassLoader cl = CFMLEngineFactory.getInstance().getCFMLEngineFactory().getClass().getClassLoader();
InputStream is = cl.getResourceAsStream("extensions/.index");
if (is == null)
is = cl.getResourceAsStream("/extensions/.index");
if (is == null)
is = SystemUtil.getResourceAsStream(null, "/extensions/.index");
if (is == null) {
log.error("extract-extension", "could not found [/extensions/.index] defined in the index in the lucee.jar");
return;
}
try {
String index = IOUtil.toString(is, CharsetUtil.UTF8);
log.info("extract-extension", "the following extensions are bundled with the lucee.jar [" + index + "]");
String[] names = lucee.runtime.type.util.ListUtil.listToStringArray(index, ';');
String name;
Resource temp = null;
RHExtension rhe;
ExtensionDefintion exist;
Iterator<ExtensionDefintion> it;
for (int i = 0; i < names.length; i++) {
name = names[i];
if (StringUtil.isEmpty(name, true))
continue;
name = name.trim();
// does it already exist?
if (existingMap.containsKey(name)) {
continue;
}
is = cl.getResourceAsStream("extensions/" + name);
if (is == null)
is = cl.getResourceAsStream("/extensions/" + name);
if (is == null) {
log.error("extract-extension", "could not found extension [" + name + "] defined in the index in the lucee.jar");
continue;
}
try {
temp = SystemUtil.getTempDirectory().getRealResource(name);
ResourceUtil.touch(temp);
Util.copy(is, temp.getOutputStream(), false, true);
rhe = new RHExtension(cs, temp, false);
ExtensionDefintion alreadyExists = null;
it = existing.iterator();
while (it.hasNext()) {
exist = it.next();
if (exist.equals(rhe)) {
alreadyExists = exist;
break;
}
}
String trgName = rhe.getId() + "-" + rhe.getVersion() + ".lex";
if (alreadyExists == null) {
temp.moveTo(dir.getRealResource(trgName));
log.info("extract-extension", "added [" + name + "] to [" + dir + "]");
} else if (!alreadyExists.getSource().getName().equals(trgName)) {
log.info("extract-extension", "rename [" + alreadyExists.getSource() + "] to [" + trgName + "]");
alreadyExists.getSource().moveTo(alreadyExists.getSource().getParentResource().getRealResource(trgName));
}
// now we check all extension name (for extension no longer delivered by lucee)
it = existing.iterator();
while (it.hasNext()) {
exist = it.next();
trgName = exist.getId() + "-" + exist.getVersion() + ".lex";
if (!trgName.equals(exist.getSource().getName())) {
exist.getSource().moveTo(exist.getSource().getParentResource().getRealResource(trgName));
log.info("extract-extension", "rename [" + exist.getSource() + "] to [" + trgName + "]");
}
}
} finally {
if (temp != null && temp.exists())
temp.delete();
}
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
log.error("extract-extension", t);
}
return;
}
use of lucee.runtime.extension.ExtensionDefintion in project Lucee by lucee.
the class CFMLEngineImpl method toSet.
public static Set<ExtensionDefintion> toSet(Set<ExtensionDefintion> set, List<ExtensionDefintion> list) {
LinkedHashMap<String, ExtensionDefintion> map = new LinkedHashMap<String, ExtensionDefintion>();
ExtensionDefintion ed;
// set > map
if (set != null) {
Iterator<ExtensionDefintion> it = set.iterator();
while (it.hasNext()) {
ed = it.next();
map.put(ed.toString(), ed);
}
}
// list > map
if (list != null) {
Iterator<ExtensionDefintion> it = list.iterator();
while (it.hasNext()) {
ed = it.next();
map.put(ed.toString(), ed);
}
}
// to Set
LinkedHashSet<ExtensionDefintion> rtn = new LinkedHashSet<ExtensionDefintion>();
Iterator<ExtensionDefintion> it = map.values().iterator();
while (it.hasNext()) {
ed = it.next();
rtn.add(ed);
}
return rtn;
}
use of lucee.runtime.extension.ExtensionDefintion in project Lucee by lucee.
the class CFMLEngineImpl method toList.
public static String toList(Set<ExtensionDefintion> set) {
StringBuilder sb = new StringBuilder();
Iterator<ExtensionDefintion> it = set.iterator();
ExtensionDefintion ed;
while (it.hasNext()) {
ed = it.next();
if (sb.length() > 0)
sb.append(", ");
sb.append(ed.toString());
}
return sb.toString();
}
use of lucee.runtime.extension.ExtensionDefintion in project Lucee by lucee.
the class ConfigServerImpl method loadLocalExtensions.
@Override
public List<ExtensionDefintion> loadLocalExtensions() {
Resource[] locReses = getLocalExtensionProviderDirectory().listResources(new ExtensionResourceFilter(".lex"));
if (localExtensions == null || localExtSize != locReses.length || extHash(locReses) != localExtHash) {
localExtensions = new ArrayList<ExtensionDefintion>();
Map<String, String> map = new HashMap<String, String>();
RHExtension ext;
String v, fileName, uuid, version;
ExtensionDefintion ed;
for (int i = 0; i < locReses.length; i++) {
ed = null;
// we stay happy with the file name when it has the right pattern (uuid-version.lex)
fileName = locReses[i].getName();
if (fileName.length() > 39) {
uuid = fileName.substring(0, 35);
version = fileName.substring(36, fileName.length() - 4);
if (Decision.isUUId(uuid)) {
ed = new ExtensionDefintion(uuid, version);
ed.setSource(this, locReses[i]);
}
}
if (ed == null) {
try {
ext = new RHExtension(this, locReses[i], false);
ed = new ExtensionDefintion(ext.getId(), ext.getVersion());
ed.setSource(ext);
} catch (Exception e) {
SystemOut.printDate(e);
}
}
if (ed != null) {
// check if we already have an extension with the same id to avoid having more than once
v = map.get(ed.getId());
if (v != null && v.compareToIgnoreCase(ed.getId()) > 0)
continue;
map.put(ed.getId(), ed.getVersion());
localExtensions.add(ed);
}
}
localExtHash = extHash(locReses);
// we store the size because localExtensions size could be smaller because of duplicates
localExtSize = locReses.length;
}
return localExtensions;
}
use of lucee.runtime.extension.ExtensionDefintion 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);
}
Aggregations