Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Override the logging level for proguard() Gradle task action #419

Open
EchoEllet opened this issue Jul 3, 2024 · 0 comments

Comments

@EchoEllet
Copy link
Contributor

EchoEllet commented Jul 3, 2024

When running the Proguard task directly inside another task by either:

proguardTask.actions.forEach { it.execute(proguardTask) }

Or:

proguardTask.proguard()

The logging level for the standard output will be LogLevel.INFO and for the error LogLevel.WARN regarding the configurations you set or update before running the Proguard task as the proguard() task action function will set it before executing Proguard:

// Gradle task execution.

@TaskAction
public void proguard() throws Exception
{
    // Let the logging manager capture the standard output and errors from
    // ProGuard.
    LoggingManager loggingManager = getLogging();
    loggingManager.captureStandardOutput(LogLevel.INFO);
    loggingManager.captureStandardError(LogLevel.WARN);

    // Run ProGuard with the collected configuration.
    new ProGuard(getConfiguration()).execute();

}

// Gradle task execution.
@TaskAction
public void proguard() throws Exception
{
// Let the logging manager capture the standard output and errors from
// ProGuard.
LoggingManager loggingManager = getLogging();
loggingManager.captureStandardOutput(LogLevel.INFO);
loggingManager.captureStandardError(LogLevel.WARN);
// Run ProGuard with the collected configuration.
new ProGuard(getConfiguration()).execute();
}

The logging level will always be INFO if you run the ProGuard task

proguardTask.logging.captureStandardOutput(LogLevel.ERROR)

// Execute the Proguard task
proguardTask.actions.forEach { it.execute(proguardTask) }

println("Standard Output Logging Level: ${proguardTask.logging.standardOutputCaptureLevel}") // Will be INFO

Without running Proguard Task:

proguardTask.logging.captureStandardOutput(LogLevel.ERROR)

println("Standard Output Logging Level: ${proguardTask.logging.standardOutputCaptureLevel}") // Will be ERROR

A workaround is to disable the logging completely while executing the task:

val oldStandardOut = System.out
val oldStandardErr = System.err
val noOpOutputStream =
    object : OutputStream() {
        override fun write(b: Int) {
            // Do nothing
        }
    }

try {
    System.setOut(java.io.PrintStream(noOpOutputStream))
    System.setErr(java.io.PrintStream(noOpOutputStream))

    // Execute the Proguard task
    proguardTask.actions.forEach { it.execute(proguardTask) }
} finally {
    System.setOut(oldStandardOut)
    System.setErr(oldStandardErr)
}

Or use another way to apply the Proguard plugin and use it, similar to Compose Desktop Proguard or SgtSilvio Gradle Proguard.

It seems that the getConfiguration() is private which is required to run with Proguard class using new ProGuard(getConfiguration()).execute();.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant