Skip to content

Commit

Permalink
Merge pull request #385 from Chu-wee/bind_proguard_output_to_maven_pl…
Browse files Browse the repository at this point in the history
…ugin_log

增加将proguard输出到Maven插件日志的功能
  • Loading branch information
lasselindqvist authored Dec 25, 2024
2 parents 004ad9f + a061f74 commit 49054b0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.github.wvengen.maven.proguard;

import org.apache.maven.plugin.logging.Log;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;

import java.io.PrintStream;

public class MavenloggingBinder extends DefaultLogger {

private final Log log;

public MavenloggingBinder(Log log) {
this.log = log;
}

@Override
public void setOutputPrintStream(PrintStream output) {

}

@Override
public void setErrorPrintStream(PrintStream err) {

}

@Override
protected void printMessage(String message, PrintStream stream, int priority) {
switch (priority) {
case Project.MSG_ERR: {
log.error(message);
break;
}
case Project.MSG_VERBOSE:
case Project.MSG_DEBUG: {
log.debug(message);
break;
}
case Project.MSG_WARN: {
log.warn(message);
break;
}
default: {
log.info(message);
break;
}
}
}
}
18 changes: 15 additions & 3 deletions src/main/java/com/github/wvengen/maven/proguard/ProGuardMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ public class ProGuardMojo extends AbstractMojo {
*/
private boolean silent;

/**
* bind proguard output to maven plugin logging.
*
* @parameter default-value="false"
*/
private boolean bindToMavenLogging;

private Log log;

/**
Expand Down Expand Up @@ -1003,9 +1010,14 @@ private void proguardMain(Collection<File> proguardJars, List<String> argsList,
antProject.setName(mojo.mavenProject.getName());
antProject.init();

DefaultLogger antLogger = new DefaultLogger();
antLogger.setOutputPrintStream(System.out);
antLogger.setErrorPrintStream(System.err);
DefaultLogger antLogger;
if (bindToMavenLogging) {
antLogger = new MavenloggingBinder(mojo.log);
} else {
antLogger = new DefaultLogger();
antLogger.setOutputPrintStream(System.out);
antLogger.setErrorPrintStream(System.err);
}
int logLevel = mojo.log.isDebugEnabled() ? Project.MSG_DEBUG : Project.MSG_INFO;
antLogger.setMessageOutputLevel(silent ? Project.MSG_ERR : logLevel);

Expand Down

0 comments on commit 49054b0

Please sign in to comment.