buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Boisvert <alex.boisv...@gmail.com>
Subject Re: ant refugees
Date Thu, 17 Sep 2009 17:49:59 GMT
Cool, I added your second example to the wiki:
http://cwiki.apache.org/confluence/display/BUILDR/How+to+call+Ant+scripts

alex


On Thu, Sep 17, 2009 at 12:27 AM, Gilles Gaillard <
gillouxGaillard@wanadoo.fr> wrote:

> Hi Alex,
>
> Thanks for the quick answer!
>
> For the record, find below at the end of my reply what I did to invoke
> ant targets from existing ant scripts:
> - from a Ruby script (without using buildr).
> - from inside a regular buildfile for buildr (your code with a minor
>  correction  (Main.main)  - just showing where to insert it)
> Note that there is a little trick to fix the classpath is the sample
> calling
> antwrap alone. I think that this would be fixed in a cleaner way by taking
> as example the buildr code in buildr/java/rjb.rb
>
> My opinion is that the ability to use existing ant scripts could ease the
> migration to buildr by enabling to keep on using some specific targets, but
> I'm not there yet ;-)
>
> Cheers,
> -- Gilles
>
> =================
> build-with-ant.rb
> =================
> require 'rjb'
> require 'antwrap'
>
> # initialize the ant library
> # NOTE: this also load the JVM via JAVA_HOME/jre/bin/xx/jvm.dll
> #       The drawback is that the javac target must:
> #       - be forked in order to be able to specify the path to the javac
> compiler
> #       - the attribute 'executable' must be set
> #       Additional notes: see below
>
> Antwrap::AntwrapClassLoader::load_ant_libs('F:/dev_aspera/farm/ant/apache-ant-1.7.1')
>
> # This does not work I guess 'load' can be called once only (to be checked)
> # Antwrap::AntwrapClassLoader::load_ant_libs('F:/java/jdk1.5.0_09')
> # Adding the following line in antwrap_utilities.rb solves the problem
> # jars << 'F:/java/jdk1.5.0_09/lib/tools.jar'
>
> # load needed java classes - see gems/Antwrap-0.7.0/lib/rjb_modules.rb
> Main = Rjb::import("org.apache.tools.ant.Main")
> # simple call equivalent to invoke on the OS command-line: 'ant compile'
> Main.main([] << 'compile')
>
> alternatively to run a given target after loading the build.xml file:
>
> # now, instead we want to load a full project from a given build file
> # and invoke a list of targets as we do usually
> # add the following line to rjb_modules.rb
> # ProjectHelper = Rjb::import("org.apache.tools.ant.ProjectHelper")
>
> # then add the following methods to gems/Antwrap-0.7.0/lib/ant_project.rb
> =begin
>    def configure(fname)
>      file = Rjb::import('java.io.File')
>      f = file.new_with_sig('Ljava.lang.String;', fname)
>      Antwrap::ApacheAnt::ProjectHelper.configureProject(@project, f)
>    end
>
>    def executeTargets(args)
>      vector = Rjb::import('java.util.Vector')
>      string = Rjb::import('java.lang.String')
>      v = vector.new
>      args.each { |s| v.add(string.new_with_sig('Ljava.lang.String;', s)) }
>      @project.executeTargets(v)
>    end
> =end
> # then load the project from the build file and invoke a target
> project = Antwrap::AntProject.new
> project.configure("build.xml")
> project.executeTargets([] << 'compile')
>
>
> ====================
> buildfile for buildr
> ====================
> define "my-project" do
>
>  project.version = VERSION_NUMBER
>  project.group = GROUP
>  manifest["Implementation-Vendor"] = COPYRIGHT
>
>  task :antCall do
>    p 'calling ant..'
>    Java.org.apache.tools.ant.Main.main( ['-file', 'build2.xml',
> 'my-target'] )
>  end
> end
>
> then on the OS command line:
>
>> buildr test-buildr:antCall
>>
>
>
>
>
> Alex Boisvert a écrit :
>
>  Hi Gilles,
>>
>> On Sat, Sep 12, 2009 at 7:17 AM, Gilles Gaillard <
>> gillouxGaillard@wanadoo.fr
>>
>>> wrote:
>>>
>>
>>  I think I'm one of these ant 'refugees' you spoke about in your July mail
>>> exchanges.
>>>
>>> Since I noticed you didn't make any progress in publishing the page you
>>> were speaking
>>> about in your mails (I know free time is a rare thing ... but users like
>>> to
>>> see updates
>>> and news produced regularly ;-) I thought that the following questions
>>> could also help
>>> you to understand what kind of questions such a refugee could expect an
>>> answer to.
>>>
>>>
>> Yes, good initiative.  I'm sure it can help people reading this list or
>> searching the mailing list archive at a later time.
>>
>> So here the list of questions, divided in two parts:
>>
>>> 1. Basics
>>> - where does buildr expect to find ant itself
>>>
>>>
>> In your local Maven2 repository.  If it's not available, it will try to
>> download it from one of your configured remote repositories.
>>
>> - where does buildr expect to find ant scripts
>>
>> Buildr doesn't use ant scripts directly but there are several ways to
>> integrate with ant:
>>
>> 1) use ant tasks directly by using Antwrap (preferred)
>>
>>  Buildr.ant(name) do |ant|
>>    ant.copy :todir =>'foo' do
>>      ant.fileset :dir=>'bar'
>>    end
>>    ant.replace :file=>"foo.properties", :token=>"@foo@", :value=>'bar'
>>  end
>>
>> 2) call ant's main() directly using RJB
>>
>>  Java.org.apache.tools.ant.Main [options] [target]
>>
>> 3) invoke ant using java and Ruby's
>>
>> system('java -Dant.home=c:\ant org.apache.tools.ant.Main [options]
>> [target]
>> ')
>>
>> 4) invoke ant using ant's shell scripts
>>
>> system('ant -buildfile foo.xml')
>>
>> The last three allow you to call ant scripts directly.
>>
>>
>>
>>  - for syntactic reasons linked to ant history, I must currently keep on
>>> using ant-1.6.2
>>>  is that a blocker point - where do I specify the ant version I want to
>>> use
>>> ?
>>>
>>>
>> In buildr.yml, simply add:
>>
>> ant: 1.6.2
>>
>>
>> - my projects layout looks like the standard one you described but is not
>>
>>> exactly the same.
>>>  For example, the 'target' build directory is named here 'build'. Where
>>> in
>>> buildr can I
>>>  change the layout or the directory names ?
>>>
>>>
>> See http://buildr.apache.org/rdoc/classes/Buildr/Layout.html
>>
>>
>>  - As a first step wouln't it be better for my use-case to use ant-wrapper
>>> without buildr ?
>>>
>>>
>> Depends if you want to take multiple small steps and refactor in-between
>> or
>> one giant step and be done with it ;)
>>
>>
>>  2. Next steps
>>> As a next step, I would like to improve my build and reduce the
>>> complexity
>>> of scripts usage
>>> by implementing an upper layer by using buildr/ruby making all ant public
>>> targets available.
>>> Is that the way you expect ant users to proceed, what advices would you
>>> give me for that
>>> purpose ?
>>>
>>>
>> Personally, I don't see much gain in reducing complexity by moving to Rake
>> +
>> Antwrap alone.
>>
>> If your build fits Buildr's model of compile, package, test, etc. then I
>> would make the jump to Buildr directly.
>>
>> Perhaps a good approach is to try on one project and refine the approach
>> until you've gotten the significant gains (productivity, complexity, ...)
>> before you move to other projects.
>>
>> Last note, I would have expected to find an 'Overview' page somewhere
>>
>>> between 'Getting Started'
>>> and 'Projects' that gives an overview of the system and how it works.
>>>
>>>
>> Agreed.  We sort of assume familiarity with Maven2.  I'm working on
>> something that will address some of this but it's not ready yet....
>>
>> alex
>>
>>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message