ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <peter.kitt.rei...@gmail.com>
Subject Re: <script> and (j)ruby !?
Date Tue, 15 Aug 2006 16:21:24 GMT
Fair enough.
I have found out how to use File in jruby, so
your example looks something like this:

        <property name="ant.working.dir" location="."/>
        <script language="ruby"><![CDATA[
          def get_prop(name)
              ret = $project.getProperty(name)
              return ret ? ret : "null"
          end
          # The next line exposes Java's File as JFile
          include_class("java.io.File") { |pkg, name| "J" + name }
          echoTask = $project.createTask "echo"
          filename = $project.getProperty("ant.working.dir") +
"/diffinfo.html"
          echoTask.setFile(JFile.new(filename))
          echoTask.setAppend(false) # do not want to append to the file
          echoTask.addText("<HTML><HEAD></HEAD><BODY><FONT
face='ARIAL'>"+"\n");
          echoTask.addText("<b>Hostname =" +
           "</b>"+ get_prop("host.name")+ "<br><br>\n\n");
          fs = $project.createDataType("fileset");
          fs.setDir(JFile.new("."))
          ds = fs.getDirectoryScanner($project);
          ds.getIncludedFiles().each() do |file|
             echoTask.addText("<b>" + file + "</b><br>\n")
          end
          echoTask.addText("</FONT></BODY></HTML>");
          echoTask.execute();
]]>
        </script>

On 8/14/06, Gilbert Rebhan <ant@schillbaer.de> wrote:
>
> Hi Peter,
>
> thanks a lot for your snippets !!, that
> helps me starting with jruby+ant
>
> > Check the ant manual!
> >
> > Example:
> >
> >    <script language="ruby">
> >      xmlfiles = Dir.new(".").entries.delete_if { |i| ! (i =~ /\.xml$/) }
> >      xmlfiles.sort.each { |i| $self.log(i) }
> >    </script>
>
> i already saw that, but doesn't deal with ant classes.
>
> > However, jruby is still new and a (large) number of things do not work,
> for
> > example I could not get (java.io.)File to work - it seems to clash with
> > ruby File. Also Thread.sleep(x) whines about accessing a private class.
> > jrunb is also a little slow at loading up (but improving).
> > some other examples:
>
> Didn't got so deep in it. I like ruby for several reasons (the elegance,
> nice syntax, GREAT community ...)
> And as i use it more and more i want to use it for ant related scripting
> too.I think jruby is the only ?! way to access ant interna via ruby as
> one has to interact with java.
>
> Regards, Gilbert
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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