Search in sources :

Example 1 with ConstantPoolException

use of org.eclipse.ceylon.langtools.classfile.ConstantPoolException in project ceylon by eclipse.

the class BytecodeUtils method readModuleInfo.

private static ClassFile readModuleInfo(String moduleName, final File jarFile) {
    // default module has no module descriptor
    if (Module.DEFAULT_MODULE_NAME.equals(moduleName))
        return null;
    try {
        try (JarFile jar = new JarFile(jarFile)) {
            String modulePath = getModulePath(moduleName);
            String name1 = modulePath + "/$module_.class";
            JarEntry entry = jar.getJarEntry(name1);
            if (entry == null) {
                String name2 = modulePath + "/module_.class";
                entry = jar.getJarEntry(name2);
            }
            if (entry != null) {
                try (InputStream stream = jar.getInputStream(entry)) {
                    return ClassFile.read(stream);
                } catch (ConstantPoolException e) {
                    throw new RuntimeException(e);
                }
            }
            return null;
        }
    } catch (IOException e) {
        throw new RuntimeException("Failed to read class file for module " + jarFile.getPath(), e);
    }
}
Also used : InputStream(java.io.InputStream) ConstantPoolException(org.eclipse.ceylon.langtools.classfile.ConstantPoolException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry)

Example 2 with ConstantPoolException

use of org.eclipse.ceylon.langtools.classfile.ConstantPoolException in project ceylon by eclipse.

the class BytecodeUtils method readClassFiles.

private static List<ClassFile> readClassFiles(final File jarFile) {
    try {
        try (JarFile jar = new JarFile(jarFile)) {
            List<ClassFile> ret = new ArrayList<ClassFile>(jar.size());
            Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                String name = entry.getName().toLowerCase();
                if (name.endsWith(".class")) {
                    try (InputStream stream = jar.getInputStream(entry)) {
                        try {
                            ret.add(ClassFile.read(stream));
                        } catch (ConstantPoolException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
            return ret;
        }
    } catch (IOException e) {
        throw new RuntimeException("Failed to read class file for module " + jarFile.getPath(), e);
    }
}
Also used : ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ConstantPoolException(org.eclipse.ceylon.langtools.classfile.ConstantPoolException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry)

Example 3 with ConstantPoolException

use of org.eclipse.ceylon.langtools.classfile.ConstantPoolException in project ceylon by eclipse.

the class ClassFileScanner method scan.

public void scan(ModuleInfo moduleInfo) throws IOException {
    PathFilter pathFilter = null;
    if (moduleInfo != null && moduleInfo.getFilter() != null) {
        pathFilter = PathFilterParser.parse(moduleInfo.getFilter());
    }
    try (ZipFile zf = new ZipFile(jarFile)) {
        Enumeration<? extends ZipEntry> entries = zf.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (entry.isDirectory() || !entry.getName().toLowerCase().endsWith(".class"))
                continue;
            if (pathFilter != null && !pathFilter.accept(entry.getName()))
                continue;
            try (InputStream is = zf.getInputStream(entry)) {
                try {
                    ClassFile classFile = ClassFile.read(is);
                    isPublicApi = false;
                    checkPublicApi(classFile);
                } catch (ConstantPoolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InvalidDescriptor e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : PathFilter(org.eclipse.ceylon.model.cmr.PathFilter) ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ConstantPoolException(org.eclipse.ceylon.langtools.classfile.ConstantPoolException) InvalidDescriptor(org.eclipse.ceylon.langtools.classfile.Descriptor.InvalidDescriptor)

Aggregations

InputStream (java.io.InputStream)3 ConstantPoolException (org.eclipse.ceylon.langtools.classfile.ConstantPoolException)3 IOException (java.io.IOException)2 JarEntry (java.util.jar.JarEntry)2 JarFile (java.util.jar.JarFile)2 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)2 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 InvalidDescriptor (org.eclipse.ceylon.langtools.classfile.Descriptor.InvalidDescriptor)1 PathFilter (org.eclipse.ceylon.model.cmr.PathFilter)1