diff --git a/src/main/java/com/github/wvengen/maven/proguard/MavenloggingBinder.java b/src/main/java/com/github/wvengen/maven/proguard/MavenloggingBinder.java new file mode 100644 index 00000000..7c9ce862 --- /dev/null +++ b/src/main/java/com/github/wvengen/maven/proguard/MavenloggingBinder.java @@ -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; + } + } + } +} diff --git a/src/main/java/com/github/wvengen/maven/proguard/ProGuardMojo.java b/src/main/java/com/github/wvengen/maven/proguard/ProGuardMojo.java index b8dd1b6a..db9282ff 100644 --- a/src/main/java/com/github/wvengen/maven/proguard/ProGuardMojo.java +++ b/src/main/java/com/github/wvengen/maven/proguard/ProGuardMojo.java @@ -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; /** @@ -1003,9 +1010,14 @@ private void proguardMain(Collection proguardJars, List 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);