Search in sources :

Example 11 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class XMLConfigAdmin method updateArchive.

public void updateArchive(Config config, Resource archive) throws PageException {
    Log logger = ((ConfigImpl) config).getLog("deploy");
    String type = null, virtual = null, name = null;
    boolean readOnly, topLevel, hidden, physicalFirst;
    short inspect;
    int listMode, listType;
    InputStream is = null;
    ZipFile file = null;
    try {
        file = new ZipFile(FileWrapper.toFile(archive));
        ZipEntry entry = file.getEntry("META-INF/MANIFEST.MF");
        // no manifest
        if (entry == null) {
            DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
            throw new ApplicationException("cannot deploy " + Constants.NAME + " Archive [" + archive + "], file is to old, the file does not have a MANIFEST.");
        }
        is = file.getInputStream(entry);
        Manifest manifest = new Manifest(is);
        Attributes attr = manifest.getMainAttributes();
        // id = unwrap(attr.getValue("mapping-id"));
        type = StringUtil.unwrap(attr.getValue("mapping-type"));
        virtual = StringUtil.unwrap(attr.getValue("mapping-virtual-path"));
        name = ListUtil.trim(virtual, "/");
        readOnly = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-readonly")), false);
        topLevel = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-top-level")), false);
        listMode = ConfigWebUtil.toListenerMode(StringUtil.unwrap(attr.getValue("mapping-listener-mode")), -1);
        listType = ConfigWebUtil.toListenerType(StringUtil.unwrap(attr.getValue("mapping-listener-type")), -1);
        inspect = ConfigWebUtil.inspectTemplate(StringUtil.unwrap(attr.getValue("mapping-inspect")), Config.INSPECT_UNDEFINED);
        if (inspect == Config.INSPECT_UNDEFINED) {
            Boolean trusted = Caster.toBoolean(StringUtil.unwrap(attr.getValue("mapping-trusted")), null);
            if (trusted != null) {
                if (trusted.booleanValue())
                    inspect = Config.INSPECT_NEVER;
                else
                    inspect = Config.INSPECT_ALWAYS;
            }
        }
        hidden = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-hidden")), false);
        physicalFirst = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-physical-first")), false);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
        throw Caster.toPageException(t);
    } finally {
        IOUtil.closeEL(is);
        ZipUtil.close(file);
    }
    try {
        Resource trgDir = config.getConfigDir().getRealResource("archives").getRealResource(type).getRealResource(name);
        Resource trgFile = trgDir.getRealResource(archive.getName());
        trgDir.mkdirs();
        // delete existing files
        ResourceUtil.deleteContent(trgDir, null);
        ResourceUtil.moveTo(archive, trgFile, true);
        logger.log(Log.LEVEL_INFO, "archive", "add " + type + " mapping [" + virtual + "] with archive [" + trgFile.getAbsolutePath() + "]");
        if ("regular".equalsIgnoreCase(type))
            _updateMapping(virtual, null, trgFile.getAbsolutePath(), "archive", inspect, topLevel, listMode, listType, readOnly);
        else if ("cfc".equalsIgnoreCase(type))
            _updateComponentMapping(virtual, null, trgFile.getAbsolutePath(), "archive", inspect);
        else if ("ct".equalsIgnoreCase(type))
            _updateCustomTag(virtual, null, trgFile.getAbsolutePath(), "archive", inspect);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
        throw Caster.toPageException(t);
    }
}
Also used : Log(lucee.commons.io.log.Log) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) Resource(lucee.commons.io.res.Resource) Manifest(java.util.jar.Manifest) ApplicationException(lucee.runtime.exp.ApplicationException) IsZipFile(lucee.runtime.functions.system.IsZipFile) ZipFile(java.util.zip.ZipFile)

Example 12 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class XMLConfigAdmin method removeArchive.

public void removeArchive(Resource archive) throws IOException, PageException {
    Log logger = ((ConfigImpl) config).getLog("deploy");
    String virtual = null, type = null;
    InputStream is = null;
    ZipFile file = null;
    try {
        file = new ZipFile(FileWrapper.toFile(archive));
        ZipEntry entry = file.getEntry("META-INF/MANIFEST.MF");
        // no manifest
        if (entry == null)
            throw new ApplicationException("cannot remove " + Constants.NAME + " Archive [" + archive + "], file is to old, the file does not have a MANIFEST.");
        is = file.getInputStream(entry);
        Manifest manifest = new Manifest(is);
        Attributes attr = manifest.getMainAttributes();
        virtual = StringUtil.unwrap(attr.getValue("mapping-virtual-path"));
        type = StringUtil.unwrap(attr.getValue("mapping-type"));
        logger.info("archive", "remove " + type + " mapping [" + virtual + "]");
        if ("regular".equalsIgnoreCase(type))
            removeMapping(virtual);
        else if ("cfc".equalsIgnoreCase(type))
            removeComponentMapping(virtual);
        else if ("ct".equalsIgnoreCase(type))
            removeCustomTag(virtual);
        else
            throw new ApplicationException("invalid type [" + type + "], valid types are [regular, cfc, ct]");
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        IOUtil.closeEL(is);
        ZipUtil.close(file);
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) IsZipFile(lucee.runtime.functions.system.IsZipFile) ZipFile(java.util.zip.ZipFile) Log(lucee.commons.io.log.Log) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest)

Example 13 with Log

use of lucee.commons.io.log.Log 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 14 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class RHExtension method toQuery.

public static Query toQuery(Config config, Element[] children) throws PageException {
    Log log = config.getLog("deploy");
    Query qry = createQuery();
    for (int i = 0; i < children.length; i++) {
        try {
            // ,i+1
            new RHExtension(config, children[i]).populate(qry);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            log.error("extension", t);
        }
    }
    return qry;
}
Also used : Query(lucee.runtime.type.Query) Log(lucee.commons.io.log.Log)

Example 15 with Log

use of lucee.commons.io.log.Log in project Lucee by lucee.

the class RHExtension method readManifestConfig.

private void readManifestConfig(Manifest manifest, String label, String _img) throws ApplicationException {
    boolean isWeb = config instanceof ConfigWeb;
    type = isWeb ? "web" : "server";
    Log logger = ((ConfigImpl) config).getLog("deploy");
    Info info = ConfigWebUtil.getEngine(config).getInfo();
    Attributes attr = manifest.getMainAttributes();
    readName(label, StringUtil.unwrap(attr.getValue("name")));
    label = name;
    readVersion(label, StringUtil.unwrap(attr.getValue("version")));
    label += " : " + version;
    readId(label, StringUtil.unwrap(attr.getValue("id")));
    readReleaseType(label, StringUtil.unwrap(attr.getValue("release-type")), isWeb);
    description = StringUtil.unwrap(attr.getValue("description"));
    trial = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("trial")), false);
    if (_img == null)
        _img = StringUtil.unwrap(attr.getValue("image"));
    image = _img;
    String cat = StringUtil.unwrap(attr.getValue("category"));
    if (StringUtil.isEmpty(cat, true))
        cat = StringUtil.unwrap(attr.getValue("categories"));
    readCategories(label, cat);
    readCoreVersion(label, StringUtil.unwrap(attr.getValue("lucee-core-version")), info);
    readLoaderVersion(label, StringUtil.unwrap(attr.getValue("lucee-loader-version")));
    startBundles = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("start-bundles")), true);
    readAMF(label, StringUtil.unwrap(attr.getValue("amf")), logger);
    readResource(label, StringUtil.unwrap(attr.getValue("resource")), logger);
    readSearch(label, StringUtil.unwrap(attr.getValue("search")), logger);
    readORM(label, StringUtil.unwrap(attr.getValue("orm")), logger);
    readMonitor(label, StringUtil.unwrap(attr.getValue("monitor")), logger);
    readCache(label, StringUtil.unwrap(attr.getValue("cache")), logger);
    readCacheHandler(label, StringUtil.unwrap(attr.getValue("cache-handler")), logger);
    readJDBC(label, StringUtil.unwrap(attr.getValue("jdbc")), logger);
    readMapping(label, StringUtil.unwrap(attr.getValue("mapping")), logger);
    readEventGatewayInstances(label, StringUtil.unwrap(attr.getValue("event-gateway-instance")), logger);
}
Also used : Log(lucee.commons.io.log.Log) Attributes(java.util.jar.Attributes) Info(lucee.Info) BundleInfo(lucee.runtime.osgi.BundleInfo) ConfigWeb(lucee.runtime.config.ConfigWeb) ConfigImpl(lucee.runtime.config.ConfigImpl)

Aggregations

Log (lucee.commons.io.log.Log)35 ConfigImpl (lucee.runtime.config.ConfigImpl)14 PageException (lucee.runtime.exp.PageException)10 Resource (lucee.commons.io.res.Resource)8 ApplicationException (lucee.runtime.exp.ApplicationException)8 DatasourceConnection (lucee.runtime.db.DatasourceConnection)7 Struct (lucee.runtime.type.Struct)6 SQLException (java.sql.SQLException)5 ZipInputStream (java.util.zip.ZipInputStream)5 DataSource (lucee.runtime.db.DataSource)5 InputStream (java.io.InputStream)4 ZipEntry (java.util.zip.ZipEntry)4 StructImpl (lucee.runtime.type.StructImpl)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 Attributes (java.util.jar.Attributes)3 DatabaseException (lucee.runtime.exp.DatabaseException)3 Key (lucee.runtime.type.Collection.Key)3