proguard.classfile.ClassPool Java Examples

The following examples show how to use proguard.classfile.ClassPool. 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 File: OutputWriter.java    From java-n-IDE-for-Android with 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 #2
Source File: OutputWriter.java    From bazel with 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 #3
Source File: SubroutineInliner.java    From java-n-IDE-for-Android with 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 #4
Source File: Preverifier.java    From java-n-IDE-for-Android with 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 #5
Source File: OutputWriter.java    From proguard with 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 #6
Source File: OutputWriter.java    From proguard with 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 #7
Source File: RepeatedClassPoolVisitor.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
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 #8
Source File: OutputWriter.java    From proguard with 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 File: KotlinUnsupportedExceptionReplacementSequences.java    From proguard with GNU General Public License v2.0 6 votes vote down vote up
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 #10
Source File: Targeter.java    From java-n-IDE-for-Android with 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 #11
Source File: DataEntryRewriter.java    From java-n-IDE-for-Android with 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 #12
Source File: ClassObfuscator.java    From java-n-IDE-for-Android with 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 #13
Source File: DescriptorKeepChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new DescriptorKeepChecker.
 */
public DescriptorKeepChecker(ClassPool      programClassPool,
                             ClassPool      libraryClassPool,
                             WarningPrinter notePrinter)
{
    this.programClassPool = programClassPool;
    this.libraryClassPool = libraryClassPool;
    this.notePrinter      = notePrinter;
}
 
Example #14
Source File: OutputWriter.java    From proguard with 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 #15
Source File: FullyQualifiedClassNameChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new FullyQualifiedClassNameChecker.
 */
public FullyQualifiedClassNameChecker(ClassPool programClassPool,
                                      ClassPool libraryClassPool,
                                      WarningPrinter notePrinter)
{
    this.programClassPool = programClassPool;
    this.libraryClassPool = libraryClassPool;
    this.notePrinter      = notePrinter;
}
 
Example #16
Source File: SideEffectMethodMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
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 #17
Source File: StringReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new StringReferenceInitializer.
 */
public StringReferenceInitializer(ClassPool programClassPool,
                                  ClassPool libraryClassPool)
{
    this.programClassPool = programClassPool;
    this.libraryClassPool = libraryClassPool;
}
 
Example #18
Source File: DynamicMemberReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #19
Source File: SeedPrinter.java    From proguard with 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 #20
Source File: UsageMarker.java    From proguard with 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 #21
Source File: MultiClassPoolVisitor.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitClassPool(ClassPool classPool)
{
    for (int index = 0; index < classPoolVisitorCount; index++)
    {
        classPoolVisitors[index].visitClassPool(classPool);
    }
}
 
Example #22
Source File: Targeter.java    From proguard with 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 #23
Source File: SeedPrinter.java    From bazel with 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 #24
Source File: OutputWriter.java    From bazel with Apache License 2.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 #25
Source File: MultiClassPoolVisitor.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitClassPool(ClassPool classPool)
{
    for (int index = 0; index < classPoolVisitorCount; index++)
    {
        classPoolVisitors[index].visitClassPool(classPool);
    }
}
 
Example #26
Source File: Targeter.java    From bazel with 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 #27
Source File: DynamicClassReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #28
Source File: SeedPrinter.java    From proguard with 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 #29
Source File: JSR310Converter.java    From proguard with 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 #30
Source File: OutputWriter.java    From proguard with 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));
}