Search in sources :

Example 1 with ExtensionDefintion

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;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Log(lucee.commons.io.log.Log) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) RHExtension(lucee.runtime.extension.RHExtension) ApplicationException(lucee.runtime.exp.ApplicationException) ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) Iterator(java.util.Iterator)

Example 2 with ExtensionDefintion

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ExtensionDefintion

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();
}
Also used : ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion)

Example 4 with ExtensionDefintion

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;
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) HashMap(java.util.HashMap) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 5 with ExtensionDefintion

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);
}
Also used : ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) Resource(lucee.commons.io.res.Resource) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException)

Aggregations

ExtensionDefintion (lucee.runtime.extension.ExtensionDefintion)9 Resource (lucee.commons.io.res.Resource)5 IOException (java.io.IOException)4 RHExtension (lucee.runtime.extension.RHExtension)4 ApplicationException (lucee.runtime.exp.ApplicationException)3 PageException (lucee.runtime.exp.PageException)3 URL (java.net.URL)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ZipInputStream (java.util.zip.ZipInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 CodeSource (java.security.CodeSource)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 ZipEntry (java.util.zip.ZipEntry)1 Log (lucee.commons.io.log.Log)1 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)1