Search in sources :

Example 1 with ClassPathOpener

use of com.taobao.android.dx.cf.direct.ClassPathOpener in project atlas by alibaba.

the class AnnotationLister method process.

/** Processes based on configuration specified in constructor. */
void process() {
    for (String path : args.files) {
        ClassPathOpener opener;
        opener = new ClassPathOpener(path, true, new ClassPathOpener.Consumer() {

            public boolean processFileBytes(String name, long lastModified, byte[] bytes) {
                if (!name.endsWith(".class")) {
                    return true;
                }
                ByteArray ba = new ByteArray(bytes);
                DirectClassFile cf = new DirectClassFile(ba, name, true);
                cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
                AttributeList attributes = cf.getAttributes();
                Attribute att;
                String cfClassName = cf.getThisClass().getClassType().getClassName();
                if (cfClassName.endsWith(PACKAGE_INFO)) {
                    att = attributes.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
                    for (; att != null; att = attributes.findNext(att)) {
                        BaseAnnotations ann = (BaseAnnotations) att;
                        visitPackageAnnotation(cf, ann);
                    }
                    att = attributes.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
                    for (; att != null; att = attributes.findNext(att)) {
                        BaseAnnotations ann = (BaseAnnotations) att;
                        visitPackageAnnotation(cf, ann);
                    }
                } else if (isMatchingInnerClass(cfClassName) || isMatchingPackage(cfClassName)) {
                    printMatch(cf);
                } else {
                    att = attributes.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
                    for (; att != null; att = attributes.findNext(att)) {
                        BaseAnnotations ann = (BaseAnnotations) att;
                        visitClassAnnotation(cf, ann);
                    }
                    att = attributes.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
                    for (; att != null; att = attributes.findNext(att)) {
                        BaseAnnotations ann = (BaseAnnotations) att;
                        visitClassAnnotation(cf, ann);
                    }
                }
                return true;
            }

            public void onException(Exception ex) {
                throw new RuntimeException(ex);
            }

            public void onProcessArchiveStart(File file) {
            }
        });
        opener.process();
    }
}
Also used : ClassPathOpener(com.taobao.android.dx.cf.direct.ClassPathOpener) DirectClassFile(com.taobao.android.dx.cf.direct.DirectClassFile) Attribute(com.taobao.android.dx.cf.iface.Attribute) AttributeList(com.taobao.android.dx.cf.iface.AttributeList) BaseAnnotations(com.taobao.android.dx.cf.attrib.BaseAnnotations) ByteArray(com.taobao.android.dx.util.ByteArray) DirectClassFile(com.taobao.android.dx.cf.direct.DirectClassFile) File(java.io.File)

Example 2 with ClassPathOpener

use of com.taobao.android.dx.cf.direct.ClassPathOpener in project atlas by alibaba.

the class Main method processOne.

/**
     * Processes one pathname element.
     *
     * @param pathname {@code non-null;} the pathname to process. May
     * be the path of a class file, a jar file, or a directory
     * containing class files.
     * @param filter {@code non-null;} A filter for excluding files.
     */
private void processOne(String pathname, FileNameFilter filter) {
    ClassPathOpener opener;
    opener = new ClassPathOpener(pathname, false, filter, new ClassPathOpener.Consumer() {

        @Override
        public boolean processFileBytes(String name, long lastModified, byte[] bytes) {
            return Main.this.processFileBytes(name, lastModified, bytes);
        }

        @Override
        public void onException(Exception ex) {
            if (ex instanceof StopProcessing) {
                throw (StopProcessing) ex;
            } else if (ex instanceof SimException) {
                dxConsole.err.println("\nEXCEPTION FROM SIMULATION:");
                dxConsole.err.println(ex.getMessage() + "\n");
                dxConsole.err.println(((SimException) ex).getContext());
            } else {
                dxConsole.err.println("\nUNEXPECTED TOP-LEVEL EXCEPTION:");
                ex.printStackTrace(dxConsole.err);
            }
            errors.incrementAndGet();
        }

        @Override
        public void onProcessArchiveStart(File file) {
            if (args.verbose) {
                dxConsole.out.println("processing archive " + file + "...");
            }
        }
    });
    if (args.numThreads > 1) {
        parallelProcessorFutures.add(threadPool.submit(new ParallelProcessor(opener)));
    } else {
        if (opener.process()) {
            anyFilesProcessed = true;
        }
    }
}
Also used : ClassPathOpener(com.taobao.android.dx.cf.direct.ClassPathOpener) SimException(com.taobao.android.dx.cf.code.SimException) CstString(com.taobao.android.dx.rop.cst.CstString) DexFile(com.taobao.android.dx.dex.file.DexFile) DirectClassFile(com.taobao.android.dx.cf.direct.DirectClassFile) File(java.io.File) DexException(com.taobao.android.dex.DexException) UsageException(com.taobao.android.dx.command.UsageException) ParseException(com.taobao.android.dx.cf.iface.ParseException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SimException(com.taobao.android.dx.cf.code.SimException)

Aggregations

ClassPathOpener (com.taobao.android.dx.cf.direct.ClassPathOpener)2 DirectClassFile (com.taobao.android.dx.cf.direct.DirectClassFile)2 File (java.io.File)2 DexException (com.taobao.android.dex.DexException)1 BaseAnnotations (com.taobao.android.dx.cf.attrib.BaseAnnotations)1 SimException (com.taobao.android.dx.cf.code.SimException)1 Attribute (com.taobao.android.dx.cf.iface.Attribute)1 AttributeList (com.taobao.android.dx.cf.iface.AttributeList)1 ParseException (com.taobao.android.dx.cf.iface.ParseException)1 UsageException (com.taobao.android.dx.command.UsageException)1 DexFile (com.taobao.android.dx.dex.file.DexFile)1 CstString (com.taobao.android.dx.rop.cst.CstString)1 ByteArray (com.taobao.android.dx.util.ByteArray)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1