Skip to content

Commit

Permalink
Renamed option -adaptkotlinmetadata to -keepkotlinmetadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLafortune committed Jun 5, 2020
1 parent ded638f commit 3dc5906
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 40 deletions.
6 changes: 3 additions & 3 deletions ant/src/proguard/ant/ProGuardTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ public void setDump(File dump)
}


public void setAddConfigurationDebugging(boolean addConfigurationDebugging)
public void setAddconfigurationdebugging(boolean addConfigurationDebugging)
{
configuration.addConfigurationDebugging = addConfigurationDebugging;
}

public void setAdaptKotlinMetadata(boolean adaptKotlinMetadata)
public void setKeepkotlinmetadata(boolean keepKotlinMetadata)
{
configuration.adaptKotlinMetadata = adaptKotlinMetadata;
configuration.keepKotlinMetadata = keepKotlinMetadata;
}


Expand Down
2 changes: 1 addition & 1 deletion base/src/proguard/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public class Configuration
/**
* Specifies whether to process Kotlin metadata or not.
*/
public boolean adaptKotlinMetadata = false;
public boolean keepKotlinMetadata = false;

/**
* Enables of disables the Kotlin asserter. This is a hidden option,
Expand Down
2 changes: 1 addition & 1 deletion base/src/proguard/ConfigurationConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class ConfigurationConstants
public static final String ZIP_ALIGN_OPTION = "-zipalign";
public static final String FORCE_PROCESSING_OPTION = "-forceprocessing";

public static final String ADAPT_KOTLIN_METADATA = "-adaptkotlinmetadata";
public static final String KEEP_KOTLIN_METADATA = "-keepkotlinmetadata";

public static final String ANY_FILE_KEYWORD = "**";

Expand Down
2 changes: 1 addition & 1 deletion base/src/proguard/ConfigurationParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ else if (ConfigurationConstants.REPACKAGE_CLASSES_OPTION
else if (ConfigurationConstants.ADAPT_CLASS_STRINGS_OPTION .startsWith(nextWord)) configuration.adaptClassStrings = parseCommaSeparatedList("class name", true, true, false, false, true, false, false, true, false, configuration.adaptClassStrings);
else if (ConfigurationConstants.ADAPT_RESOURCE_FILE_NAMES_OPTION .startsWith(nextWord)) configuration.adaptResourceFileNames = parseCommaSeparatedList("resource file name", true, true, false, true, false, true, false, false, false, configuration.adaptResourceFileNames);
else if (ConfigurationConstants.ADAPT_RESOURCE_FILE_CONTENTS_OPTION .startsWith(nextWord)) configuration.adaptResourceFileContents = parseCommaSeparatedList("resource file name", true, true, false, true, false, true, false, false, false, configuration.adaptResourceFileContents);
else if (ConfigurationConstants.ADAPT_KOTLIN_METADATA .startsWith(nextWord)) configuration.adaptKotlinMetadata = parseNoArgument(true);
else if (ConfigurationConstants.KEEP_KOTLIN_METADATA .startsWith(nextWord)) configuration.keepKotlinMetadata = parseNoArgument(true);

else if (ConfigurationConstants.DONT_PREVERIFY_OPTION .startsWith(nextWord)) configuration.preverify = parseNoArgument(false);
else if (ConfigurationConstants.MICRO_EDITION_OPTION .startsWith(nextWord)) configuration.microEdition = parseNoArgument(true);
Expand Down
2 changes: 1 addition & 1 deletion base/src/proguard/ConfigurationWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void write(Configuration configuration) throws IOException
writeOption(ConfigurationConstants.ADAPT_CLASS_STRINGS_OPTION, configuration.adaptClassStrings, true);
writeOption(ConfigurationConstants.ADAPT_RESOURCE_FILE_NAMES_OPTION, configuration.adaptResourceFileNames);
writeOption(ConfigurationConstants.ADAPT_RESOURCE_FILE_CONTENTS_OPTION, configuration.adaptResourceFileContents);
writeOption(ConfigurationConstants.ADAPT_KOTLIN_METADATA, configuration.adaptKotlinMetadata);
writeOption(ConfigurationConstants.KEEP_KOTLIN_METADATA, configuration.keepKotlinMetadata);

writeOption(ConfigurationConstants.DONT_PREVERIFY_OPTION, !configuration.preverify);
writeOption(ConfigurationConstants.MICRO_EDITION_OPTION, configuration.microEdition);
Expand Down
6 changes: 3 additions & 3 deletions base/src/proguard/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void execute(ClassPool programClassPool,
WarningPrinter kotlinInitializationWarningPrinter = new WarningPrinter(err, configuration.warn);

// Initialize the Kotlin Metadata for Kotlin classes.
if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
ClassVisitor kotlinMetadataInitializer =
new AllAttributeVisitor(
Expand Down Expand Up @@ -319,7 +319,7 @@ public void execute(ClassPool programClassPool,
programClassPool.accept(classSubHierarchyInitializer);
libraryClassPool.accept(classSubHierarchyInitializer);

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
resourceFilePool.resourceFilesAccept(new KotlinModuleReferenceInitializer(programClassPool, libraryClassPool));

Expand Down Expand Up @@ -542,7 +542,7 @@ public void execute(ClassPool programClassPool,
err.println(" (https://www.guardsquare.com/proguard/manual/troubleshooting#unresolvedlibraryclassmember)");
}

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
int kotlinInitializationWarningCount = kotlinInitializationWarningPrinter.getWarningCount();

Expand Down
2 changes: 1 addition & 1 deletion base/src/proguard/InputReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void execute(ClassPool programClassPool,
new ResourceFileDataEntryReader(resourceFilePoolFiller,
adaptedDataEntryFilter);

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
resourceReader =
new NameFilteredDataEntryReader(KotlinConstants.MODULE.FILE_EXPRESSION,
Expand Down
2 changes: 1 addition & 1 deletion base/src/proguard/OutputWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void writeOutput(DataEntryWriterFactory dataEntryWriterFactory,
resourceWriter);
}

if (configuration.adaptKotlinMetadata &&
if (configuration.keepKotlinMetadata &&
(configuration.shrink ||
configuration.obfuscate))
{
Expand Down
8 changes: 4 additions & 4 deletions base/src/proguard/ProGuard.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void execute() throws IOException
configuration.obfuscate ||
configuration.preverify ||
configuration.addConfigurationDebugging ||
configuration.adaptKotlinMetadata)
configuration.keepKotlinMetadata)
{
initialize();
mark();
Expand Down Expand Up @@ -196,9 +196,9 @@ public void execute() throws IOException
obfuscate();
}

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
adaptKotlinMetadata();
keepKotlinMetadata();
}

if (configuration.optimize ||
Expand Down Expand Up @@ -364,7 +364,7 @@ private void addConfigurationLogging()
/**
* Adapts Kotlin Metadata annotations.
*/
private void adaptKotlinMetadata()
private void keepKotlinMetadata()
{
if (configuration.verbose)
{
Expand Down
22 changes: 11 additions & 11 deletions base/src/proguard/obfuscate/Obfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void execute(ClassPool programClassPool,
new MemberAccessFilter(AccessConstants.ABSTRACT, 0,
nameMarker))))))));

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
programClassPool.classesAccept(
// Keep Kotlin default implementations class where the user had already kept the interface.
Expand Down Expand Up @@ -182,15 +182,15 @@ public void execute(ClassPool programClassPool,
new AllAttributeVisitor(true,
new ParameterNameMarker(attributeUsageMarker)))));

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
programClassPool.classesAccept(
new ReferencedKotlinMetadataVisitor(
new KotlinValueParameterUsageMarker()));
}
}

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
programClassPool.classesAccept(
new ReferencedKotlinMetadataVisitor(
Expand All @@ -214,7 +214,7 @@ public void execute(ClassPool programClassPool,
// configuration may rely on annotations.
programClassPool.classesAccept(new AttributeShrinker());

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
programClassPool.classesAccept(
new ReferencedKotlinMetadataVisitor(
Expand Down Expand Up @@ -287,7 +287,7 @@ public void execute(ClassPool programClassPool,
configuration.flattenPackageHierarchy,
configuration.repackageClasses,
configuration.allowAccessModification,
configuration.adaptKotlinMetadata));
configuration.keepKotlinMetadata));

// Come up with new names for all class members.
NameFactory nameFactory = new SimpleNameFactory();
Expand Down Expand Up @@ -512,7 +512,7 @@ public void execute(ClassPool programClassPool,
}
}

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
programClassPool.classesAccept(
new MultiClassVisitor(
Expand Down Expand Up @@ -605,7 +605,7 @@ public void execute(ClassPool programClassPool,
obfuscatedFieldCounter))
);

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
// Ensure multi-file parts and facades are in the same package.
programClassPool.classesAccept(
Expand All @@ -617,7 +617,7 @@ public void execute(ClassPool programClassPool,
programClassPool.classesAccept(classRenamer);
libraryClassPool.classesAccept(classRenamer);

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
// Apply new names to Kotlin properties.
programClassPool.classesAccept(
Expand All @@ -631,7 +631,7 @@ public void execute(ClassPool programClassPool,
libraryClassPool.classesAccept(new ClassReferenceFixer(false));
programClassPool.classesAccept(new MemberReferenceFixer(configuration.android));

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
programClassPool.classesAccept(
new ReferencedKotlinMetadataVisitor(
Expand Down Expand Up @@ -692,15 +692,15 @@ public void execute(ClassPool programClassPool,
System.out.println(" Number of obfuscated methods: " + obfuscatedMethodCounter.getCount());
}

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
// Fix the Kotlin modules so the filename matches and the class names match.
resourceFilePool.resourceFilesAccept(
new ResourceFileProcessingFlagFilter(0, ProcessingFlags.DONT_PROCESS_KOTLIN_MODULE,
new KotlinModuleFixer()));
}

if (configuration.adaptKotlinMetadata && configuration.enableKotlinAsserter)
if (configuration.keepKotlinMetadata && configuration.enableKotlinAsserter)
{
new KotlinMetadataAsserter().execute(programClassPool, libraryClassPool, resourceFilePool, warningPrinter);
}
Expand Down
2 changes: 1 addition & 1 deletion base/src/proguard/shrink/Shrinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public ClassPool execute(ClassPool programClassPool,
new UsedClassFilter(simpleUsageMarker,
new ClassShrinker(simpleUsageMarker)));

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
// Clean up Kotlin metadata for unused classes/members.
newProgramClassPool.classesAccept(
Expand Down
4 changes: 2 additions & 2 deletions base/src/proguard/shrink/UsageMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void mark(ClassPool programClassPool,
));

// Mark the elements of Kotlin metadata that need to be kept.
if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
// Mark Kotlin things that refer to classes that have been marked as being kept now.
programClassPool.classesAccept(
Expand All @@ -129,7 +129,7 @@ public void mark(ClassPool programClassPool,
// Mark interfaces that have to be kept.
programClassPool.classesAccept(new InterfaceUsageMarker(classUsageMarker));

if (configuration.adaptKotlinMetadata)
if (configuration.keepKotlinMetadata)
{
// Mark the used Kotlin modules.
resourceFilePool.resourceFilesAccept(
Expand Down
10 changes: 5 additions & 5 deletions docs/md/manual/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Kotlin compiler injects code and metadata into the classes that it generates

In most cases, you do not need to keep Kotlin metadata for app projects - therefore, no configuration changes are necessary and the Kotlin metadata can be safely removed.

ProGuard will only keep the Kotlin metadata of a class if you explicitly keep that class or one of its members and you add `-adaptkotlinmetadata` option to your configuration.
ProGuard will only keep the Kotlin metadata of a class if you explicitly keep that class or one of its members and you add `-keepkotlinmetadata` option to your configuration.

For example, if you have the following keep rule for a Kotlin class named `com.example.KotlinExample`, by default the class will be kept but its metadata will not:

Expand All @@ -15,11 +15,11 @@ For example, if you have the following keep rule for a Kotlin class named `com.e
-keep class com.example.KotlinExample
```

You can add `-adaptkotlinmetadata` to your configuration to instruct ProGuard to keep and adapt Kotlin metadata:
You can add `-keepkotlinmetadata` to your configuration to instruct ProGuard to keep and adapt Kotlin metadata:

```
# Add this option to tell ProGuard to keep and adapt Kotlin metadata
-adaptkotlinmetadata
-keepkotlinmetadata
```


Expand All @@ -31,7 +31,7 @@ The most common case to keep Kotlin metadata would be if you use the [kotlin-ref
In this case, to instruct ProGuard to keep and adapt the corresponding Kotlin metadata, add the following to your configuration:

```
-adaptkotlinmetadata
-keepkotlinmetadata
```

A popular framework that relies on reflection is [Jackson](https://github.com/FasterXML/jackson-module-kotlin).
Expand All @@ -45,7 +45,7 @@ In the case of a library, you would already be keeping the public API so you can
to your configuration:

```
-adaptkotlinmetadata
-keepkotlinmetadata
```

## Protection
Expand Down
6 changes: 6 additions & 0 deletions docs/md/manual/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ you can abbreviate them to their first unique characters.
obfuscated stack traces](examples.md#stacktrace). Only applicable when
obfuscating.

`-keepkotlinmetadata`{: #keepkotlinmetadata}
: Specifies to process `kotlin.Metadata` annotations if present.
Currently only shrinking and obfuscation of its content is supported.
Classes containing such annotations should be excuded from optimization
if this option is enabled.

`-adaptclassstrings`{: #adaptclassstrings} \[*[class\_filter](#filters)*\]
: Specifies that string constants that correspond to class names should be
obfuscated as well. Without a filter, all string constants that correspond
Expand Down
2 changes: 1 addition & 1 deletion docs/md/releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

| Version| Issue | Module | Explanation
|--------|----------|----------|----------------------------------
| 7.0.0 | | CORE | Added support for Kotlin metadata.
| 7.0.0 | | CORE | Added support for [Kotlin metadata](manual/kotlin.md), with new option `-keepkotlinmetadata`.
| 7.0.0 | PGD-32 | CORE | Allowing Java 14 class files.
| 7.0.0 | | CORE | Optimizing away instance references to constructor-less classes.
| 7.0.0 | DGD-1489 | CORE | Fixed potential `IllegalArgumentException` with message `Value "x" is not a reference value` when optimizing code with conditional casts.
Expand Down
8 changes: 4 additions & 4 deletions gradle-plugin/src/proguard/gradle/ProGuardTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -1063,15 +1063,15 @@ public void adaptclassstrings(String filter)
}

// Hack: support the keyword without parentheses in Groovy.
public Object getadaptkotlinmetadata()
public Object getkeepkotlinmetadata()
{
adaptkotlinmetadata();
keepkotlinmetadata();
return null;
}

public void adaptkotlinmetadata()
public void keepkotlinmetadata()
{
configuration.adaptKotlinMetadata = true;
configuration.keepKotlinMetadata = true;
}

// Hack: support the keyword without parentheses in Groovy.
Expand Down

0 comments on commit 3dc5906

Please sign in to comment.