Should you really be using the JVM of maven to run these tools?

I would argue no. You should be forking the toolchains specified JVM and
using that forked JVM to do the work. If you do it that way you can
completely control what logging those forked JVMs uses and route it to the
Maven logger of choice

On 2 February 2015 at 15:07, Lennart Jörelid <lennart.jore...@gmail.com>
wrote:

> Hello all,
>
> I'm in the final phase of revamping the Jaxb2-Maven-Plugin, and have
> encountered a (presumably) common problem. The plugin delegates most of its
> work to the JDK-distributed tools XJC and SchemaGen. These two tools use
> JUL for logging; and their respective outputs should be emitted onto the
> Maven Log for debugging and clarity.
>
> Writing a small Handler which delegates the JUL LogRecords to the active
> Maven Log is trivial - but I wonder if I need to reset the JUL root logger
> after the tool has been run, or if that is done automagically by Maven.
>
> Basically - will the next downstream plugin which needs to wrap a tool
> using JUL be affected by my fiddlings according to the snippet below?
>
> // Redirect the JUL Logging statements to the Maven Log.
> final Logger rootLogger = Logger.getLogger("");
> rootLogger.setLevel(Level.FINER);
> for(Handler current : rootLogger.getHandlers()) {
>     rootLogger.removeHandler(current);
> }
> rootLogger.addHandler(new MavenLogHandler(getLog(), "XJC", 
> getEncoding(false)));
>
> // Fire XJC
> if (XJC_COMPLETED_OK != Driver.run(xjcArguments, new 
> XjcLogAdapter(getLog()))) { ... display error message ... }
>
> The approach works as expected - the boldfaced logging statements below
> are harvested from the XJC tool being put to work by the jabx2-maven-plugin:
>
> [DEBUG] Created episode directory
> [/Users/lj/Development/Projects/Codehaus/github_jaxb2_plugin/target/it/xjc-include-xsds-in-artifact/target/generated-sources/jaxb/META-INF]:
> true
> [DEBUG] Using explicitly configured encoding [UTF-8]
>
>
>
>
>
> *[DEBUG] [XJC]: feb 02, 2015 3:51:53 EM
> com.sun.xml.bind.v2.util.XmlFactory createSchemaFactoryFIN: SchemaFactory
> instance:
> com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory@5b6813df[DEBUG]
> [XJC]: feb 02, 2015 3:51:53 EM com.sun.xml.bind.v2.util.XmlFactory
> allowExternalAccessFIN: Property
> "http://javax.xml.XMLConstants/property/accessExternalSchema
> <http://javax.xml.XMLConstants/property/accessExternalSchema>" is supported
> and has been successfully set by used JAXP implementation.*
>
> --
>
> --
> +==============================+
> | Bästa hälsningar,
> | [sw. "Best regards"]
> |
> | Lennart Jörelid
> | EAI Architect & Integrator
> |
> | jGuru Europe AB
> | Mölnlycke - Kista
> |
> | Email: l...@jguru.se
> | URL:   www.jguru.se
> | Phone
> | (skype):    jgurueurope
> | (intl):     +46 708 507 603
> | (domestic): 0708 - 507 603
> +==============================+
>
>

Reply via email to