Java Code Examples for proguard.classfile.ClassPool

The following examples show how to use proguard.classfile.ClassPool. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: proguard   Source File: OutputWriter.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes possibly renamed directories that should be preserved to the
 * given resource copier, and non-directories to the given file copier.
 */
private DirectoryFilter writeDirectories(ClassPool       programClassPool,
                                         DataEntryReader directoryCopier,
                                         DataEntryReader fileCopier)
{
    DataEntryReader directoryRewriter = null;

    // Wrap the directory copier with a filter and a data entry renamer.
    if (configuration.keepDirectories != null)
    {
        StringFunction packagePrefixFunction =
            new MapStringFunction(createPackagePrefixMap(programClassPool));

        directoryRewriter =
            new NameFilteredDataEntryReader(configuration.keepDirectories,
            new RenamedDataEntryReader(packagePrefixFunction,
                                       directoryCopier,
                                       directoryCopier));
    }

    // Filter on directories and files.
    return new DirectoryFilter(directoryRewriter, fileCopier);
}
 
Example 2
Source Project: proguard   Source File: OutputWriter.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a map of old package prefixes to new package prefixes, based on
 * the given class pool.
 */
private static Map createPackagePrefixMap(ClassPool classPool)
{
    Map packagePrefixMap = new HashMap();

    Iterator iterator = classPool.classNames();
    while (iterator.hasNext())
    {
        String className     = (String)iterator.next();
        String packagePrefix = ClassUtil.internalPackagePrefix(className);

        String mappedNewPackagePrefix = (String)packagePrefixMap.get(packagePrefix);
        if (mappedNewPackagePrefix == null ||
            !mappedNewPackagePrefix.equals(packagePrefix))
        {
            String newClassName     = classPool.getClass(className).getName();
            String newPackagePrefix = ClassUtil.internalPackagePrefix(newClassName);

            packagePrefixMap.put(packagePrefix, newPackagePrefix);
        }
    }

    return packagePrefixMap;
}
 
Example 3
public void visitClassPool(ClassPool classPool)
{
    // Visit all classes at least once, until the class visitors stop
    // setting the repeat trigger.
    do
    {
        if (DEBUG)
        {
            System.out.println("RepeatedClassPoolVisitor: new iteration");
        }

        repeatTrigger.reset();

        // Visit over all classes once.
        classPoolVisitor.visitClassPool(classPool);
    }
    while (repeatTrigger.isSet());

    if (DEBUG)
    {
        System.out.println("RepeatedClassPoolVisitor: done iterating");
    }
}
 
Example 4
public KotlinUnsupportedExceptionReplacementSequences(ClassPool programClassPool, ClassPool libraryClassPool)
{
    InstructionSequenceBuilder ____ = new InstructionSequenceBuilder(programClassPool, libraryClassPool);

    SEQUENCES = new Instruction[][][] {
        {
            ____
                .aload(ALOAD_INDEX)
                .ifnull(InstructionSequenceMatcher.Y)
                .new_(NAME_JAVA_LANG_UNSUPPORTED_OP_EXCEPTION)
                .dup()
                .ldc_(CONSTANT_INDEX_1)
                .invokespecial(NAME_JAVA_LANG_UNSUPPORTED_OP_EXCEPTION, "<init>", "(Ljava/lang/String;)V").__(),

            ____
                .aload(ALOAD_INDEX)
                .ifnull(InstructionSequenceMatcher.Y)
                .new_(NAME_JAVA_LANG_UNSUPPORTED_OP_EXCEPTION)
                .dup()
                .invokespecial(NAME_JAVA_LANG_UNSUPPORTED_OP_EXCEPTION, "<init>", "()V").__()
        },
    };

    CONSTANTS = ____.constants();
}
 
Example 5
Source Project: java-n-IDE-for-Android   Source File: Preverifier.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Performs preverification of the given program class pool.
 */
public void execute(ClassPool programClassPool)
{
    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());

    // Preverify all methods.
    ClassVisitor preverifier =
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new CodePreverifier(configuration.microEdition)));

    // In Java Standard Edition, only class files from Java 6 or higher
    // should be preverified.
    if (!configuration.microEdition)
    {
        preverifier =
            new ClassVersionFilter(ClassConstants.INTERNAL_CLASS_VERSION_1_6,
                                   Integer.MAX_VALUE,
                                   preverifier);
    }

    programClassPool.classesAccept(preverifier);
}
 
Example 6
Source Project: java-n-IDE-for-Android   Source File: SubroutineInliner.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Performs subroutine inlining of the given program class pool.
 */
public void execute(ClassPool programClassPool)
{
    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());

    // Inline all subroutines.
    ClassVisitor inliner =
        new AllMethodVisitor(
        new AllAttributeVisitor(
        new CodeSubroutineInliner()));

    // In Java Standard Edition, only class files from Java 6 or higher
    // should be preverified.
    if (!configuration.microEdition)
    {
        inliner =
            new ClassVersionFilter(ClassConstants.INTERNAL_CLASS_VERSION_1_6,
                                   Integer.MAX_VALUE,
                                   inliner);
    }

    programClassPool.classesAccept(inliner);
}
 
Example 7
Source Project: java-n-IDE-for-Android   Source File: OutputWriter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a map of old package prefixes to new package prefixes, based on
 * the given class pool.
 */
private static Map createPackagePrefixMap(ClassPool classPool)
{
    Map packagePrefixMap = new HashMap();

    Iterator iterator = classPool.classNames();
    while (iterator.hasNext())
    {
        String className     = (String)iterator.next();
        String packagePrefix = ClassUtil.internalPackagePrefix(className);

        String mappedNewPackagePrefix = (String)packagePrefixMap.get(packagePrefix);
        if (mappedNewPackagePrefix == null ||
            !mappedNewPackagePrefix.equals(packagePrefix))
        {
            String newClassName     = classPool.getClass(className).getName();
            String newPackagePrefix = ClassUtil.internalPackagePrefix(newClassName);

            packagePrefixMap.put(packagePrefix, newPackagePrefix);
        }
    }

    return packagePrefixMap;
}
 
Example 8
Source Project: proguard   Source File: OutputWriter.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a map of old package prefixes to new package prefixes, based on
 * the given class pool.
 */
private static Map createPackagePrefixMap(ClassPool classPool)
{
    Map packagePrefixMap = new HashMap();

    Iterator iterator = classPool.classNames();
    while (iterator.hasNext())
    {
        String className     = (String)iterator.next();
        String packagePrefix = ClassUtil.internalPackagePrefix(className);

        String mappedNewPackagePrefix = (String)packagePrefixMap.get(packagePrefix);
        if (mappedNewPackagePrefix == null ||
            !mappedNewPackagePrefix.equals(packagePrefix))
        {
            String newClassName     = classPool.getClass(className).getName();
            String newPackagePrefix = ClassUtil.internalPackagePrefix(newClassName);

            packagePrefixMap.put(packagePrefix, newPackagePrefix);
        }
    }

    return packagePrefixMap;
}
 
Example 9
Source Project: bazel   Source File: OutputWriter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a map of old package prefixes to new package prefixes, based on
 * the given class pool.
 */
private static Map createPackagePrefixMap(ClassPool classPool)
{
    Map packagePrefixMap = new HashMap();

    Iterator iterator = classPool.classNames();
    while (iterator.hasNext())
    {
        String className     = (String)iterator.next();
        String packagePrefix = ClassUtil.internalPackagePrefix(className);

        String mappedNewPackagePrefix = (String)packagePrefixMap.get(packagePrefix);
        if (mappedNewPackagePrefix == null ||
            !mappedNewPackagePrefix.equals(packagePrefix))
        {
            String newClassName     = classPool.getClass(className).getName();
            String newPackagePrefix = ClassUtil.internalPackagePrefix(newClassName);

            packagePrefixMap.put(packagePrefix, newPackagePrefix);
        }
    }

    return packagePrefixMap;
}
 
Example 10
Source Project: proguard   Source File: SeedPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints out the seeds for the classes in the given program class pool.
 * @param configuration the configuration containing the keep options.
 * @throws IOException if an IO error occurs while writing the configuration.
 */
public void write(Configuration configuration,
                  ClassPool     programClassPool,
                  ClassPool     libraryClassPool) throws IOException
{
    // Check if we have at least some keep commands.
    if (configuration.keep == null)
    {
        throw new IOException("You have to specify '-keep' options if you want to write out kept elements with '-printseeds'.");
    }

    // Clean up any old processing info.
    programClassPool.classesAccept(new ClassCleaner());
    libraryClassPool.classesAccept(new ClassCleaner());

    // Create a visitor for printing out the seeds. We're  printing out
    // the program elements that are preserved against shrinking,
    // optimization, or obfuscation.
    KeepMarker keepMarker = new KeepMarker();
    ClassPoolVisitor classPoolvisitor =
        new KeepClassSpecificationVisitorFactory(true, true, true)
            .createClassPoolVisitor(configuration.keep,
                                    keepMarker,
                                    keepMarker,
                                    keepMarker,
                                    null);

    // Mark the seeds.
    programClassPool.accept(classPoolvisitor);
    libraryClassPool.accept(classPoolvisitor);

    // Print out the seeds.
    SimpleClassPrinter printer = new SimpleClassPrinter(false, printWriter);
    programClassPool.classesAcceptAlphabetically(
        new MultiClassVisitor(
            new KeptClassFilter(printer),
            new AllMemberVisitor(new KeptMemberFilter(printer))
        ));
}
 
Example 11
Source Project: proguard   Source File: UsageMarker.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marks classes, resources, resource files and native libraries as being
 * used, based on the configuration.
 *
 * @param programClassPool  the program class pool.
 * @param libraryClassPool  the library class pool.
 * @param resourceFilePool  the resource file pool.
 * @param simpleUsageMarker the usage marker for marking any visitor
 *                          accepters.
 */
public void mark(ClassPool         programClassPool,
                 ClassPool         libraryClassPool,
                 ResourceFilePool  resourceFilePool,
                 SimpleUsageMarker simpleUsageMarker)
{
    mark(programClassPool,
         libraryClassPool,
         resourceFilePool,
         simpleUsageMarker,
         new ClassUsageMarker(simpleUsageMarker));
}
 
Example 12
Source Project: proguard   Source File: JSR310Converter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new JSR310Converter instance.
 */
public JSR310Converter(ClassPool          programClassPool,
                       ClassPool          libraryClassPool,
                       WarningPrinter     warningPrinter,
                       ClassVisitor       modifiedClassVisitor,
                       InstructionVisitor extraInstructionVisitor)
{
    super(programClassPool,
          libraryClassPool,
          warningPrinter,
          modifiedClassVisitor,
          extraInstructionVisitor);

    TypeReplacement[] typeReplacements = new TypeReplacement[]
    {
        // java.time package has been added in Java 8
        replace("java/time/**", "org/threeten/bp/<1>"),
    };

    MethodReplacement[] methodReplacements = new MethodReplacement[]
    {
        // all classes in java.time.** are converted to
        // org.threeeten.bp.**.
        replace("java/time/**",        "**",  "**",
                "org/threeten/bp/<1>", "<1>", "<1>"),
    };

    setTypeReplacements(typeReplacements);
    setMethodReplacements(methodReplacements);
}
 
Example 13
Source Project: proguard   Source File: OutputWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a reader that writes all general resource files (manifest,
 * native libraries, text files) with shrunk, optimized, and obfuscated
 * contents to the given writer.
 */
private DataEntryReader adaptResourceFiles(ClassPool       programClassPool,
                                           DataEntryWriter writer)
{
    // Pick a suitable encoding.
    Charset charset = configuration.android ?
        Charset.forName("UTF-8") :
        Charset.defaultCharset();

    // Filter between the various general resource files.
    return
        new NameFilteredDataEntryReader("META-INF/MANIFEST.MF,META-INF/*.SF",
            new ManifestRewriter(programClassPool, charset, writer),
        new DataEntryRewriter(programClassPool, charset, writer));
}
 
Example 14
Source Project: proguard   Source File: Targeter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the target version on classes in the given program class pool.
 */
public void execute(ClassPool programClassPool) throws IOException
{
    Set newerClassVersions = configuration.warn != null ? null : new HashSet();

    programClassPool.classesAccept(new ClassVersionSetter(configuration.targetClassVersion,
                                                          newerClassVersions));

    if (newerClassVersions != null &&
        newerClassVersions.size() > 0)
    {
        System.err.print("Warning: some classes have more recent versions (");

        Iterator iterator = newerClassVersions.iterator();
        while (iterator.hasNext())
        {
            Integer classVersion = (Integer)iterator.next();
            System.err.print(ClassUtil.externalClassVersion(classVersion.intValue()));

            if (iterator.hasNext())
            {
                System.err.print(",");
            }
        }

        System.err.println(")");
        System.err.println("         than the target version ("+ClassUtil.externalClassVersion(configuration.targetClassVersion)+").");

        if (!configuration.ignoreWarnings)
        {
            System.err.println("         If you are sure this is not a problem,");
            System.err.println("         you could try your luck using the '-ignorewarnings' option.");
            throw new IOException("Please correct the above warnings first.");
        }
    }
}
 
Example 15
Source Project: java-n-IDE-for-Android   Source File: SeedPrinter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Prints out the seeds for the classes in the given program class pool.
 * @param configuration the configuration containing the keep options.
 * @throws IOException if an IO error occurs while writing the configuration.
 */
public void write(Configuration configuration,
                  ClassPool programClassPool,
                  ClassPool libraryClassPool) throws IOException
{
    // Check if we have at least some keep commands.
    if (configuration.keep == null)
    {
        throw new IOException("You have to specify '-keep' options for the shrinking step.");
    }

    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());
    libraryClassPool.classesAccept(new ClassCleaner());

    // Create a visitor for printing out the seeds. We're  printing out
    // the program elements that are preserved against shrinking,
    // optimization, or obfuscation.
    KeepMarker keepMarker = new KeepMarker();
    ClassPoolVisitor classPoolvisitor =
        ClassSpecificationVisitorFactory.createClassPoolVisitor(configuration.keep,
                                                                keepMarker,
                                                                keepMarker,
                                                                true,
                                                                true,
                                                                true);
    // Mark the seeds.
    programClassPool.accept(classPoolvisitor);
    libraryClassPool.accept(classPoolvisitor);

    // Print out the seeds.
    SimpleClassPrinter printer = new SimpleClassPrinter(false, ps);
    programClassPool.classesAcceptAlphabetically(new MultiClassVisitor(
        new ClassVisitor[]
        {
            new KeptClassFilter(printer),
            new AllMemberVisitor(new KeptMemberFilter(printer))
        }));
}
 
Example 16
public void visitClassPool(ClassPool classPool)
{
    for (int index = 0; index < classPoolVisitorCount; index++)
    {
        classPoolVisitors[index].visitClassPool(classPool);
    }
}
 
Example 17
/**
 * Creates a new ClassReferenceInitializer that initializes the references
 * of all visited class files, optionally printing warnings if some classes
 * or class members can't be found or if they are in the program class pool.
 */
public ClassReferenceInitializer(ClassPool programClassPool,
                                 ClassPool libraryClassPool,
                                 WarningPrinter missingClassWarningPrinter,
                                 WarningPrinter missingMemberWarningPrinter,
                                 WarningPrinter dependencyWarningPrinter)
{
    this.programClassPool            = programClassPool;
    this.libraryClassPool            = libraryClassPool;
    this.missingClassWarningPrinter  = missingClassWarningPrinter;
    this.missingMemberWarningPrinter = missingMemberWarningPrinter;
    this.dependencyWarningPrinter    = dependencyWarningPrinter;
}
 
Example 18
/**
 * Creates a new DynamicClassReferenceInitializer that optionally prints
 * warnings and notes, with optional class specifications for which never
 * to print notes.
 */
public DynamicClassReferenceInitializer(ClassPool programClassPool,
                                        ClassPool libraryClassPool,
                                        WarningPrinter missingNotePrinter,
                                        WarningPrinter dependencyWarningPrinter,
                                        WarningPrinter notePrinter,
                                        StringMatcher  noteExceptionMatcher)
{
    this.programClassPool         = programClassPool;
    this.libraryClassPool         = libraryClassPool;
    this.missingNotePrinter       = missingNotePrinter;
    this.dependencyWarningPrinter = dependencyWarningPrinter;
    this.notePrinter              = notePrinter;
    this.noteExceptionMatcher     = noteExceptionMatcher;
}
 
Example 19
/**
 * Creates a new ClassSuperHierarchyInitializer that initializes the super
 * hierarchy of all visited class files, optionally printing warnings if
 * some classes can't be found or if they are in the program class pool.
 */
public ClassSuperHierarchyInitializer(ClassPool programClassPool,
                                      ClassPool libraryClassPool,
                                      WarningPrinter missingWarningPrinter,
                                      WarningPrinter dependencyWarningPrinter)
{
    this.programClassPool         = programClassPool;
    this.libraryClassPool         = libraryClassPool;
    this.missingWarningPrinter    = missingWarningPrinter;
    this.dependencyWarningPrinter = dependencyWarningPrinter;
}
 
Example 20
/**
 * Creates a new DynamicMemberReferenceInitializer.
 */
public DynamicMemberReferenceInitializer(ClassPool programClassPool,
                                         ClassPool libraryClassPool,
                                         WarningPrinter notePrinter,
                                         StringMatcher  noteFieldExceptionMatcher,
                                         StringMatcher  noteMethodExceptionMatcher)
{
    this.programClassPool           = programClassPool;
    this.libraryClassPool           = libraryClassPool;
    this.notePrinter                = notePrinter;
    this.noteFieldExceptionMatcher  = noteFieldExceptionMatcher;
    this.noteMethodExceptionMatcher = noteMethodExceptionMatcher;
}
 
Example 21
/**
 * Creates a new StringReferenceInitializer.
 */
public StringReferenceInitializer(ClassPool programClassPool,
                                  ClassPool libraryClassPool)
{
    this.programClassPool = programClassPool;
    this.libraryClassPool = libraryClassPool;
}
 
Example 22
public void visitClassPool(ClassPool classPool)
{
    // Go over all classes and their methods, marking if they have side
    // effects, until no new cases can be found.
    do
    {
        newSideEffectCount = 0;

        // Go over all classes and their methods once.
        classPool.classesAccept(this);
    }
    while (newSideEffectCount > 0);
}
 
Example 23
/**
 * Creates a new FullyQualifiedClassNameChecker.
 */
public FullyQualifiedClassNameChecker(ClassPool programClassPool,
                                      ClassPool libraryClassPool,
                                      WarningPrinter notePrinter)
{
    this.programClassPool = programClassPool;
    this.libraryClassPool = libraryClassPool;
    this.notePrinter      = notePrinter;
}
 
Example 24
Source Project: java-n-IDE-for-Android   Source File: Targeter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the target version on classes in the given program class pool.
 */
public void execute(ClassPool programClassPool) throws IOException
{
    Set newerClassVersions = configuration.warn != null ? null : new HashSet();

    programClassPool.classesAccept(new ClassVersionSetter(configuration.targetClassVersion,
                                                          newerClassVersions));

    if (newerClassVersions != null &&
        newerClassVersions.size() > 0)
    {
        System.err.print("Warning: some classes have more recent versions (");

        Iterator iterator = newerClassVersions.iterator();
        while (iterator.hasNext())
        {
            Integer classVersion = (Integer)iterator.next();
            System.err.print(ClassUtil.externalClassVersion(classVersion.intValue()));

            if (iterator.hasNext())
            {
                System.err.print(",");
            }
        }

        System.err.println(")");
        System.err.println("         than the target version ("+ClassUtil.externalClassVersion(configuration.targetClassVersion)+").");

        if (!configuration.ignoreWarnings)
        {
            System.err.println("         If you are sure this is not a problem,");
            System.err.println("         you could try your luck using the '-ignorewarnings' option.");
            throw new IOException("Please correct the above warnings first.");
        }
    }
}
 
Example 25
/**
 * Creates a new DescriptorKeepChecker.
 */
public DescriptorKeepChecker(ClassPool      programClassPool,
                             ClassPool      libraryClassPool,
                             WarningPrinter notePrinter)
{
    this.programClassPool = programClassPool;
    this.libraryClassPool = libraryClassPool;
    this.notePrinter      = notePrinter;
}
 
Example 26
Source Project: java-n-IDE-for-Android   Source File: ClassObfuscator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ClassObfuscator.
 * @param programClassPool        the class pool in which class names
 *                                have to be unique.
 * @param classNameFactory        the optional class obfuscation dictionary.
 * @param packageNameFactory      the optional package obfuscation
 *                                dictionary.
 * @param useMixedCaseClassNames  specifies whether obfuscated packages and
 *                                classes can get mixed-case names.
 * @param keepPackageNames        the optional filter for which matching
 *                                package names are kept.
 * @param flattenPackageHierarchy the base package if the obfuscated package
 *                                hierarchy is to be flattened.
 * @param repackageClasses        the base package if the obfuscated classes
 *                                are to be repackaged.
 * @param allowAccessModification specifies whether obfuscated classes can
 *                                be freely moved between packages.
 */
public ClassObfuscator(ClassPool programClassPool,
                       DictionaryNameFactory classNameFactory,
                       DictionaryNameFactory packageNameFactory,
                       boolean               useMixedCaseClassNames,
                       List                  keepPackageNames,
                       String                flattenPackageHierarchy,
                       String                repackageClasses,
                       boolean               allowAccessModification)
{
    this.classNameFactory   = classNameFactory;
    this.packageNameFactory = packageNameFactory;

    // First append the package separator if necessary.
    if (flattenPackageHierarchy != null &&
        flattenPackageHierarchy.length() > 0)
    {
        flattenPackageHierarchy += ClassConstants.INTERNAL_PACKAGE_SEPARATOR;
    }

    // First append the package separator if necessary.
    if (repackageClasses != null &&
        repackageClasses.length() > 0)
    {
        repackageClasses += ClassConstants.INTERNAL_PACKAGE_SEPARATOR;
    }

    this.useMixedCaseClassNames  = useMixedCaseClassNames;
    this.keepPackageNamesMatcher = keepPackageNames == null ? null :
        new ListParser(new FileNameParser()).parse(keepPackageNames);
    this.flattenPackageHierarchy = flattenPackageHierarchy;
    this.repackageClasses        = repackageClasses;
    this.allowAccessModification = allowAccessModification;

    // Map the root package onto the root package.
    packagePrefixMap.put("", "");

    // Collect all names that have been taken already.
    programClassPool.classesAccept(new MyKeepCollector());
}
 
Example 27
Source Project: java-n-IDE-for-Android   Source File: DataEntryRewriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new DataEntryRewriter.
 */
public DataEntryRewriter(ClassPool classPool,
                         DataEntryWriter dataEntryWriter)
{
    super(dataEntryWriter);

    this.classPool = classPool;
}
 
Example 28
Source Project: proguard   Source File: SeedPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints out the seeds for the classes in the given program class pool.
 * @param configuration the configuration containing the keep options.
 * @throws IOException if an IO error occurs while writing the configuration.
 */
public void write(Configuration configuration,
                  ClassPool     programClassPool,
                  ClassPool     libraryClassPool) throws IOException
{
    // Check if we have at least some keep commands.
    if (configuration.keep == null)
    {
        throw new IOException("You have to specify '-keep' options for the shrinking step.");
    }

    // Clean up any old visitor info.
    programClassPool.classesAccept(new ClassCleaner());
    libraryClassPool.classesAccept(new ClassCleaner());

    // Create a visitor for printing out the seeds. We're  printing out
    // the program elements that are preserved against shrinking,
    // optimization, or obfuscation.
    KeepMarker keepMarker = new KeepMarker();
    ClassPoolVisitor classPoolvisitor =
        ClassSpecificationVisitorFactory.createClassPoolVisitor(configuration.keep,
                                                                keepMarker,
                                                                keepMarker,
                                                                true,
                                                                true,
                                                                true);
    // Mark the seeds.
    programClassPool.accept(classPoolvisitor);
    libraryClassPool.accept(classPoolvisitor);

    // Print out the seeds.
    SimpleClassPrinter printer = new SimpleClassPrinter(false, ps);
    programClassPool.classesAcceptAlphabetically(new MultiClassVisitor(
        new ClassVisitor[]
        {
            new KeptClassFilter(printer),
            new AllMemberVisitor(new KeptMemberFilter(printer))
        }));
}
 
Example 29
Source Project: proguard   Source File: OutputWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes the given class pool to class files, based on the current
 * configuration.
 */
public void execute(ClassPool programClassPool) throws IOException
{
    ClassPath programJars = configuration.programJars;

    int firstInputIndex = 0;
    int lastInputIndex  = 0;

    // Go over all program class path entries.
    for (int index = 0; index < programJars.size(); index++)
    {
        // Is it an input entry?
        ClassPathEntry entry = programJars.get(index);
        if (!entry.isOutput())
        {
            // Remember the index of the last input entry.
            lastInputIndex = index;
        }
        else
        {
            // Check if this the last output entry in a series.
            int nextIndex = index + 1;
            if (nextIndex == programJars.size() ||
                !programJars.get(nextIndex).isOutput())
            {
                // Write the processed input entries to the output entries.
                writeOutput(programClassPool,
                            programJars,
                            firstInputIndex,
                            lastInputIndex + 1,
                            nextIndex);

                // Start with the next series of input entries.
                firstInputIndex = nextIndex;
            }
        }
    }
}
 
Example 30
public void visitClassPool(ClassPool classPool)
{
    for (int index = 0; index < classPoolVisitorCount; index++)
    {
        classPoolVisitors[index].visitClassPool(classPool);
    }
}