Search in sources :

Example 1 with PathFilter

use of org.eclipse.ceylon.model.cmr.PathFilter 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)

Example 2 with PathFilter

use of org.eclipse.ceylon.model.cmr.PathFilter in project ceylon by eclipse.

the class JvmBackendUtil method loadStaticMetamodel.

public static void loadStaticMetamodel(InputStream is, List<String> dexEntries, StaticMetamodelLoader staticMetamodelLoader) {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
        String line;
        ModuleSpec module = null;
        SortedSet<String> packages = new TreeSet<>();
        List<ArtifactResult> imports = new LinkedList<ArtifactResult>();
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("=")) {
                if (module != null)
                    finishLoadingModule(module, packages, imports, dexEntries, staticMetamodelLoader);
                module = ModuleSpec.parse(line.substring(1));
                packages.clear();
                imports.clear();
                continue;
            }
            boolean _optional = false;
            boolean _shared = false;
            if (line.startsWith("?")) {
                _optional = true;
                line = line.substring(1);
            }
            if (line.startsWith("+")) {
                _shared = true;
                line = line.substring(1);
            }
            // SERIOUSLY!!
            final boolean optional = _optional;
            final boolean shared = _shared;
            if (line.startsWith("@")) {
                packages.add(line.substring(1));
                continue;
            }
            // it's an import
            ModuleSpec importSpec = ModuleSpec.parse(line);
            final String namespace = ModuleUtil.getNamespaceFromUri(importSpec.getName());
            final String name = ModuleUtil.getModuleNameFromUri(importSpec.getName());
            final String version = importSpec.getVersion();
            imports.add(new ArtifactResult() {

                @Override
                public String namespace() {
                    return namespace;
                }

                @Override
                public String name() {
                    return name;
                }

                @Override
                public String version() {
                    return version;
                }

                @Override
                public boolean optional() {
                    return optional;
                }

                @Override
                public boolean exported() {
                    return shared;
                }

                @Override
                public ArtifactResultType type() {
                    // Is this important?
                    return ArtifactResultType.OTHER;
                }

                @Override
                public VisibilityType visibilityType() {
                    return VisibilityType.STRICT;
                }

                @Override
                public File artifact() throws RepositoryException {
                    return null;
                }

                @Override
                public PathFilter filter() {
                    return null;
                }

                @Override
                public List<ArtifactResult> dependencies() throws RepositoryException {
                    return null;
                }

                @Override
                public String artifactId() {
                    return ModuleUtil.getMavenArtifactIdIfMavenModule(name);
                }

                @Override
                public String groupId() {
                    return ModuleUtil.getMavenGroupIdIfMavenModule(name);
                }

                @Override
                public String classifier() {
                    return ModuleUtil.getMavenClassifierIfMavenModule(name);
                }

                @Override
                public String repositoryDisplayString() {
                    return "Android dependency";
                }

                @Override
                public Repository repository() {
                    return null;
                }

                @Override
                public ModuleScope moduleScope() {
                    return ModuleScope.COMPILE;
                }

                @Override
                public List<Exclusion> getExclusions() {
                    return null;
                }
            });
        }
        if (module != null)
            finishLoadingModule(module, packages, imports, dexEntries, staticMetamodelLoader);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : PathFilter(org.eclipse.ceylon.model.cmr.PathFilter) InputStreamReader(java.io.InputStreamReader) ModuleScope(org.eclipse.ceylon.model.cmr.ModuleScope) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) Repository(org.eclipse.ceylon.model.cmr.Repository) ArtifactResultType(org.eclipse.ceylon.model.cmr.ArtifactResultType) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) VisibilityType(org.eclipse.ceylon.model.cmr.VisibilityType) TreeSet(java.util.TreeSet) BufferedReader(java.io.BufferedReader) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

ZipFile (java.util.zip.ZipFile)2 PathFilter (org.eclipse.ceylon.model.cmr.PathFilter)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 ZipEntry (java.util.zip.ZipEntry)1 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)1 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)1 ConstantPoolException (org.eclipse.ceylon.langtools.classfile.ConstantPoolException)1 InvalidDescriptor (org.eclipse.ceylon.langtools.classfile.Descriptor.InvalidDescriptor)1 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)1 ArtifactResultType (org.eclipse.ceylon.model.cmr.ArtifactResultType)1 ModuleScope (org.eclipse.ceylon.model.cmr.ModuleScope)1 Repository (org.eclipse.ceylon.model.cmr.Repository)1