Search in sources :

Example 1 with SourceInfo

use of lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo in project Lucee by lucee.

the class PageExceptionImpl method toString.

public static String toString(PageContext pc, StackTraceElement trace) {
    String path = null;
    if (trace.getFileName() == null || trace.getFileName().endsWith(".java"))
        return trace.toString();
    Config config = ThreadLocalPageContext.getConfig(pc);
    if (config != null) {
        Resource res = pc.getConfig().getResource(trace.getFileName());
        if (res.exists())
            path = trace.getFileName();
        // get path from source
        if (path == null) {
            SourceInfo si = MappingUtil.getMatch(pc, trace);
            if (si != null) {
                if (si.absolutePath(pc) != null) {
                    res = pc.getConfig().getResource(si.absolutePath(pc));
                    if (res.exists())
                        path = si.absolutePath(pc);
                }
                if (path == null && si.relativePath != null)
                    path = si.relativePath;
            }
            if (path == null)
                path = trace.getFileName();
        }
    }
    return trace.getClassName() + "." + trace.getMethodName() + (trace.isNativeMethod() ? "(Native Method)" : (path != null && trace.getLineNumber() >= 0 ? "(" + path + ":" + trace.getLineNumber() + ")" : (path != null ? "(" + path + ")" : "(Unknown Source)")));
}
Also used : SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) Config(lucee.runtime.config.Config) Resource(lucee.commons.io.res.Resource)

Example 2 with SourceInfo

use of lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo in project Lucee by lucee.

the class PageExceptionImpl method _getTagContext.

private static void _getTagContext(Config config, Array tagContext, StackTraceElement[] traces, LinkedList<PageSource> sources) {
    // StackTraceElement[] traces = getStackTraceElements(t);
    int line = 0;
    String template = "", tlast;
    Struct item;
    StackTraceElement trace = null;
    int index = -1;
    PageSource ps;
    PageContextImpl pc = null;
    if (config instanceof ConfigWeb)
        pc = (PageContextImpl) ThreadLocalPageContext.get();
    for (int i = 0; i < traces.length; i++) {
        trace = traces[i];
        tlast = template;
        template = trace.getFileName();
        if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java"))
            continue;
        // content
        if (!StringUtil.emptyIfNull(tlast).equals(template))
            index++;
        String[] content = null;
        String dspPath = template;
        try {
            Resource res = config.getResource(template);
            if (!res.exists()) {
                PageSource _ps = pc == null ? null : pc.getPageSource(template);
                res = _ps == null ? null : _ps.getPhyscalFile();
                if (res == null || !res.exists()) {
                    res = config.getResource(_ps.getDisplayPath());
                    if (res != null && res.exists())
                        dspPath = res.getAbsolutePath();
                } else
                    dspPath = res.getAbsolutePath();
            } else
                dspPath = res.getAbsolutePath();
            // class was not build on the local filesystem
            if (!res.exists()) {
                SourceInfo si = pc != null ? MappingUtil.getMatch(pc, trace) : MappingUtil.getMatch(config, trace);
                if (si != null && si.relativePath != null) {
                    dspPath = si.relativePath;
                    res = ResourceUtil.toResourceNotExisting(ThreadLocalPageContext.get(), si.relativePath, true, true);
                    if (!res.exists()) {
                        PageSource _ps = PageSourceImpl.best(config.getPageSources(ThreadLocalPageContext.get(), null, si.relativePath, false, false, true));
                        if (_ps != null && _ps.exists()) {
                            res = _ps.getResource();
                            if (res != null && res.exists())
                                dspPath = res.getAbsolutePath();
                        } else
                            dspPath = res.getAbsolutePath();
                    } else
                        dspPath = res.getAbsolutePath();
                }
            }
            if (res.exists()) {
                InputStream is = res.getInputStream();
                if (ClassUtil.isBytecode(is)) {
                    // empty code array to show ??
                    content = new String[] {};
                } else
                    content = IOUtil.toStringArray(IOUtil.getReader(res, config.getTemplateCharset()));
                IOUtil.closeEL(is);
            } else {
                if (sources.size() > index)
                    ps = sources.get(index);
                else
                    ps = null;
                if (ps != null && trace.getClassName().equals(ps.getClassName())) {
                    if (ps.physcalExists())
                        content = IOUtil.toStringArray(IOUtil.getReader(ps.getPhyscalFile(), config.getTemplateCharset()));
                    template = ps.getDisplayPath();
                }
            }
        } catch (Throwable th) {
        }
        // check last
        if (tagContext.size() > 0) {
            try {
                Struct last = (Struct) tagContext.getE(tagContext.size());
                if (last.get(KeyConstants._Raw_Trace).equals(trace.toString()))
                    continue;
            } catch (Exception e) {
            }
        }
        item = new StructImpl();
        line = trace.getLineNumber();
        item.setEL(KeyConstants._template, dspPath);
        item.setEL(KeyConstants._line, new Double(line));
        item.setEL(KeyConstants._id, "??");
        item.setEL(KeyConstants._Raw_Trace, trace.toString());
        item.setEL(KeyConstants._type, "cfml");
        item.setEL(KeyConstants._column, new Double(0));
        if (content != null) {
            if (content.length > 0) {
                item.setEL(KeyConstants._codePrintHTML, getCodePrint(content, line, true));
                item.setEL(KeyConstants._codePrintPlain, getCodePrint(content, line, false));
            } else {
                item.setEL(KeyConstants._codePrintHTML, "??");
                item.setEL(KeyConstants._codePrintPlain, "??");
            }
        } else {
            item.setEL(KeyConstants._codePrintHTML, "");
            item.setEL(KeyConstants._codePrintPlain, "");
        }
        // FUTURE id
        tagContext.appendEL(item);
    }
}
Also used : SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource) StructImpl(lucee.runtime.type.StructImpl)

Example 3 with SourceInfo

use of lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo in project Lucee by lucee.

the class MappingUtil method searchArchive.

private static PageSource searchArchive(Mapping mapping, String name, boolean onlyCFC) {
    Resource archive = mapping.getArchive();
    if (archive != null && archive.isFile()) {
        ZipInputStream zis = null;
        try {
            zis = new ZipInputStream(archive.getInputStream());
            ZipEntry entry;
            Class<?> clazz;
            while ((entry = zis.getNextEntry()) != null) {
                if (entry.isDirectory() || !entry.getName().endsWith(".class"))
                    continue;
                clazz = mapping.getArchiveClass(toClassName(entry.getName()), null);
                if (clazz == null)
                    continue;
                SourceInfo srcInf = ASMUtil.getSourceInfo(mapping.getConfig(), clazz, onlyCFC);
                if (name.equalsIgnoreCase(srcInf.name)) {
                    PageSource ps = mapping.getPageSource(srcInf.relativePath);
                    return ps;
                }
            }
        } catch (IOException ioe) {
            SystemOut.printDate(ioe);
        } finally {
            IOUtil.closeEL(zis);
        }
    }
    // TODO Auto-generated method stub
    return null;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) ZipEntry(java.util.zip.ZipEntry) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) PageSource(lucee.runtime.PageSource)

Example 4 with SourceInfo

use of lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo in project Lucee by lucee.

the class MappingUtil method getMatch.

public static SourceInfo getMatch(PageContext pc, Config config, StackTraceElement trace) {
    if (trace.getFileName() == null)
        return null;
    if (pc == null && config == null)
        config = ThreadLocalPageContext.getConfig();
    // PageContext pc = ThreadLocalPageContext.get();
    Mapping[] mappings = pc != null ? ConfigWebUtil.getAllMappings(pc) : ConfigWebUtil.getAllMappings(config);
    if (pc != null)
        config = pc.getConfig();
    Mapping mapping;
    Class clazz;
    for (int i = 0; i < mappings.length; i++) {
        mapping = mappings[i];
        // print.e("virtual:"+mapping.getVirtual()+"+"+trace.getClassName());
        // look for the class in that mapping
        clazz = ((MappingImpl) mapping).loadClass(trace.getClassName());
        if (clazz == null)
            continue;
        // classname is not distinct, because of that we must check class content
        try {
            SourceInfo si = ASMUtil.getSourceInfo(config, clazz, false);
            if (si != null && trace.getFileName() != null && trace.getFileName().equals(si.absolutePath(pc)))
                return si;
        } catch (IOException e) {
        }
    }
    return null;
}
Also used : SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) Mapping(lucee.runtime.Mapping) IOException(java.io.IOException)

Aggregations

SourceInfo (lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo)4 IOException (java.io.IOException)3 Resource (lucee.commons.io.res.Resource)3 PageSource (lucee.runtime.PageSource)2 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 Mapping (lucee.runtime.Mapping)1 PageContextImpl (lucee.runtime.PageContextImpl)1 Config (lucee.runtime.config.Config)1 ConfigWeb (lucee.runtime.config.ConfigWeb)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1