You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Mark Petrovic <ms...@gmail.com> on 2010/08/27 03:53:19 UTC

Newbie classpath question

Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the black Buildr book, and now I'm attempting to do some simple stuff with the JAXB XJC task.  Here's what I have so far:

...
    compile :xjc
    package :jar, :id => 'vzapi'

    task :xjc do
          begin
          ant('xjc') do |ant|
            xjcOutput='target/generated-sources/xjc'
            rm_rf "#{xjcOutput}"
            mkdir_p "#{xjcOutput}"
            t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
            puts t
            ant.taskdef :name=>"xjc", :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
            ant.xjc :schema=>"src/main/resources/c.xsd", :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
          end
        end
    end

where you can see my horribly clumsy, two-left-foot attempts to put together a classpath for the Ant taskdef.  The JAXB jars are in ENV['HOME']}/tools/jaxb-ri/lib/*.jar.

Can someone suggest the "Buildr way" to build this classpath?  I've studied the examples referred to here http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but I'm still not quite getting it.  I'm learning Ruby as I go, having read the Pickaxe book, but where not a lot of it has sunk in yet.

Thanks!

--
Mark Petrovic



Re: Newbie classpath question

Posted by Mark Petrovic <ms...@gmail.com>.
Bundle my code?  Heck yes!

On Aug 27, 2010, at 9:44 AM, Antoine Toulme wrote:

> Nice! Retweeted with the buildr account, and if you want tomorrow I'll
> bundle your code as a buildr extension.
> 
> On Fri, Aug 27, 2010 at 09:23, Mark Petrovic <ms...@gmail.com> wrote:
> 
>> Thanks.  A good first step into using Buildr.
>> 
>> http://radioae6rt.wordpress.com/2010/08/27/a-buildr-task-for-jaxb-xjc/
>> 
>> 
>> On Aug 26, 2010, at 9:35 PM, Antoine Toulme wrote:
>> 
>>> Looking very good. You can externalize the artifact definitions to make
>> it
>>> easy to change versions or for people to add or edit jars, like the
>>> hibernate addon.
>>> 
>>> The file(xjcOutput => sources) instruction is a Rake task definition. You
>>> create a file task associated with the path xjcOutput, which is added to
>> the
>>> prerequisites of the sources task. You won't find that info in the
>> Pickaxe,
>>> it's pretty custom stuff.
>>> 
>>> Antoine
>>> 
>>> 
>>> 
>>> On Thu, Aug 26, 2010 at 21:18, Mark Petrovic <ms...@gmail.com>
>> wrote:
>>> 
>>>> Thank you very much.
>>>> 
>>>> 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?
>>>> 
>>>> 
>>>> I'm not really sure what "file(xjcOutput => sources)" actually does, or
>> how
>>>> to interpret it;  back to the Pickaxe book!
>>>> 
>>>> 
>>>> 
>>>> On Aug 26, 2010, at 8:27 PM, Antoine Toulme wrote:
>>>> 
>>>>> Hello Marc,
>>>>> 
>>>>> a few remarks:
>>>>> 1. "#{xjcOutput}" is equivalent to xjcOutput. That should simplify your
>>>>> code.
>>>>> 2. Why bother with mentioning local artifacts ? Do you know which jar
>> you
>>>>> need ? Are they hosted on a maven repository ?
>>>>> If yes, you can do :classpath=>
>>>>> Buildr.artifacts("com.sun.jaxb:jaxb:jar:1.2.3",
>>>>> 
>>>> 
>> "com.sun.jaxb:jaxb-impl:jar:1.2.3").map(&:to_s).join(File::PATH_SEPARATOR)
>>>>> Your code will work on any machine then.
>>>>> 
>>>>> 
>>>>> On Thu, Aug 26, 2010 at 18:53, Mark Petrovic <ms...@gmail.com>
>>>> wrote:
>>>>> 
>>>>>> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the
>> black
>>>>>> Buildr book, and now I'm attempting to do some simple stuff with the
>>>> JAXB
>>>>>> XJC task.  Here's what I have so far:
>>>>>> 
>>>>>> ...
>>>>>> compile :xjc
>>>>>> package :jar, :id => 'vzapi'
>>>>>> 
>>>>>> task :xjc do
>>>>>>       begin
>>>>>>       ant('xjc') do |ant|
>>>>>>         xjcOutput='target/generated-sources/xjc'
>>>>>>         rm_rf "#{xjcOutput}"
>>>>>>         mkdir_p "#{xjcOutput}"
>>>>>> 
>>>>>> 
>>>> 
>> t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
>>>>>>         puts t
>>>>>>         ant.taskdef :name=>"xjc",
>>>>>> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
>>>>>>         ant.xjc :schema=>"src/main/resources/c.xsd",
>>>>>> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
>>>>>>       end
>>>>>>     end
>>>>>> end
>>>>>> 
>>>>>> where you can see my horribly clumsy, two-left-foot attempts to put
>>>>>> together a classpath for the Ant taskdef.  The JAXB jars are in
>>>>>> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
>>>>>> 
>>>>>> Can someone suggest the "Buildr way" to build this classpath?  I've
>>>> studied
>>>>>> the examples referred to here
>>>>>> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but
>>>> I'm
>>>>>> still not quite getting it.  I'm learning Ruby as I go, having read
>> the
>>>>>> Pickaxe book, but where not a lot of it has sunk in yet.
>>>>>> 
>>>>>> Thanks!
>>>>>> 
>>>>>> --
>>>>>> Mark Petrovic
>>>>>> 
>>>>>> 
>>>>>> 
>>>> 
>>>> 
>>>> --
>>>> Mark Petrovic
>>>> 
>>>> 
>>>> 
>> 
>> 
>> --
>> Mark Petrovic
>> 
>> 
>> 


--
Mark Petrovic



Re: Newbie classpath question

Posted by Antoine Toulme <an...@lunar-ocean.com>.
Nice! Retweeted with the buildr account, and if you want tomorrow I'll
bundle your code as a buildr extension.

On Fri, Aug 27, 2010 at 09:23, Mark Petrovic <ms...@gmail.com> wrote:

> Thanks.  A good first step into using Buildr.
>
> http://radioae6rt.wordpress.com/2010/08/27/a-buildr-task-for-jaxb-xjc/
>
>
> On Aug 26, 2010, at 9:35 PM, Antoine Toulme wrote:
>
> > Looking very good. You can externalize the artifact definitions to make
> it
> > easy to change versions or for people to add or edit jars, like the
> > hibernate addon.
> >
> > The file(xjcOutput => sources) instruction is a Rake task definition. You
> > create a file task associated with the path xjcOutput, which is added to
> the
> > prerequisites of the sources task. You won't find that info in the
> Pickaxe,
> > it's pretty custom stuff.
> >
> > Antoine
> >
> >
> >
> > On Thu, Aug 26, 2010 at 21:18, Mark Petrovic <ms...@gmail.com>
> wrote:
> >
> >> Thank you very much.
> >>
> >> 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?
> >>
> >>
> >> I'm not really sure what "file(xjcOutput => sources)" actually does, or
> how
> >> to interpret it;  back to the Pickaxe book!
> >>
> >>
> >>
> >> On Aug 26, 2010, at 8:27 PM, Antoine Toulme wrote:
> >>
> >>> Hello Marc,
> >>>
> >>> a few remarks:
> >>> 1. "#{xjcOutput}" is equivalent to xjcOutput. That should simplify your
> >>> code.
> >>> 2. Why bother with mentioning local artifacts ? Do you know which jar
> you
> >>> need ? Are they hosted on a maven repository ?
> >>> If yes, you can do :classpath=>
> >>> Buildr.artifacts("com.sun.jaxb:jaxb:jar:1.2.3",
> >>>
> >>
> "com.sun.jaxb:jaxb-impl:jar:1.2.3").map(&:to_s).join(File::PATH_SEPARATOR)
> >>> Your code will work on any machine then.
> >>>
> >>>
> >>> On Thu, Aug 26, 2010 at 18:53, Mark Petrovic <ms...@gmail.com>
> >> wrote:
> >>>
> >>>> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the
> black
> >>>> Buildr book, and now I'm attempting to do some simple stuff with the
> >> JAXB
> >>>> XJC task.  Here's what I have so far:
> >>>>
> >>>> ...
> >>>>  compile :xjc
> >>>>  package :jar, :id => 'vzapi'
> >>>>
> >>>>  task :xjc do
> >>>>        begin
> >>>>        ant('xjc') do |ant|
> >>>>          xjcOutput='target/generated-sources/xjc'
> >>>>          rm_rf "#{xjcOutput}"
> >>>>          mkdir_p "#{xjcOutput}"
> >>>>
> >>>>
> >>
> t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
> >>>>          puts t
> >>>>          ant.taskdef :name=>"xjc",
> >>>> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
> >>>>          ant.xjc :schema=>"src/main/resources/c.xsd",
> >>>> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
> >>>>        end
> >>>>      end
> >>>>  end
> >>>>
> >>>> where you can see my horribly clumsy, two-left-foot attempts to put
> >>>> together a classpath for the Ant taskdef.  The JAXB jars are in
> >>>> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
> >>>>
> >>>> Can someone suggest the "Buildr way" to build this classpath?  I've
> >> studied
> >>>> the examples referred to here
> >>>> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but
> >> I'm
> >>>> still not quite getting it.  I'm learning Ruby as I go, having read
> the
> >>>> Pickaxe book, but where not a lot of it has sunk in yet.
> >>>>
> >>>> Thanks!
> >>>>
> >>>> --
> >>>> Mark Petrovic
> >>>>
> >>>>
> >>>>
> >>
> >>
> >> --
> >> Mark Petrovic
> >>
> >>
> >>
>
>
> --
> Mark Petrovic
>
>
>

Re: Newbie classpath question

Posted by Mark Petrovic <ms...@gmail.com>.
Thanks.  A good first step into using Buildr.

http://radioae6rt.wordpress.com/2010/08/27/a-buildr-task-for-jaxb-xjc/


On Aug 26, 2010, at 9:35 PM, Antoine Toulme wrote:

> Looking very good. You can externalize the artifact definitions to make it
> easy to change versions or for people to add or edit jars, like the
> hibernate addon.
> 
> The file(xjcOutput => sources) instruction is a Rake task definition. You
> create a file task associated with the path xjcOutput, which is added to the
> prerequisites of the sources task. You won't find that info in the Pickaxe,
> it's pretty custom stuff.
> 
> Antoine
> 
> 
> 
> On Thu, Aug 26, 2010 at 21:18, Mark Petrovic <ms...@gmail.com> wrote:
> 
>> Thank you very much.
>> 
>> 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?
>> 
>> 
>> I'm not really sure what "file(xjcOutput => sources)" actually does, or how
>> to interpret it;  back to the Pickaxe book!
>> 
>> 
>> 
>> On Aug 26, 2010, at 8:27 PM, Antoine Toulme wrote:
>> 
>>> Hello Marc,
>>> 
>>> a few remarks:
>>> 1. "#{xjcOutput}" is equivalent to xjcOutput. That should simplify your
>>> code.
>>> 2. Why bother with mentioning local artifacts ? Do you know which jar you
>>> need ? Are they hosted on a maven repository ?
>>> If yes, you can do :classpath=>
>>> Buildr.artifacts("com.sun.jaxb:jaxb:jar:1.2.3",
>>> 
>> "com.sun.jaxb:jaxb-impl:jar:1.2.3").map(&:to_s).join(File::PATH_SEPARATOR)
>>> Your code will work on any machine then.
>>> 
>>> 
>>> On Thu, Aug 26, 2010 at 18:53, Mark Petrovic <ms...@gmail.com>
>> wrote:
>>> 
>>>> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the black
>>>> Buildr book, and now I'm attempting to do some simple stuff with the
>> JAXB
>>>> XJC task.  Here's what I have so far:
>>>> 
>>>> ...
>>>>  compile :xjc
>>>>  package :jar, :id => 'vzapi'
>>>> 
>>>>  task :xjc do
>>>>        begin
>>>>        ant('xjc') do |ant|
>>>>          xjcOutput='target/generated-sources/xjc'
>>>>          rm_rf "#{xjcOutput}"
>>>>          mkdir_p "#{xjcOutput}"
>>>> 
>>>> 
>> t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
>>>>          puts t
>>>>          ant.taskdef :name=>"xjc",
>>>> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
>>>>          ant.xjc :schema=>"src/main/resources/c.xsd",
>>>> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
>>>>        end
>>>>      end
>>>>  end
>>>> 
>>>> where you can see my horribly clumsy, two-left-foot attempts to put
>>>> together a classpath for the Ant taskdef.  The JAXB jars are in
>>>> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
>>>> 
>>>> Can someone suggest the "Buildr way" to build this classpath?  I've
>> studied
>>>> the examples referred to here
>>>> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but
>> I'm
>>>> still not quite getting it.  I'm learning Ruby as I go, having read the
>>>> Pickaxe book, but where not a lot of it has sunk in yet.
>>>> 
>>>> Thanks!
>>>> 
>>>> --
>>>> Mark Petrovic
>>>> 
>>>> 
>>>> 
>> 
>> 
>> --
>> Mark Petrovic
>> 
>> 
>> 


--
Mark Petrovic



Re: Newbie classpath question

Posted by Antoine Toulme <an...@lunar-ocean.com>.
Looking very good. You can externalize the artifact definitions to make it
easy to change versions or for people to add or edit jars, like the
hibernate addon.

The file(xjcOutput => sources) instruction is a Rake task definition. You
create a file task associated with the path xjcOutput, which is added to the
prerequisites of the sources task. You won't find that info in the Pickaxe,
it's pretty custom stuff.

Antoine



On Thu, Aug 26, 2010 at 21:18, Mark Petrovic <ms...@gmail.com> wrote:

> Thank you very much.
>
> 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?
>
>
> I'm not really sure what "file(xjcOutput => sources)" actually does, or how
> to interpret it;  back to the Pickaxe book!
>
>
>
> On Aug 26, 2010, at 8:27 PM, Antoine Toulme wrote:
>
> > Hello Marc,
> >
> > a few remarks:
> > 1. "#{xjcOutput}" is equivalent to xjcOutput. That should simplify your
> > code.
> > 2. Why bother with mentioning local artifacts ? Do you know which jar you
> > need ? Are they hosted on a maven repository ?
> > If yes, you can do :classpath=>
> > Buildr.artifacts("com.sun.jaxb:jaxb:jar:1.2.3",
> >
> "com.sun.jaxb:jaxb-impl:jar:1.2.3").map(&:to_s).join(File::PATH_SEPARATOR)
> > Your code will work on any machine then.
> >
> >
> > On Thu, Aug 26, 2010 at 18:53, Mark Petrovic <ms...@gmail.com>
> wrote:
> >
> >> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the black
> >> Buildr book, and now I'm attempting to do some simple stuff with the
> JAXB
> >> XJC task.  Here's what I have so far:
> >>
> >> ...
> >>   compile :xjc
> >>   package :jar, :id => 'vzapi'
> >>
> >>   task :xjc do
> >>         begin
> >>         ant('xjc') do |ant|
> >>           xjcOutput='target/generated-sources/xjc'
> >>           rm_rf "#{xjcOutput}"
> >>           mkdir_p "#{xjcOutput}"
> >>
> >>
> t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
> >>           puts t
> >>           ant.taskdef :name=>"xjc",
> >> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
> >>           ant.xjc :schema=>"src/main/resources/c.xsd",
> >> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
> >>         end
> >>       end
> >>   end
> >>
> >> where you can see my horribly clumsy, two-left-foot attempts to put
> >> together a classpath for the Ant taskdef.  The JAXB jars are in
> >> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
> >>
> >> Can someone suggest the "Buildr way" to build this classpath?  I've
> studied
> >> the examples referred to here
> >> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but
> I'm
> >> still not quite getting it.  I'm learning Ruby as I go, having read the
> >> Pickaxe book, but where not a lot of it has sunk in yet.
> >>
> >> Thanks!
> >>
> >> --
> >> Mark Petrovic
> >>
> >>
> >>
>
>
> --
> Mark Petrovic
>
>
>

Re: Newbie classpath question

Posted by Mark Petrovic <ms...@gmail.com>.
Pretty cool.

You guys feel free to do what you want with respect to the addon implementation.  I'm just glad to have gotten something relatively un-hideous to work.


On Aug 27, 2010, at 10:28 AM, Alex Boisvert wrote:

> On Thu, Aug 26, 2010 at 9:18 PM, Mark Petrovic <ms...@gmail.com> 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


--
Mark Petrovic



Re: Newbie classpath question

Posted by Alex Boisvert <al...@gmail.com>.
On Thu, Aug 26, 2010 at 9:18 PM, Mark Petrovic <ms...@gmail.com> 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

Re: Newbie classpath question

Posted by Mark Petrovic <ms...@gmail.com>.
Thank you very much.

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?


I'm not really sure what "file(xjcOutput => sources)" actually does, or how to interpret it;  back to the Pickaxe book!



On Aug 26, 2010, at 8:27 PM, Antoine Toulme wrote:

> Hello Marc,
> 
> a few remarks:
> 1. "#{xjcOutput}" is equivalent to xjcOutput. That should simplify your
> code.
> 2. Why bother with mentioning local artifacts ? Do you know which jar you
> need ? Are they hosted on a maven repository ?
> If yes, you can do :classpath=>
> Buildr.artifacts("com.sun.jaxb:jaxb:jar:1.2.3",
> "com.sun.jaxb:jaxb-impl:jar:1.2.3").map(&:to_s).join(File::PATH_SEPARATOR)
> Your code will work on any machine then.
> 
> 
> On Thu, Aug 26, 2010 at 18:53, Mark Petrovic <ms...@gmail.com> wrote:
> 
>> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the black
>> Buildr book, and now I'm attempting to do some simple stuff with the JAXB
>> XJC task.  Here's what I have so far:
>> 
>> ...
>>   compile :xjc
>>   package :jar, :id => 'vzapi'
>> 
>>   task :xjc do
>>         begin
>>         ant('xjc') do |ant|
>>           xjcOutput='target/generated-sources/xjc'
>>           rm_rf "#{xjcOutput}"
>>           mkdir_p "#{xjcOutput}"
>> 
>> t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
>>           puts t
>>           ant.taskdef :name=>"xjc",
>> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
>>           ant.xjc :schema=>"src/main/resources/c.xsd",
>> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
>>         end
>>       end
>>   end
>> 
>> where you can see my horribly clumsy, two-left-foot attempts to put
>> together a classpath for the Ant taskdef.  The JAXB jars are in
>> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
>> 
>> Can someone suggest the "Buildr way" to build this classpath?  I've studied
>> the examples referred to here
>> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but I'm
>> still not quite getting it.  I'm learning Ruby as I go, having read the
>> Pickaxe book, but where not a lot of it has sunk in yet.
>> 
>> Thanks!
>> 
>> --
>> Mark Petrovic
>> 
>> 
>> 


--
Mark Petrovic



Re: Newbie classpath question

Posted by Antoine Toulme <an...@lunar-ocean.com>.
Hello Marc,

a few remarks:
1. "#{xjcOutput}" is equivalent to xjcOutput. That should simplify your
code.
2. Why bother with mentioning local artifacts ? Do you know which jar you
need ? Are they hosted on a maven repository ?
If yes, you can do :classpath=>
Buildr.artifacts("com.sun.jaxb:jaxb:jar:1.2.3",
"com.sun.jaxb:jaxb-impl:jar:1.2.3").map(&:to_s).join(File::PATH_SEPARATOR)
Your code will work on any machine then.


On Thu, Aug 26, 2010 at 18:53, Mark Petrovic <ms...@gmail.com> wrote:

> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the black
> Buildr book, and now I'm attempting to do some simple stuff with the JAXB
> XJC task.  Here's what I have so far:
>
> ...
>    compile :xjc
>    package :jar, :id => 'vzapi'
>
>    task :xjc do
>          begin
>          ant('xjc') do |ant|
>            xjcOutput='target/generated-sources/xjc'
>            rm_rf "#{xjcOutput}"
>            mkdir_p "#{xjcOutput}"
>
>  t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
>            puts t
>            ant.taskdef :name=>"xjc",
> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
>            ant.xjc :schema=>"src/main/resources/c.xsd",
> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
>          end
>        end
>    end
>
> where you can see my horribly clumsy, two-left-foot attempts to put
> together a classpath for the Ant taskdef.  The JAXB jars are in
> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
>
> Can someone suggest the "Buildr way" to build this classpath?  I've studied
> the examples referred to here
> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but I'm
> still not quite getting it.  I'm learning Ruby as I go, having read the
> Pickaxe book, but where not a lot of it has sunk in yet.
>
> Thanks!
>
> --
> Mark Petrovic
>
>
>

Re: Newbie classpath question

Posted by Alex Boisvert <al...@gmail.com>.
If you're curious about making a plugin for JAXB, you could take a look at
the XMLBeans plugin -- similar pattern.
http://github.com/apache/buildr/blob/trunk/addon/buildr/xmlbeans.rb

<http://github.com/apache/buildr/blob/trunk/addon/buildr/xmlbeans.rb>alex

On Sat, Aug 28, 2010 at 5:53 AM, Mark Petrovic <ms...@gmail.com> wrote:

> Thanks.
>
> That's a goodly chunk of information.  I understand the concept of changing
> the layout, and why you might want to do it to add source code paths to the
> defaults for compile.  But for the JAXB XJC operation specifically, I need
> some processing to happen before compile happens, namely the XSD file has to
> be processed to produce JAXB Java classes.  Where does that happen in the
> scheme below?  Maybe you are speaking to a more general point, where the
> question doesn't actually operate.
>
> One thing that could be generalized with respect to the inline JAXB task is
> to parametrize the task with respect to the location of the XSD file so
> other projects can use it.  Hmm.
>
> On Aug 27, 2010, at 9:15 AM, Ed Smiley wrote:
>
> > As you intuitively know, you don't really need to use ant to do much of
> > anything inside Buildr.
> >
> > By changing the settings for the target and source you can take care of
> the
> > file management automatically.  Cleaning, rebuilding, dependencies etc.
> By
> > setting compile with, you can add all your dependencies.
> >
> > Here's an example:
> >
> > To set the target and source, you define a "layout" which reassigns the
> > defaults, for example, to change your Java source to src/, and to use a
> > custom built_dir/ target directory,
> >
> >  my_layout = Layout.new
> >  my_layout[:source, :main, :java] = 'src'
> >  my_layout[:target, :main] = 'build_dir'
> > Then make your project use it:
> >
> > define "myproject" , *:layout=>my_layout *do
> >
> > to add dependencies,
> >
> > define an array of libraries and paths, for example
> > AXIS2 = 'org.apache.axis2:axis2:jar:1.2'
> > LIB = ["jars/*.jar", AXIS2]
> >
> > and change the compile directive to use with:
> >
> > ...
> >
> > compile.with LIB# Added classpath dependencies
> >    package(:jar)
> > end
> >
> > So this will compile and jar using both an external dependency, which
> will
> > be automatically downloaded, and your local libraries.  You can pretty
> much
> > run Java directly from inside Buildr too: Java.System.out.println("this
> > prints")
> > That might be an easier way fo running JAXB.
> >
> >
> > On Thu, Aug 26, 2010 at 6:53 PM, Mark Petrovic <ms...@gmail.com>
> wrote:
> >
> >> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the black
> >> Buildr book, and now I'm attempting to do some simple stuff with the
> JAXB
> >> XJC task.  Here's what I have so far:
> >>
> >> ...
> >>   compile :xjc
> >>   package :jar, :id => 'vzapi'
> >>
> >>   task :xjc do
> >>         begin
> >>         ant('xjc') do |ant|
> >>           xjcOutput='target/generated-sources/xjc'
> >>           rm_rf "#{xjcOutput}"
> >>           mkdir_p "#{xjcOutput}"
> >>
> >>
> t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
> >>           puts t
> >>           ant.taskdef :name=>"xjc",
> >> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
> >>           ant.xjc :schema=>"src/main/resources/c.xsd",
> >> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
> >>         end
> >>       end
> >>   end
> >>
> >> where you can see my horribly clumsy, two-left-foot attempts to put
> >> together a classpath for the Ant taskdef.  The JAXB jars are in
> >> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
> >>
> >> Can someone suggest the "Buildr way" to build this classpath?  I've
> studied
> >> the examples referred to here
> >> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but
> I'm
> >> still not quite getting it.  I'm learning Ruby as I go, having read the
> >> Pickaxe book, but where not a lot of it has sunk in yet.
> >>
> >> Thanks!
> >>
> >> --
> >> Mark Petrovic
> >>
> >>
> >>
>
>
> --
> Mark Petrovic
>
>
>

Re: Newbie classpath question

Posted by Mark Petrovic <ms...@gmail.com>.
Thanks.

That's a goodly chunk of information.  I understand the concept of changing the layout, and why you might want to do it to add source code paths to the defaults for compile.  But for the JAXB XJC operation specifically, I need some processing to happen before compile happens, namely the XSD file has to be processed to produce JAXB Java classes.  Where does that happen in the scheme below?  Maybe you are speaking to a more general point, where the question doesn't actually operate.

One thing that could be generalized with respect to the inline JAXB task is to parametrize the task with respect to the location of the XSD file so other projects can use it.  Hmm.

On Aug 27, 2010, at 9:15 AM, Ed Smiley wrote:

> As you intuitively know, you don't really need to use ant to do much of
> anything inside Buildr.
> 
> By changing the settings for the target and source you can take care of the
> file management automatically.  Cleaning, rebuilding, dependencies etc. By
> setting compile with, you can add all your dependencies.
> 
> Here's an example:
> 
> To set the target and source, you define a "layout" which reassigns the
> defaults, for example, to change your Java source to src/, and to use a
> custom built_dir/ target directory,
> 
>  my_layout = Layout.new
>  my_layout[:source, :main, :java] = 'src'
>  my_layout[:target, :main] = 'build_dir'
> Then make your project use it:
> 
> define "myproject" , *:layout=>my_layout *do
> 
> to add dependencies,
> 
> define an array of libraries and paths, for example
> AXIS2 = 'org.apache.axis2:axis2:jar:1.2'
> LIB = ["jars/*.jar", AXIS2]
> 
> and change the compile directive to use with:
> 
> ...
> 
> compile.with LIB# Added classpath dependencies
>    package(:jar)
> end
> 
> So this will compile and jar using both an external dependency, which will
> be automatically downloaded, and your local libraries.  You can pretty much
> run Java directly from inside Buildr too: Java.System.out.println("this
> prints")
> That might be an easier way fo running JAXB.
> 
> 
> On Thu, Aug 26, 2010 at 6:53 PM, Mark Petrovic <ms...@gmail.com> wrote:
> 
>> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the black
>> Buildr book, and now I'm attempting to do some simple stuff with the JAXB
>> XJC task.  Here's what I have so far:
>> 
>> ...
>>   compile :xjc
>>   package :jar, :id => 'vzapi'
>> 
>>   task :xjc do
>>         begin
>>         ant('xjc') do |ant|
>>           xjcOutput='target/generated-sources/xjc'
>>           rm_rf "#{xjcOutput}"
>>           mkdir_p "#{xjcOutput}"
>> 
>> t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
>>           puts t
>>           ant.taskdef :name=>"xjc",
>> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
>>           ant.xjc :schema=>"src/main/resources/c.xsd",
>> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
>>         end
>>       end
>>   end
>> 
>> where you can see my horribly clumsy, two-left-foot attempts to put
>> together a classpath for the Ant taskdef.  The JAXB jars are in
>> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
>> 
>> Can someone suggest the "Buildr way" to build this classpath?  I've studied
>> the examples referred to here
>> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but I'm
>> still not quite getting it.  I'm learning Ruby as I go, having read the
>> Pickaxe book, but where not a lot of it has sunk in yet.
>> 
>> Thanks!
>> 
>> --
>> Mark Petrovic
>> 
>> 
>> 


--
Mark Petrovic



Re: Newbie classpath question

Posted by Ed Smiley <es...@ebrary.com>.
As you intuitively know, you don't really need to use ant to do much of
anything inside Buildr.

By changing the settings for the target and source you can take care of the
file management automatically.  Cleaning, rebuilding, dependencies etc. By
setting compile with, you can add all your dependencies.

Here's an example:

To set the target and source, you define a "layout" which reassigns the
defaults, for example, to change your Java source to src/, and to use a
custom built_dir/ target directory,

  my_layout = Layout.new
  my_layout[:source, :main, :java] = 'src'
  my_layout[:target, :main] = 'build_dir'
Then make your project use it:

define "myproject" , *:layout=>my_layout *do

to add dependencies,

define an array of libraries and paths, for example
AXIS2 = 'org.apache.axis2:axis2:jar:1.2'
LIB = ["jars/*.jar", AXIS2]

and change the compile directive to use with:

 ...

compile.with LIB# Added classpath dependencies
    package(:jar)
end

So this will compile and jar using both an external dependency, which will
be automatically downloaded, and your local libraries.  You can pretty much
run Java directly from inside Buildr too: Java.System.out.println("this
prints")
That might be an easier way fo running JAXB.


On Thu, Aug 26, 2010 at 6:53 PM, Mark Petrovic <ms...@gmail.com> wrote:

> Hi.  I'm new to Buildr, coming from Ant and Maven.  I've read the black
> Buildr book, and now I'm attempting to do some simple stuff with the JAXB
> XJC task.  Here's what I have so far:
>
> ...
>    compile :xjc
>    package :jar, :id => 'vzapi'
>
>    task :xjc do
>          begin
>          ant('xjc') do |ant|
>            xjcOutput='target/generated-sources/xjc'
>            rm_rf "#{xjcOutput}"
>            mkdir_p "#{xjcOutput}"
>
>  t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
>            puts t
>            ant.taskdef :name=>"xjc",
> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
>            ant.xjc :schema=>"src/main/resources/c.xsd",
> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
>          end
>        end
>    end
>
> where you can see my horribly clumsy, two-left-foot attempts to put
> together a classpath for the Ant taskdef.  The JAXB jars are in
> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
>
> Can someone suggest the "Buildr way" to build this classpath?  I've studied
> the examples referred to here
> http://www.mail-archive.com/users@buildr.apache.org/msg01115.html but I'm
> still not quite getting it.  I'm learning Ruby as I go, having read the
> Pickaxe book, but where not a lot of it has sunk in yet.
>
> Thanks!
>
> --
> Mark Petrovic
>
>
>