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 Mon, 14 Aug 2006 17:34:20 GMT
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>

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:
swing: (note the include_class to get accees to non java.io.*, java.lang.*and
java.util.* classes)

        <script language="ruby"><![CDATA[
require 'java'

include_class "javax.swing.JFrame"
include_class "javax.swing.JLabel"

frame = JFrame.new("Hello Swing")
label = JLabel.new("Hello World")

frame.getContentPane().add(label)
frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
frame.pack()
frame.setVisible(true)

sleep 100
            ]]>
            </script>
      </target>

ant properties:
        <!-- overwrite and new property  (note the use of $ to access
project) -->
        <script language="ruby">
            # overwrite property (note: optional brackets)
            $project.setProperty "foobar", "bla"
            # new Property
            $project.setNewProperty("MyNewProperty", "blabla")
        </script>


ant task:
    <macrodef name="my-macro">
        <attribute name="y"/>
        <sequential>
            <echo>y is @{y}</echo>
        </sequential>
    </macrodef>

    <script language="ruby">
       myMacro = $project.createTask("my-macro")
       myMacro.setDynamicAttribute "y", "abc"
       myMacro.execute
    </script>

Some minuses:
  * File problem meantioned above
  * unable to write new java classes
     (this can be done in beanshell and groovy)
  * a bit slow to load
  (I have only played with it for a few minutes - so may be mistaken!)

I find using beanshell to be the best of the scripting languges
in ant at the moment.

Peter

On 8/14/06, Rebhan, Gilbert <Gilbert.Rebhan@huk-coburg.de> wrote:
>
>
> Hi,
>
> just learning ruby and i like it :-)
>
> Until now i used  javascript and groovy for scripting
>
> I'm searching examples of ruby in ant.
>
> f.e. what's the equivalent of =
>
> <script language="javascript">
> <![CDATA[
>    // overwrite property
>   project.setProperty("foobar","bla");
>   // new Property
>   project.setNewProperty("MyNewProperty", "blabla");
> ]]>
> </script>
>
> with jruby, means how do i access ant classes via (j)ruby ?
>
> or how to do things like =
>
> <script language="javascript">
> <![CDATA[
> echoTask = project.createTask("echo");
> echoTask.setFile(new
> java.io.File((project.getProperty("ant.working.dir"))+"/diffinfo.html"))
> ;
> echoTask.setAppend(true);
> echoTask.addText("<HTML><HEAD></HEAD><BODY><FONT face='ARIAL'>"+"\n");
> echoTask.addText("<b>Hostname =
> </b>"+(project.getProperty("host.name"))+ "<br><br>\n\n");
> ...
> ds = diffJars.getDirectoryScanner(project);
> files = ds.getIncludedFiles();
> for (var i = 0; i < files.length; i++)
> echoTask.addText("<b>"+files[i]+"</b><br>\n");
> echoTask.addText("</FONT></BODY></HTML>");
> echoTask.execute();
> ]]>
> </script>
>
>
> Any hints, ideas, examples, urls, docs ?
>
>
> 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