ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Jaxb task anyone?
Date Thu, 14 Nov 2002 20:36:48 GMT
To provide on update on this month old thread, the task provided by SUN is
not smart at all!!! So the task I started writing was not completely wasted
after all, since after converting it to Jaxb 1.0 beta, it's working nicely
for us now. It forks a new instance of the command-line Jaxb compiler
(thanks to <java>) per schema file only when the smarts have figured out it
needs to run (schema more recent or generated files modified/removed).

Here's the interface it has in our build.xml. If anyone's interested, I'll
post the task in Ant's BugZilla (used it AS-IS, at your own risk!). --DD

  <!-- ====================================================
       Generates the Jaxb-generated Java code from XML schemas (XSDs)

       This task will not regenerate the Java code from the schemas if the
       schema is not more recent the files in the target package/directory,
       or if this target package/directory as not been modified in any way.
       Otherwise, the target package/directory will be deleted,
       and regeneration of the Java code will occur.

       By default, the target package is deduced from the location of the
       schema, in a generated sub-package with further a sub-package named
       after the schema short filename (lower-cased).

       For example, schema com/lgc/infra/acme/tools.xsd
       yields package name com.lgc.infra.acme.generated.tools

       Schema filenames yielding invalid package name fragments
       will cause build exceptions... For example, schema-1.xsd
       or schema#1.xsd or 1schema.xsd are all invalid!

       But one can define a mapper to custom-deduce the package name to
       generate the Java code into, as shown in the target below.
    -->
  <target name="generated" depends="-buildmagic"
          description="Generates (using Jaxb) Java code from XML schemas">
    <jaxb destDir="${src}"
          readOnly="true"
          strictValidation="true"
          xjcjar="tools/jaxb/jaxb-xjc.jar">
      <schemas dir="${src}" includes="**/doc-files/*.xsd" />

      <!-- Custom mapper to deduce the target package name:
           For example, schema com/lgc/infra/acme/doc-files/tools.xsd
           yields package name com.lgc.infra.acme.generated.tools
        -->
      <targetPackageMapper type="regexp"
                           from="(.*)/doc-files/(.*)\.xsd"
                           to="\1/generated/\2" />
    </jaxb>
  </target>

  <target name="clean.generated">
    <delete includeEmptyDirs="true" quiet="true">
      <fileset dir="${src}" includes="**/generated/**" />
    </delete>
  </target>

-----Original Message-----
From: Glenn Kidd [mailto:GKidd@placeware.com] 
Sent: Tuesday, October 15, 2002 3:35 PM
To: 'Ant Users List'
Subject: RE: Jaxb task anyone?

Not sure if task is smart enough, I will let you know because I intend to
find out some time this week.  Even though you have to scrap it, we still
appreciate the hard work ;)


Glenn

-----Original Message-----
From: Dominique Devienne [mailto:DDevienne@lgc.com]
Sent: Tuesday, October 15, 2002 12:24 PM
To: 'Ant Users List'
Subject: RE: Jaxb task anyone?


Yes, I just realized that myself reading the doc... That just means we need
to switch all our DTDs to schemas!!! Hopefully the task is smart enough not
to re-generate the Java sources if the schema hasn't changed (do you know?).
Hard to say until I have schemas to test, since their task, as the rest of
the Jaxb code, is closed-source (except for the API classes though).

Again, thanks for the info. I can just scrap my own task (that's the second
task I write/augment that I have to scrap the same day, after Mkdir... Sigh)

--DD

PS: SUN shipping the Ant 1.5 JAR is not that great either IMHO.

-----Original Message-----
From: Glenn Kidd [mailto:GKidd@placeware.com] 
Sent: Tuesday, October 15, 2002 2:12 PM
To: 'Ant Users List'
Subject: RE: Jaxb task anyone?

The new release has drastic changes, no more dtd and xjs, instead they
switched to XML schemas...


Glenn

-----Original Message-----
From: Dominique Devienne [mailto:DDevienne@lgc.com]
Sent: Tuesday, October 15, 2002 12:08 PM
To: 'Ant Users List'
Subject: RE: Jaxb task anyone?


It's ironic I read your message seconds after the first commit of my very
own Jaxb task (see below).... Thanks! I'm checking out the SUN's task as I
write this. --DD 

/**
 * Compiles using SUN's JAXB Java &amp; XML Data Binding framework
 * a DTD with optionally a binding schema (XJS file).
 * <p>
 * Uses the &lt;dependset&gt; and &lt;java&gt; task internally to do most
 * of the work. Neither the DTD nor the binding schema are parsed, but
instead
 * the output of the Jaxb compiler is parsed to <em>learn</em> a posteriori
 * which files this combination of DTD and XJS files yields. This
information
 * is then cached for subsequent run to avoid unnecessary re-generation of
the
 * generated Java files. When lacking this cached information, this task
 * always runs the Jaxb compiler again.
 */
public class JaxbSchemaCompiler ...

-----Original Message-----
From: Glenn Kidd [mailto:GKidd@placeware.com] 
Sent: Tuesday, October 15, 2002 1:49 PM
To: 'Ant Users List'
Subject: RE: Jaxb task anyone?

This was posted 3 weeks ago.  I just noticed that sun releases a beta
implementation of JAXB (http://java.sun.com/xml/downloads/jaxb.html -
requires logon to download).  In it there is an ant task for the JAXB xjc.
Hope this helps.  


Glenn

-----Original Message-----
From: Dominique Devienne [mailto:DDevienne@lgc.com]
Sent: Tuesday, October 01, 2002 1:22 PM
To: 'ant-user@jakarta.apache.org'
Subject: Jaxb task anyone?


Has anyone wrapped SUN's jaxb com.sun.tools.xjc.Main into a task?
Or are people simply using <java> and/or <apply>?

Thanks, --DD

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message