From 20c99aa3e80f73ca1582ec3bbbf20fdca2538ca2 Mon Sep 17 00:00:00 2001 From: "niccolo.piazzesi" Date: Thu, 7 Mar 2024 09:58:51 +0100 Subject: [PATCH] Parse `-maximumremovedandroidloglevel` --- .../java/proguard/ConfigurationConstants.java | 2 + .../java/proguard/ConfigurationParser.java | 18 ++++++- .../proguard/ConfigurationParserTest.kt | 49 +++++++++++++++++++ docs/md/manual/releasenotes.md | 1 + 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/base/src/main/java/proguard/ConfigurationConstants.java b/base/src/main/java/proguard/ConfigurationConstants.java index fe571f2e..9b40e643 100644 --- a/base/src/main/java/proguard/ConfigurationConstants.java +++ b/base/src/main/java/proguard/ConfigurationConstants.java @@ -118,6 +118,8 @@ public class ConfigurationConstants public static final String ALWAYS_INLINE = "-alwaysinline"; public static final String IDENTIFIER_NAME_STRING = "-identifiernamestring"; + public static final String MAXIMUM_REMOVED_ANDROID_LOG_LEVEL = "-maximumremovedandroidloglevel"; + public static final String ANY_FILE_KEYWORD = "**"; diff --git a/base/src/main/java/proguard/ConfigurationParser.java b/base/src/main/java/proguard/ConfigurationParser.java index ef0996f2..8d30c50c 100644 --- a/base/src/main/java/proguard/ConfigurationParser.java +++ b/base/src/main/java/proguard/ConfigurationParser.java @@ -260,6 +260,7 @@ else if (ConfigurationConstants.REPACKAGE_CLASSES_OPTION else if (ConfigurationConstants.OPTIMIZE_AGGRESSIVELY .startsWith(nextWord)) configuration.optimizeConservatively = parseNoArgument(false); else if (ConfigurationConstants.ALWAYS_INLINE .startsWith(nextWord)) parseUnsupportedR8Rules(ConfigurationConstants.ALWAYS_INLINE, true); else if (ConfigurationConstants.IDENTIFIER_NAME_STRING .startsWith(nextWord)) parseUnsupportedR8Rules(ConfigurationConstants.IDENTIFIER_NAME_STRING, true); + else if (ConfigurationConstants.MAXIMUM_REMOVED_ANDROID_LOG_LEVEL .equals(nextWord)) parseMaximumRemovedAndroidLogLevel(); else { if (unknownOptionHandler != null) { @@ -2087,9 +2088,22 @@ private void parseUnsupportedR8Rules(String option, boolean parseClassSpecificat parseClassSpecificationArguments(); } - System.out.println("Warning: The R8 option " + option + " is currently not supported by ProGuard.\n" + - "This option will have no effect on the optimized artifact."); + warnUnsupportedR8Option(option); + } + + private void parseMaximumRemovedAndroidLogLevel() throws IOException, ParseException { + parseIntegerArgument(); + if (!configurationEnd(true)) { + parseClassSpecificationArguments(); + } + + warnUnsupportedR8Option(ConfigurationConstants.MAXIMUM_REMOVED_ANDROID_LOG_LEVEL); + } + + private static void warnUnsupportedR8Option(String option) { + System.out.println("Warning: The R8 option " + option + " is currently not supported by ProGuard.\n" + + "This option will have no effect on the optimized artifact."); } diff --git a/base/src/test/kotlin/proguard/ConfigurationParserTest.kt b/base/src/test/kotlin/proguard/ConfigurationParserTest.kt index 24977e79..bf838c83 100644 --- a/base/src/test/kotlin/proguard/ConfigurationParserTest.kt +++ b/base/src/test/kotlin/proguard/ConfigurationParserTest.kt @@ -200,6 +200,55 @@ class ConfigurationParserTest : FreeSpec({ } } } + "Testing -maximumremovedandroidloglevel parsing" - { + "Given an empty configuration" - { + val savedPrintStream = System.out + val customOutputStream = ByteArrayOutputStream() + System.setOut(PrintStream(customOutputStream)) + + parseConfiguration("") + + "The option does not print anything" { + customOutputStream.toString() shouldContain "" + System.setOut(savedPrintStream) + } + } + + "Given a configuration with -maximumremovedandroidloglevel without a class specification" - { + val savedPrintStream = System.out + val customOutputStream = ByteArrayOutputStream() + System.setOut(PrintStream(customOutputStream)) + + parseConfiguration("-maximumremovedandroidloglevel 1") + + "The option prints out a warning" { + customOutputStream.toString() shouldContain "Warning: The R8 option -maximumremovedandroidloglevel is currently not supported by ProGuard.\n" + + "This option will have no effect on the optimized artifact." + System.setOut(savedPrintStream) + } + } + + "Given a configuration with -maximumremovedandroidloglevel with a class specification" - { + val savedPrintStream = System.out + val customOutputStream = ByteArrayOutputStream() + System.setOut(PrintStream(customOutputStream)) + + parseConfiguration( + """ + -maximumremovedandroidloglevel 1 @org.chromium.build.annotations.DoNotStripLogs class ** { + ; + } + """.trimIndent(), + ) + + "The option prints out a warning" { + customOutputStream.toString() shouldContain "Warning: The R8 option -maximumremovedandroidloglevel is currently not supported by ProGuard.\n" + + "This option will have no effect on the optimized artifact." + System.setOut(savedPrintStream) + } + } + } + "Wildcard type tests" - { class TestConfig( diff --git a/docs/md/manual/releasenotes.md b/docs/md/manual/releasenotes.md index 6086aee3..b626960b 100644 --- a/docs/md/manual/releasenotes.md +++ b/docs/md/manual/releasenotes.md @@ -3,6 +3,7 @@ ### Bugfixes - Prevent unwanted name collision leading to missing methods in Kotlin DefaultImpls classes. +- Prevent `ParseException` when consumer rules contain `-maximumremovedandroidloglevel` rules. ## Version 7.4.2