mirror of
https://github.com/Guardsquare/proguard.git
synced 2026-03-13 09:50:34 +08:00
Compare commits
1 Commits
record-att
...
permitted-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ff5df070c |
@@ -102,6 +102,12 @@ implements AttributeVisitor
|
||||
}
|
||||
|
||||
|
||||
public void visitPermittedSubclassesAttribute(Clazz clazz, PermittedSubclassesAttribute permittedSubclassesAttribute)
|
||||
{
|
||||
attributeVisitor.visitPermittedSubclassesAttribute(clazz, permittedSubclassesAttribute);
|
||||
}
|
||||
|
||||
|
||||
public void visitModuleAttribute(Clazz clazz, ModuleAttribute moduleAttribute)
|
||||
{
|
||||
attributeVisitor.visitModuleAttribute(clazz, moduleAttribute);
|
||||
|
||||
@@ -54,7 +54,7 @@ implements ClassVisitor,
|
||||
|
||||
private int[] constantIndexMap = new int[ClassEstimates.TYPICAL_CONSTANT_POOL_SIZE];
|
||||
private int[] bootstrapMethodIndexMap = new int[ClassEstimates.TYPICAL_CONSTANT_POOL_SIZE];
|
||||
private final MyNestmemberShrinker nestMemberShrinker = new MyNestmemberShrinker();
|
||||
private final MyAttributeShrinker attributeShrinker = new MyAttributeShrinker();
|
||||
private final ConstantPoolRemapper constantPoolRemapper = new ConstantPoolRemapper();
|
||||
private final BootstrapMethodRemapper bootstrapMethodRemapper = new BootstrapMethodRemapper();
|
||||
private final MySignatureCleaner signatureCleaner = new MySignatureCleaner();
|
||||
@@ -127,8 +127,8 @@ implements ClassVisitor,
|
||||
.visitProgramClass(programClass);
|
||||
}
|
||||
|
||||
// Shrink the arrays for nest members.
|
||||
programClass.attributesAccept(nestMemberShrinker);
|
||||
// Shrink the arrays for nest members and permitted subclasses.
|
||||
programClass.attributesAccept(attributeShrinker);
|
||||
|
||||
// Shrink the constant pool, also setting up an index map.
|
||||
int newConstantPoolCount =
|
||||
@@ -361,9 +361,10 @@ implements ClassVisitor,
|
||||
|
||||
/**
|
||||
* This AttributeVisitor shrinks the nest members in the nest member
|
||||
* attributes and the permitted subclasses in the permitted subclasses
|
||||
* attributes that it visits.
|
||||
*/
|
||||
private class MyNestmemberShrinker
|
||||
private class MyAttributeShrinker
|
||||
implements AttributeVisitor
|
||||
{
|
||||
public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
|
||||
@@ -378,6 +379,17 @@ implements ClassVisitor,
|
||||
nestMembersAttribute.u2classes,
|
||||
nestMembersAttribute.u2classesCount);
|
||||
}
|
||||
|
||||
|
||||
public void visitPermittedSubclassesAttribute(Clazz clazz, PermittedSubclassesAttribute permittedSubclassesAttribute)
|
||||
{
|
||||
// Shrink the array of nest member indices.
|
||||
// We must do this before the corresponding constants are remapped.
|
||||
permittedSubclassesAttribute.u2classesCount =
|
||||
shrinkConstantIndexArray(((ProgramClass)clazz).constantPool,
|
||||
permittedSubclassesAttribute.u2classes,
|
||||
permittedSubclassesAttribute.u2classesCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -949,6 +949,19 @@ implements ClassVisitor,
|
||||
}
|
||||
|
||||
|
||||
public void visitPermittedSubclassesAttribute(Clazz clazz, PermittedSubclassesAttribute permittedSubclassesAttribute)
|
||||
{
|
||||
// Don't mark the attribute and its contents yet. We may mark it later,
|
||||
// in NestUsageMarker.
|
||||
//markAsUsed(permittedSubclassesAttribute);
|
||||
|
||||
//markConstant(clazz, permittedSubclassesAttribute.u2attributeNameIndex);
|
||||
|
||||
// Mark the nest member entries.
|
||||
//permittedSubclassesAttribute.memberClassConstantsAccept(clazz, this);
|
||||
}
|
||||
|
||||
|
||||
public void visitModuleAttribute(Clazz clazz, ModuleAttribute moduleAttribute)
|
||||
{
|
||||
markAsUsed(moduleAttribute);
|
||||
|
||||
@@ -28,8 +28,8 @@ import proguard.classfile.constant.visitor.ConstantVisitor;
|
||||
import proguard.classfile.visitor.ClassVisitor;
|
||||
|
||||
/**
|
||||
* This AttributeVisitor marks all necessary nest host attributes and nest
|
||||
* members attributes that it visits.
|
||||
* This AttributeVisitor marks all necessary nest host attributes, nest
|
||||
* members attributes, and permitted subclasses attributes that it visits.
|
||||
*
|
||||
* @see UsageMarker
|
||||
*
|
||||
@@ -82,14 +82,14 @@ implements AttributeVisitor,
|
||||
|
||||
public void visitNestMembersAttribute(Clazz clazz, NestMembersAttribute nestMembersAttribute)
|
||||
{
|
||||
// Mark the necessary inner classes information.
|
||||
// Mark the necessary nest member information.
|
||||
attributeUsed = false;
|
||||
nestMembersAttribute.memberClassConstantsAccept(clazz, this);
|
||||
|
||||
if (attributeUsed)
|
||||
{
|
||||
// We got a positive used flag, so the nest members class is being used.
|
||||
// Mark this attribute as being used as well.
|
||||
// We got a positive used flag, so at least one of the nest members
|
||||
// is being used. Mark this attribute as being used as well.
|
||||
classUsageMarker.markAsUsed(nestMembersAttribute);
|
||||
|
||||
markConstant(clazz, nestMembersAttribute.u2attributeNameIndex);
|
||||
@@ -97,6 +97,24 @@ implements AttributeVisitor,
|
||||
}
|
||||
|
||||
|
||||
public void visitPermittedSubclassesAttribute(Clazz clazz, PermittedSubclassesAttribute permittedSubclassesAttribute)
|
||||
{
|
||||
// Mark the necessary permitted subclasses information.
|
||||
attributeUsed = false;
|
||||
permittedSubclassesAttribute.permittedSubclassConstantsAccept(clazz, this);
|
||||
|
||||
if (attributeUsed)
|
||||
{
|
||||
// We got a positive used flag, so at least one of the permitted
|
||||
// subclasses class is being used. Mark this attribute as being
|
||||
// used as well.
|
||||
classUsageMarker.markAsUsed(permittedSubclassesAttribute);
|
||||
|
||||
markConstant(clazz, permittedSubclassesAttribute.u2attributeNameIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Implementations for ConstantVisitor.
|
||||
|
||||
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
|
||||
|
||||
@@ -69,15 +69,16 @@ Yes, you can. **ProGuard** itself is distributed under the GPL, but this
|
||||
doesn't affect the programs that you process. Your code remains yours, and its
|
||||
license can remain the same.
|
||||
|
||||
## Does ProGuard work with Java 2, 5,..., 14? {: #jdk1.4}
|
||||
## Does ProGuard work with Java 2, 5,..., 15? {: #jdk1.4}
|
||||
|
||||
Yes, **ProGuard** supports all JDKs from 1.1 up to and including 14. Java 2
|
||||
Yes, **ProGuard** supports all JDKs from 1.1 up to and including 15. Java 2
|
||||
introduced some small differences in the class file format. Java 5 added
|
||||
attributes for generics and for annotations. Java 6 introduced optional
|
||||
preverification attributes. Java 7 made preverification obligatory and
|
||||
introduced support for dynamic languages. Java 8 added more attributes and
|
||||
default methods. Java 9 added support for modules. Java 11 added dynamic
|
||||
constants and nest-based access control. Java 14 added records.
|
||||
constants and nest-based access control. Java 14 added records. Java 15
|
||||
added sealed classes.
|
||||
**ProGuard** handles all versions correctly.
|
||||
|
||||
## Does ProGuard work with Java Micro Edition? {: #jme}
|
||||
|
||||
@@ -47,7 +47,7 @@ attributes. You can keep them with the
|
||||
: Specifies the name of the source directory from which the class file was
|
||||
compiled.
|
||||
|
||||
`Record`
|
||||
`Record` <div>(Java 14 or higher)</div>
|
||||
: Specifies the components of a record class. Code may access this information
|
||||
by reflection.
|
||||
|
||||
@@ -59,6 +59,10 @@ attributes. You can keep them with the
|
||||
referenced in a compiled library. Code may access this information by
|
||||
reflection, for instance to derive the simple name of the class.
|
||||
|
||||
`PermittedSubclasses` <div>(Java 15 or higher)</div>
|
||||
: Specifies the allowed extensions or implementations of sealed classes or
|
||||
interfaces.
|
||||
|
||||
`EnclosingMethod`<div>(Java 5 or higher)</div>
|
||||
: Specifies the method in which the class was defined. Compilers may need this
|
||||
information to find classes referenced in a compiled library. Code may
|
||||
|
||||
@@ -347,8 +347,9 @@ still be used as such, for developing code based on its public API.
|
||||
|
||||
-keepparameternames
|
||||
-renamesourcefileattribute SourceFile
|
||||
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
|
||||
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
|
||||
-keepattributes Signature,Exceptions,*Annotation*,
|
||||
InnerClasses,PermittedSubclasses,EnclosingMethod,
|
||||
Deprecated,SourceFile,LineNumberTable
|
||||
|
||||
-keepclasseswithmembernames,includedescriptorclasses class * {
|
||||
native <methods>;
|
||||
@@ -373,16 +374,26 @@ access in the library. Only if there are any other non-public classes or
|
||||
methods that are invoked dynamically, they should be specified using
|
||||
additional [`-keep`](usage.md#keep) options.
|
||||
|
||||
The "Signature" attribute is required to be able to access generic types.
|
||||
|
||||
The "Exceptions" attribute has to be preserved, so the compiler knows
|
||||
which exceptions methods may throw.
|
||||
|
||||
The various "\*Annotations\*" attributes contain any annotations, which
|
||||
developers might need to access through reflection.
|
||||
|
||||
The "InnerClasses" attribute (or more precisely, its source name part) has to
|
||||
be preserved too, for any inner classes that can be referenced from outside
|
||||
the library. The `javac` compiler would be unable to find the inner classes
|
||||
otherwise.
|
||||
|
||||
The "Signature" attribute is required to be able to access generic types when
|
||||
compiling in JDK 5.0 and higher.
|
||||
The "PermittedSubclasses" attribute defines sealed classes, which developers
|
||||
can't extend further.
|
||||
|
||||
The "EnclosingMethod" attribute marks classes that are defined inside methods.
|
||||
|
||||
The "Deprecated" attribute marks any deprecated classes, fields, or
|
||||
methods, which may be useful for developers to know.
|
||||
|
||||
The [`-keepparameternames`](usage.md#keepparameternames) option keeps the
|
||||
parameter names in the "LocalVariableTable" and "LocalVariableTypeTable"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
| Version| Issue | Module | Explanation
|
||||
|--------|----------|----------|----------------------------------
|
||||
| 7.1.x | PGD-0064 | CORE | Added support for Java 14 and 15.
|
||||
| 7.1.x | PGD-0064 | CORE | Added support for sealed classes (permitted subclasses attributes).
|
||||
| 7.1.x | PGD-0064 | CORE | Added support for record attributes.
|
||||
| 7.1.x | DGD-2390 | CORE | Fixed storage and alignment of uncompressed zip entries.
|
||||
| 7.1.x | DGD-2338 | CORE | Fixed processing of constant boolean arrays.
|
||||
|
||||
@@ -21,13 +21,14 @@
|
||||
|
||||
<!-- Keep some useful attributes. -->
|
||||
|
||||
<keepattribute name="Signature" />
|
||||
<keepattribute name="Exceptions" />
|
||||
<keepattribute name="InnerClasses" />
|
||||
<keepattribute name="Signature" />
|
||||
<keepattribute name="PermittedSubclasses" />
|
||||
<keepattribute name="EnclosingMethod" />
|
||||
<keepattribute name="Deprecated" />
|
||||
<keepattribute name="SourceFile" />
|
||||
<keepattribute name="LineNumberTable" />
|
||||
<keepattribute name="EnclosingMethod" />
|
||||
|
||||
<!-- Preserve all public classes, and their public and protected fields
|
||||
and methods. -->
|
||||
|
||||
@@ -53,7 +53,7 @@ task ('proguard', type: proguard.gradle.ProGuardTask) {
|
||||
printmapping 'out.map'
|
||||
keepparameternames
|
||||
renamesourcefileattribute 'SourceFile'
|
||||
keepattributes 'Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod'
|
||||
keepattributes 'Signature,Exceptions,InnerClasses,PermittedSubclasses,EnclosingMethod,Deprecated,SourceFile,LineNumberTable'
|
||||
|
||||
// Preserve all annotations.
|
||||
|
||||
|
||||
@@ -28,8 +28,9 @@
|
||||
-printmapping out.map
|
||||
-keepparameternames
|
||||
-renamesourcefileattribute SourceFile
|
||||
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
|
||||
SourceFile,LineNumberTable,EnclosingMethod
|
||||
-keepattributes Signature,Exceptions,
|
||||
InnerClasses,PermittedSubclasses,EnclosingMethod,
|
||||
Deprecated,SourceFile,LineNumberTable
|
||||
|
||||
# Preserve all annotations.
|
||||
|
||||
@@ -78,7 +79,7 @@
|
||||
java.lang.Object readResolve();
|
||||
}
|
||||
|
||||
# Your library may contain more items that need to be preserved;
|
||||
# Your library may contain more items that need to be preserved;
|
||||
# typically classes that are dynamically created using Class.forName:
|
||||
|
||||
# -keep public class com.example.MyClass
|
||||
|
||||
Reference in New Issue
Block a user