On Thu, Aug 26, 2010 at 9:18 PM, Mark Petrovic <[email protected]> wrote:

> This works:
>
>    xjcOutput=path_to('target/generated-sources/xjc')
>    xjc = file(xjcOutput => sources) do |dir|
>      ant('xjc') do |ant|
>        mkdir_p xjcOutput
>        cp = Buildr.artifacts("javax.xml.bind:jaxb-api:jar:2.2.1",
> "com.sun.xml.bind:jaxb-impl:jar:2.2.1",
>                              "com.sun.xml.bind:jaxb-xjc:jar:2.2.1").each(&
> :invoke).map(& :name).join(File::PATH_SEPARATOR)
>        ant.taskdef :name=>"xjc", :classname=>"com.sun.tools.xjc.XJCTask",
> :classpath=>cp
>        ant.xjc :schema=>path_to("src/main/resources/c.xsd"),
> :destdir=>path_to(xjcOutput), :package=>"org.foo.api"
>      end
>    end
>
> How does it look?
>

Another improvement you could do is wire the artifact download as
dependencies instead of calling invoke() on them directly.  This is the
spirit of rake -- everything in the dependency graph.

To do so, you can define your artifacts outside the task,

XJC_DEPENDENCIES = %w{
 javax.xml.bind:jaxb-api:jar:2.2.1
 com.sun.xml.bind:jaxb-impl:jar:2.2.1
 com.sun.xml.bind:jaxb-xjc:jar:2.2.1
}

xjc = file(xjcOutput => [sources] + Buildr.artifacts(XJC_DEPENDENCIES)) do
|dir|
   ...
end

alex

Reply via email to