Java Code Examples for proguard.classfile.ClassConstants#CLASS_FILE_EXTENSION

The following examples show how to use proguard.classfile.ClassConstants#CLASS_FILE_EXTENSION . 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: ClassRewriter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void read(DataEntry dataEntry) throws IOException
{
    String inputName = dataEntry.getName();
    String className = inputName.substring(0, inputName.length() - ClassConstants.CLASS_FILE_EXTENSION.length());

    // Find the modified class corrsponding to the input entry.
    ProgramClass programClass = (ProgramClass)classPool.getClass(className);
    if (programClass != null)
    {
        // Rename the data entry if necessary.
        String newClassName = programClass.getName();
        if (!className.equals(newClassName))
        {
            dataEntry = new RenamedDataEntry(dataEntry, newClassName + ClassConstants.CLASS_FILE_EXTENSION);
        }

        // Get the output entry corresponding to this input entry.
        OutputStream outputStream = dataEntryWriter.getOutputStream(dataEntry);
        if (outputStream != null)
        {
            // Write the class to the output entry.
            DataOutputStream classOutputStream = new DataOutputStream(outputStream);

            new ProgramClassWriter(classOutputStream).visitProgramClass(programClass);

            classOutputStream.flush();
        }
    }
}
 
Example 2
Source File: ClassFilter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ClassFilter that delegates to either of the two given
 * readers.
 */
public ClassFilter(DataEntryReader classReader,
                   DataEntryReader dataEntryReader)
{
    super(new DataEntryNameFilter(
          new ExtensionMatcher(ClassConstants.CLASS_FILE_EXTENSION)),
          classReader,
          dataEntryReader);
}
 
Example 3
Source File: ClassFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new ClassFilter that delegates to either of the two given
 * readers.
 */
public ClassFilter(DataEntryReader classReader,
                   DataEntryReader dataEntryReader)
{
    super(new DataEntryNameFilter(
          new ExtensionMatcher(ClassConstants.CLASS_FILE_EXTENSION)),
          classReader,
          dataEntryReader);
}
 
Example 4
Source File: ClassFilter.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ClassFilter that delegates to either of the two given
 * readers.
 */
public ClassFilter(DataEntryReader classReader,
                   DataEntryReader dataEntryReader)
{
    super(new DataEntryNameFilter(
          new ExtensionMatcher(ClassConstants.CLASS_FILE_EXTENSION)),
          classReader,
          dataEntryReader);
}
 
Example 5
Source File: DataEntryReaderFactory.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Wraps the given DataEntryReader in a JarReader, filtering it if
 * necessary.
 * @param reader             the data entry reader that can read the
 *                           entries contained in the jar file.
 * @param stripClassesPrefix specifies whether to strip the ""classes/"
 *                           prefix from contained .class data entries.
 *@param stripJmodHeader     specifies whether to strip the jmod magic
 *                           bytes from the zip.
 * @param isJar              specifies whether the data entries should
 *                           always be unzipped.
 * @param jarFilter          otherwise, an optional filter on the data
 *                           entry names.
 * @param jarExtension       also otherwise, a required data entry name
 *                           extension.
 * @return a DataEntryReader for reading the entries of jar file data
 *         entries.
 */
private DataEntryReader wrapInJarReader(DataEntryReader reader,
                                        boolean         stripClassesPrefix,
                                        boolean         stripJmodHeader,
                                        boolean         isJar,
                                        List            jarFilter,
                                        String          jarExtension)
{
    if (stripClassesPrefix)
    {
        reader = new FilteredDataEntryReader(
            new DataEntryNameFilter(new ExtensionMatcher(ClassConstants.CLASS_FILE_EXTENSION)),
            new PrefixStrippingDataEntryReader(CLASS_FILE_PREFIX, reader),
            reader);
    }

    // Unzip any jars, if necessary.
    DataEntryReader jarReader = new JarReader(stripJmodHeader, reader);

    if (isJar)
    {
        // Always unzip.
        return jarReader;
    }
    else
    {
        // Add a filter, if specified.
        if (jarFilter != null)
        {
            jarReader = new FilteredDataEntryReader(
                        new DataEntryNameFilter(
                        new ListParser(new FileNameParser()).parse(jarFilter)),
                            jarReader);
        }

        StringMatcher jarMatcher =
            new ExtensionMatcher(jarExtension);

        // Don't unzip archives in Android assets directories.
        if (android)
        {
            jarMatcher =
                new AndMatcher(new NotMatcher(
                               new FixedStringMatcher("assets/",
                               new ConstantMatcher(true))),

                               jarMatcher);
        }

        // Only unzip the right type of jars.
        return new FilteredDataEntryReader(
               new DataEntryNameFilter(jarMatcher),
                   jarReader,
                   reader);
    }
}