AntBuilder 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2006 Nick Sieger <nick@nicksieger.com>
2
+ Copyright (c) 2006 Ola Bini <ola@ologix.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,24 @@
1
+ = AntBuilder -- Bringing the power of apache ant to JRuby
2
+
3
+ Write apache ant scripts in JRuby. AntBuilder is an implementation of the
4
+ Groovy language's AntBuilder. This is not a translation of the Groovy code,
5
+ but a from scratch implementation with some differences in style. Its built
6
+ on Jim Weirich's (ruby) Builder::XmlMarkup markup builder and Martin Pllu's
7
+ (java) leafcutter ant api.
8
+
9
+ AntBuilder is a sub project of jruby-extras at RubyForge.
10
+
11
+ == Using AntBuilder
12
+
13
+ See index.html in the docs directory.
14
+
15
+ == Contact
16
+
17
+ Author:: Tim Azzopardi
18
+ Email:: tim@tigerfive.com
19
+ Home Page:: http://onestepback.org
20
+ License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
21
+
22
+ The Leafcutter jar and source jar is included in this gem.
23
+ Leafcutter (https://leafcutter.dev.java.net/) is released
24
+ under the Apache Software License http://www.apache.org/LICENSE.txt.
@@ -0,0 +1,16 @@
1
+ Modify your CLASSPATH to include leafcutter.jar.
2
+ Modify your CLASSPATH to include log4j.jar
3
+
4
+ For convenience, AntBuilder includes leafcutter.jar. (https://leafcutter.dev.java.net/)
5
+
6
+ Note that leafcutter.jar includes all the ant 1.6.5 jars except xercesImpl.jar
7
+ and xml-apis.jar.
8
+
9
+ (If you want to use the 'javac' ant task to compile java code, then a java runtime
10
+ is not enough. You will also need to modify your CLASSPATH environment variable to
11
+ include a tools.jar from your java JDK.)
12
+
13
+ (If you want to use the 'junit' ant task to run junit tests, then you will also need
14
+ to modify your CLASSPATH environment variable to include a junit.jar.)
15
+
16
+
Binary file
@@ -0,0 +1,4 @@
1
+ log4j.rootLogger=INFO, A1
2
+ log4j.appender.A1=org.apache.log4j.ConsoleAppender
3
+ log4j.appender.A1.layout=org.apache.log4j.PatternLayout
4
+ log4j.appender.A1.layout.ConversionPattern=......%m%n
@@ -0,0 +1,517 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
+ <HTML>
3
+ <HEAD>
4
+ <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
5
+ <TITLE></TITLE>
6
+ <META NAME="GENERATOR" CONTENT="OpenOffice.org 2.0 (Win32)">
7
+ <META NAME="AUTHOR" CONTENT="Tim Azzopardi">
8
+ <META NAME="CREATED" CONTENT="20051130;81967">
9
+ <META NAME="CHANGEDBY" CONTENT="Tim Azzopardi">
10
+ <META NAME="CHANGED" CONTENT="20060330;23532238">
11
+ <STYLE>
12
+ <!--
13
+ @page { size: 21cm 29.7cm }
14
+ -->
15
+ </STYLE>
16
+ </HEAD>
17
+ <BODY LANG="en-US" DIR="LTR">
18
+ <H1>AntBuilder ant scripts in JRuby</H1>
19
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>***********************************************************************************************</FONT></FONT></P>
20
+ <P STYLE="margin-bottom: 0cm"><FONT COLOR="#ff0000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>Warning...This
21
+ is still alpha code... 31<SUP>th</SUP> March 2006 although its
22
+ approaching a beta release. The api is almost stable.</FONT></FONT></FONT></P>
23
+ <P STYLE="margin-bottom: 0cm"><BR>
24
+ </P>
25
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>***********************************************************************************************</FONT></FONT></P>
26
+ <H2>Project Home Page at rubyforge.org</H2>
27
+ <P><A HREF="http://rubyforge.org/projects/antbuilder/">http://rubyforge.org/projects/antbuilder/</A></P>
28
+ <H2>Quick start for Windows XP</H2>
29
+ <UL>
30
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Windows
31
+ XP is the only currently tested environment. If you're a unix or
32
+ macox user, you have initiative<SPAN STYLE="background: transparent"><SUP>tm</SUP></SPAN>
33
+ so you'll figure it out.</FONT></P>
34
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">The
35
+ Sun Java JDK version 5 is the only tested environment. But Sun JDK
36
+ 1.4.2 also works. </FONT>
37
+ </P>
38
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">First
39
+ do a JRuby install:</FONT></P>
40
+ <UL>
41
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">You'll
42
+ need a Java JDK &gt;= 1.4 and you'll need to set up a JAVA_HOME
43
+ environment variable.</FONT></P>
44
+ <LI><P STYLE="margin-bottom: 0cm"><SPAN STYLE="background: transparent"><SPAN STYLE="text-decoration: none"><FONT FACE="Times New Roman, serif"><FONT COLOR="#000000">Get
45
+ the JRuby 0.8.2 (or later) binary distribution from
46
+ </FONT></FONT></SPAN></SPAN><A HREF="http://prdownloads.sourceforge.net/jruby/jruby-src-0.8.2.tar.gz?download"><SPAN STYLE="background: transparent"><SPAN STYLE="text-decoration: none"><FONT FACE="Times New Roman, serif"><FONT COLOR="#000000">http://prdownloads.sourceforge.net/jruby/jruby-src-0.8.2.tar.gz?download</FONT></FONT></SPAN></SPAN></A><SPAN STYLE="background: transparent"><SPAN STYLE="text-decoration: none"><FONT COLOR="#000000">
47
+ <FONT FACE="Times New Roman, serif">and unzip to (for example)
48
+ c:\apps </FONT></FONT></SPAN></SPAN>
49
+ </P>
50
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Set
51
+ up an environment variable JRUBY_HOME to (for example)
52
+ JRUBY_HOME=C:\apps\jruby-0.8.2</FONT></P>
53
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Modify
54
+ your PATH environment variable to include %JRUBY_HOME%\bin</FONT></P>
55
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Open
56
+ up a command prompt (Start Run... cmd.exe) and type &quot;jruby
57
+ --version&quot;. You should see &quot;ruby 1.8.2 (0) [java]&quot;. </FONT>
58
+ </P>
59
+ </UL>
60
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Then
61
+ do an AntBuilder install:</FONT></P>
62
+ <UL>
63
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Download
64
+ the AntBuilder tarball from <A HREF="http://rubyforge.org/frs/?group_id=1142"><FONT FACE="Times New Roman, serif">http://rubyforge.org/frs/?group_id=1142</FONT></A>
65
+ and unzip it to, for example, C:\dev </FONT>
66
+ </P>
67
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>Copy
68
+ the AntBuilder 'builder' directory to the lib\ruby\site_ruby
69
+ directory of JRuby (create lib/ruby/site_ruby if necessary)</FONT></FONT></P>
70
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Modify
71
+ your CLASSPATH environment variable (or add it if it doesn't exist
72
+ yet) to include leafcutter.jar. Please note that leafcutter.jar
73
+ includes all the ant 1.6.5 jars except xercesImpl.jar and
74
+ xml-apis.jar. </FONT>
75
+ </P>
76
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Open
77
+ up a command prompt (Start Run... cmd.exe) and cd to where you
78
+ unzipped the AntBuilder tarbar e.g. &quot;cd
79
+ \dev\antbuilder\AntBuilder\examples\basic&quot; and run &quot;jruby
80
+ check_install.rb&quot; and you should see &quot;AntBuilder
81
+ installed ok&quot;</FONT></P>
82
+ </UL>
83
+ </UL>
84
+ <P STYLE="margin-bottom: 0cm"><BR>
85
+ </P>
86
+ <P STYLE="margin-bottom: 0cm">Common optional extras:</P>
87
+ <UL>
88
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">If
89
+ you want to use the 'javac' ant task to compile java code, then a
90
+ java runtime is not enough. You will also need to modify your
91
+ CLASSPATH environment variable to include a tools.jar from your java
92
+ JDK.</FONT></P>
93
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">If
94
+ you want to use the 'junit' ant task to run junit tests, then you
95
+ will also need to modify your CLASSPATH environment variable to
96
+ include a junit.jar.</FONT></P>
97
+ </UL>
98
+ <P STYLE="margin-bottom: 0cm"><BR>
99
+ </P>
100
+ <H2>Getting Started with your own JRuby ant scripts</H2>
101
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>See
102
+ the examples: </FONT></FONT>
103
+ </P>
104
+ <P STYLE="margin-bottom: 0cm"><BR>
105
+ </P>
106
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>examples/basic/check_install.rb</FONT></FONT></P>
107
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>examples/jruby/build.rb</FONT></FONT></P>
108
+ <P STYLE="margin-bottom: 0cm"><BR>
109
+ </P>
110
+ <P STYLE="margin-bottom: 0cm"><BR>
111
+ </P>
112
+ <H2 STYLE="margin-top: 0cm; margin-bottom: 0cm">To subclass or not to
113
+ subclass AntBuilder</H2>
114
+ <P STYLE="margin-bottom: 0cm"><BR>
115
+ </P>
116
+ <P STYLE="margin-bottom: 0cm">If you do not want to subclass
117
+ AntBuilder then you have to say:</P>
118
+ <PRE STYLE="margin-left: 2cm">require 'builder/antbuilder'
119
+
120
+ <FONT COLOR="#ff0000">ant</FONT> = Builder::AntBuilder.new
121
+ ...
122
+ <B><FONT COLOR="#ff0000">ant</FONT>.</B>copy(:todir =&gt; @jruby_classes_dir) {
123
+ <B><FONT COLOR="#ff0000">ant</FONT>.</B>fileset(:dir =&gt; @src_dir, :includes =&gt; &quot;**/*.properties&quot;)
124
+ }</PRE><P STYLE="margin-bottom: 0cm">
125
+ (You don't have to use the name 'ant'; its just an example)</P>
126
+ <P STYLE="margin-bottom: 0cm"><BR>
127
+ </P>
128
+ <P STYLE="margin-bottom: 0cm">If you *do* subclass AntBuilder then
129
+ you can don't have to use the 'ant' prefix all over the place.</P>
130
+ <P STYLE="margin-bottom: 0cm"><BR>
131
+ </P>
132
+ <PRE STYLE="margin-left: 2cm">class Build &lt; Builder::AntBuilder
133
+
134
+ def compile_tasks # Builds the Ant tasks that we need later on in the build
135
+ ...
136
+ copy(:todir =&gt; @jruby_classes_dir) {
137
+ fileset(:dir =&gt; @src_dir, :includes =&gt; &quot;**/*.properties&quot;)
138
+ }
139
+ end
140
+
141
+ ...
142
+
143
+ end</PRE><H2>
144
+ Ant properties and Ant property Files
145
+ </H2>
146
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>After
147
+ every ant command is executed, AntBuilder retrieves the ant
148
+ properties that have changed since the last command and copies them
149
+ to ruby instance variables. (Remember that ant properties can only be
150
+ assigned once).</FONT></FONT></P>
151
+ <P STYLE="margin-bottom: 0cm"><BR>
152
+ </P>
153
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>Properties
154
+ such as &quot;<FONT COLOR="#000000">build.dir&quot; are converted to
155
+ @build_dir. Any characters in the ant property that are not legal in
156
+ a ruby instance variable are converted to underscores.</FONT></FONT></FONT></P>
157
+ <P STYLE="margin-bottom: 0cm"><BR>
158
+ </P>
159
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>In
160
+ ant xml build files you will often see:</FONT></FONT></P>
161
+ <P STYLE="margin-bottom: 0cm"><BR>
162
+ </P>
163
+ <UL>
164
+ <LI><P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>&lt;property
165
+ file=&quot;default.build.properties&quot;/&gt;</FONT></FONT></FONT></P>
166
+ </UL>
167
+ <P STYLE="margin-bottom: 0cm"><BR>
168
+ </P>
169
+ <P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>You
170
+ can try this in AntBulder with </FONT></FONT></FONT>
171
+ </P>
172
+ <P STYLE="margin-bottom: 0cm"><BR>
173
+ </P>
174
+ <UL>
175
+ <LI><P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>ant.property(:file=&gt;&quot;default.build.properties&quot;)
176
+ # you can omit the &quot;ant.&quot; if you are subclassing
177
+ AntBuilder</FONT></FONT></FONT></P>
178
+ </UL>
179
+ <P STYLE="margin-bottom: 0cm"><BR>
180
+ </P>
181
+ <P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>If
182
+ the file contains</FONT></FONT></FONT></P>
183
+ <P STYLE="margin-left: 2cm; margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>build.dir=build</FONT></FONT></FONT></P>
184
+ <P STYLE="margin-left: 2cm; margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>classes.dir=${build.dir}/classes</FONT></FONT></FONT></P>
185
+ <P STYLE="margin-left: 2cm; margin-bottom: 0cm"><BR>
186
+ </P>
187
+ <P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>Then
188
+ the ruby instance variables defined will be the equivalent of:</FONT></FONT></FONT></P>
189
+ <P STYLE="margin-left: 2cm; margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>@build_dir=&quot;build&quot;</FONT></FONT></FONT></P>
190
+ <P STYLE="margin-left: 2cm; margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>@classes_dir=&quot;build/classes&quot;</FONT></FONT></FONT></P>
191
+ <P STYLE="margin-bottom: 0cm"><BR>
192
+ </P>
193
+ <P STYLE="margin-bottom: 0cm">(Of course you could always define
194
+ build_dir and classes_dir rather than build.dir and classes.dir in
195
+ the <FONT FACE="Times New Roman, serif"><FONT COLOR="#000000">default.build.properties
196
+ file)</FONT></FONT></P>
197
+ <P STYLE="margin-bottom: 0cm"><BR>
198
+ </P>
199
+ <P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>You
200
+ cannot use the ant properties in the ant commands in the ${property}
201
+ form. ${property} works in ant xml files and replaced by the ant xml
202
+ file preprocessor. </FONT></FONT></FONT>
203
+ </P>
204
+ <P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>But
205
+ you can use the #{@property} form instead in JRuby code. There are a
206
+ couple of exceptions &ndash; firstly the ant.property task will
207
+ process ant properties of the form ${property} in the properties file
208
+ as shown above (<FONT SIZE=2><FONT FACE="Courier New, monospace">classes.dir=<B>${build.dir}</B>/classes</FONT></FONT>).</FONT></FONT></FONT></P>
209
+ <P STYLE="margin-bottom: 0cm"><BR>
210
+ </P>
211
+ <P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>Another
212
+ case where 'native' ant properties can be used is shown here:</FONT></FONT></FONT></P>
213
+ <P STYLE="margin-bottom: 0cm"><BR>
214
+ </P>
215
+ <PRE STYLE="margin-left: 2cm; margin-bottom: 0.5cm">available(:property=&gt;&quot;jdk1.4+&quot;, :classname=&gt;&quot;java.lang.CharSequence&quot;)
216
+ patternset(:id =&gt; &quot;java.src.pattern&quot;) {
217
+ exclude(:unless=&gt;&quot;jdk1.4+&quot;, :name=&gt;&quot;**/AstPersistenceDelegates.java&quot;)
218
+ }</PRE><P>
219
+ <BR><BR>
220
+ </P>
221
+ <P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>The
222
+ above code will also create a ruby instance variable called @jdk1_4_</FONT></FONT></FONT></P>
223
+ <H2>Ant dependencies</H2>
224
+ <UL>
225
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Ant
226
+ build files were always <A HREF="http://c2.com/cgi/wiki?AntPractices"><FONT FACE="Times New Roman, serif">originally
227
+ intended to be declarative</FONT></A> using &lt;target name=&quot;xxx&quot;
228
+ depends=&quot;aaa, bbb, ccc&quot;&gt; extensivly where the
229
+ dependencies are only exected once per build.</FONT></P>
230
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>AntBuilder
231
+ fully supports this declarative style of ant usage using the depends
232
+ method. See the example in examples/jruby/build.rb </FONT></FONT>
233
+ </P>
234
+ </UL>
235
+ <P STYLE="margin-bottom: 0cm"><BR>
236
+ </P>
237
+ <PRE STYLE="margin-left: 2cm; page-break-before: always">def compile # Compile the source files for the project
238
+ <B>depends </B>:compile_tasks, :check_for_optional_packages
239
+ javac(
240
+ :destdir =&gt; @jruby_classes_dir,
241
+ :debug =&gt; &quot;true&quot;,
242
+ :source=&gt; @javac_version,
243
+ :classpathref =&gt; &quot;build.classpath&quot;
244
+ ) {
245
+ src(:path =&gt; @src_dir)
246
+ patternset(:refid =&gt; &quot;java.src.pattern&quot;)
247
+ }
248
+ end</PRE>
249
+ <UL>
250
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>Circular
251
+ dependencies are detected dynamically rather than statically as ant
252
+ does. </FONT></FONT>
253
+ </P>
254
+ </UL>
255
+ <P STYLE="margin-bottom: 0cm"><BR>
256
+ </P>
257
+ <H2 STYLE="margin-top: 0cm; margin-bottom: 0cm">Taskdefs</H2>
258
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">The
259
+ ant taskdef task can be used but the classpath attribute is ignored.
260
+ If you actually want to use the declared task, you have to make sure
261
+ that the class is on the classpath.</FONT></P>
262
+ <P STYLE="margin-bottom: 0cm"><BR>
263
+ </P>
264
+ <PRE STYLE="margin-left: 2cm">taskdef(:name =&gt;&quot;jruby_serialize&quot;, :classname=&gt;&quot;org.jruby.util.ant.JRubySerialize&quot;) {
265
+ classpath(:path =&gt; @jruby_classes_dir) # ignored
266
+ }
267
+ ...
268
+ jruby_serialize(:destdir =&gt; @jruby_classes_dir, :verbose=&gt;&quot;true&quot;) {
269
+ fileset(:dir =&gt; @src_dir) {
270
+ patternset(:refid=&gt;&quot;ruby.src.pattern&quot;)
271
+ }
272
+ }</PRE><H2>
273
+ run_targets_from_command_line</H2>
274
+ <P>If you subclass AntBuilder then you can end the class definition
275
+ with run_targets_from_command_line and it will run tasks from the
276
+ command line like ant does.</P>
277
+ <PRE>class Build &lt; Builder::AntBuilder
278
+
279
+ def compile_all
280
+ ...
281
+ end
282
+
283
+ def clean
284
+ ...
285
+ end
286
+
287
+ ...
288
+ run_targets_from_command_line
289
+
290
+ end</PRE><P>
291
+ Then from the command line you could say:</P>
292
+ <PRE STYLE="margin-bottom: 0.5cm">jruby build.rb clean compile_all</PRE><H2>
293
+ Current Limitations and Gotchas</H2>
294
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">The
295
+ AntBuilder project uses the excellent </FONT><A HREF="https://leafcutter.dev.java.net/"><FONT FACE="Times New Roman, serif">leafcutter
296
+ api</FONT></A> <FONT FACE="Times New Roman, serif">and is influenced
297
+ by its features:</FONT></P>
298
+ <UL>
299
+ <UL>
300
+ <UL>
301
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Simple
302
+ </FONT><A HREF="http://ant.apache.org/manual/using.html#references"><B><FONT FACE="Times New Roman, serif">ant
303
+ references</FONT></B></A> <FONT FACE="Times New Roman, serif">via
304
+ the ant &quot;refid&quot; are supported. See build.rb for
305
+ examples.</FONT></P>
306
+ </UL>
307
+ </UL>
308
+ </UL>
309
+ <P STYLE="margin-bottom: 0cm"><BR>
310
+ </P>
311
+ <UL>
312
+ <UL>
313
+ <UL>
314
+ <LI><PRE STYLE="margin-bottom: 0.5cm"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>Some Ant tasks are configured by text content rather than attributes, for example the &quot;echo&quot; task, the &quot;mail&quot; &quot;message&quot; attribute, and the &quot;javadoc&quot; &quot;bottom&quot; attribute. For example for the equivalent of &lt;echo&gt;hello&lt;/echo&gt; in AntBuilder: ant.echo(:text=&gt;&quot;hello&quot;)</FONT></FONT></PRE>
315
+ </UL>
316
+ </UL>
317
+ </UL>
318
+ <P STYLE="margin-bottom: 0cm"><BR>
319
+ </P>
320
+ <P STYLE="margin-bottom: 0cm"><BR>
321
+ </P>
322
+ <H2 STYLE="margin-top: 0cm; margin-bottom: 0cm">Common AntBuilder
323
+ Errors</H2>
324
+ <UL>
325
+ <LI><P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>&quot;<B>wrong
326
+ number of arguments&quot;</B></FONT></FONT></FONT></P>
327
+ </UL>
328
+ <UL>
329
+ <LI><P STYLE="margin-bottom: 0cm; text-decoration: none"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>For
330
+ example, you get an error:</FONT></FONT></FONT></P>
331
+ <UL>
332
+ <LI><P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3><U>foo..rb:283</U>:in
333
+ `test': wrong number of arguments(1 for 0) (ArgumentError)</FONT></FONT></FONT></P>
334
+ </UL>
335
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">A
336
+ common explanation is that you have defined a method &quot;test&quot;
337
+ (equivalent to an ant target called test), and somewhere else you
338
+ are also trying to call the ant task called &quot;test&quot;. This
339
+ call to, what you think is the ant task &quot;test&quot;, is
340
+ interpreted as a call to the method test with some parameters. As
341
+ your defined method does not (usually) take parameters, the jruby
342
+ interpreter gives you the above error.</FONT></P>
343
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">The
344
+ solution is simply to call you method something that doesn't clash
345
+ with an and task name, such as do_test.</FONT></P>
346
+ </UL>
347
+ <P STYLE="margin-bottom: 0cm"><BR>
348
+ </P>
349
+ <UL>
350
+ <LI><P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3><B>TaskRunnerException:
351
+ Can't determine class for 'create_api_docs' (NativeException)</B></FONT></FONT></FONT></P>
352
+ <LI><P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>Common
353
+ explanation: you are trying to call a method called &quot;create_apidocs&quot;
354
+ that you have defined in the build file, but you have got the name
355
+ wrong, and antbuilder tries to get leafcutter to run it as an ant
356
+ task.</FONT></FONT></FONT></P>
357
+ <LI><P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><FONT SIZE=3>The
358
+ solution is simply to call you method using the correct name.</FONT></FONT></FONT></P>
359
+ </UL>
360
+ <P STYLE="margin-bottom: 0cm"><BR>
361
+ </P>
362
+ <UL>
363
+ <LI><P STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Times New Roman, serif"><B>junitreport:
364
+ </B>If this task complains about not being able to find xalan you
365
+ may have (a) a version of ant &lt; 1.6.0 on the classpath before
366
+ leafcutter.jar and (b) running under java5. </FONT></FONT>
367
+ </P>
368
+ </UL>
369
+ <P STYLE="margin-bottom: 0cm"><BR>
370
+ </P>
371
+ <H2>How Does It Work?</H2>
372
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">AntBuilder
373
+ is just a </FONT><A HREF="http://rubyforge.org/cgi-bin/viewcvs.cgi/*checkout*/AntBuilder/builder/antbuilder.rb?rev=HEAD&amp;root=antbuilder"><FONT FACE="Times New Roman, serif">tiny</FONT></A>
374
+ <FONT FACE="Times New Roman, serif">bit of JRuby glue, that sticks
375
+ together </FONT><A HREF="http://ant.apache.org/"><FONT FACE="Times New Roman, serif">apache-ant</FONT></A><FONT FACE="Times New Roman, serif">,
376
+ </FONT><A HREF="https://leafcutter.dev.java.net/"><FONT FACE="Times New Roman, serif">leafcutter</FONT></A>
377
+ <FONT FACE="Times New Roman, serif">and </FONT><A HREF="http://builder.rubyforge.org/"><FONT FACE="Times New Roman, serif">Builder::XMLBase</FONT></A><FONT FACE="Times New Roman, serif">.
378
+ It relies heavily on Builder::XMLBase to generate the correct syntax
379
+ for the leafcutter ant api.</FONT></P>
380
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Very
381
+ briefly: When you say &quot;echo(:text =&gt; 'starting-build')&quot;
382
+ there is no such method as echo defined in the class, and this event
383
+ gets trapped in Builder::XMLBase. The missing method and its
384
+ parameters are then converted to a string &quot;echo
385
+ text=starting-build&quot; by XMLBase and the AntBuilder subclass.
386
+ This string is compatible with the leafcutter api syntax for
387
+ executing ant code. The string is passed over to leafcutter for
388
+ execution.</FONT></P>
389
+ <P STYLE="margin-bottom: 0cm"><BR>
390
+ </P>
391
+ <H2>Background</H2>
392
+ <P><FONT FACE="Times New Roman, serif">First came Groovy's markup
393
+ concept: See <A HREF="http://groovy.codehaus.org/GroovyMarkup">http://groovy.codehaus.org/GroovyMarkup</A>
394
+ which was an inspired idea. This inspired Ruby's Builder(and
395
+ ::XmlMarkup) (<A HREF="http://builder.rubyforge.org/">http://builder.rubyforge.org/</A>).
396
+ See
397
+ <A HREF="http://www.onestepback.org/index.cgi/Tech/Ruby/BuilderObjects.rdoc">http://www.onestepback.org/index.cgi/Tech/Ruby/BuilderObjects.rdoc</A>)
398
+ for the story and the subsequent <A HREF="http://www.onestepback.org/index.cgi/Tech/Ruby/StayingSimple.rdoc">namespace
399
+ issue solution</A> which <A HREF="http://docs.codehaus.org/display/GroovyJSR/Closure+and+Markup+name+resolution+proposal">stung
400
+ Groovy in the tail </A>big time recently. Basically the Builder
401
+ concept can be applied to any semi hierarchical structure, such as
402
+ Swing gui construction and ant scripts. Groovy uses this concept to
403
+ very good effect with its AntBuilder, SwingBuilder, and SWTBuilder.
404
+ See <A HREF="http://www.javaworld.com/javaworld/jw-10-2004/jw-1004-groovy.html">http://www.javaworld.com/javaworld/jw-10-2004/jw-1004-groovy.html</A>
405
+ for an excellent example of the Groovy AntBuilder concept in
406
+ practice. </FONT>
407
+ </P>
408
+ <P STYLE="margin-bottom: 0cm"><BR>
409
+ </P>
410
+ <H2>Other Alternatives to AntBuilder in the Java world</H2>
411
+ <UL>
412
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Use
413
+ ant itself as nature intended!</FONT></P>
414
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Use
415
+ the excellent java leafcutter api:</FONT></P>
416
+ </UL>
417
+ <P STYLE="margin-left: 2cm; margin-bottom: 0cm"><CODE><FONT SIZE=2><FONT FACE="Courier New, monospace">import
418
+ org.leafcutter.core.TaskRunner;</FONT></FONT></CODE></P>
419
+ <P STYLE="margin-left: 2cm; margin-bottom: 0cm"><CODE><FONT SIZE=2><FONT FACE="Courier New, monospace">public
420
+ class MyBuild {</FONT></FONT></CODE></P>
421
+ <P STYLE="margin-left: 4cm; margin-bottom: 0cm"><CODE><FONT SIZE=2><FONT FACE="Courier New, monospace">public
422
+ static void main(String[] args) {</FONT></FONT></CODE></P>
423
+ <P STYLE="margin-left: 6cm; margin-bottom: 0cm"><CODE><FONT SIZE=2><FONT FACE="Courier New, monospace">TaskRunner.run(&quot;copy
424
+ file=hello.txt tofile=world.txt overwrite=true&rdquo;);</FONT></FONT></CODE></P>
425
+ <P STYLE="margin-left: 4cm; margin-bottom: 0cm"><CODE><FONT SIZE=2><FONT FACE="Courier New, monospace">}</FONT></FONT></CODE></P>
426
+ <P STYLE="margin-left: 2cm; margin-bottom: 0cm"><CODE><FONT SIZE=2><FONT FACE="Courier New, monospace">}</FONT></FONT></CODE></P>
427
+ <UL>
428
+ <LI><P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Use
429
+ Groovy's AntBuilder</FONT></P>
430
+ </UL>
431
+ <P STYLE="margin-bottom: 0cm"><BR>
432
+ </P>
433
+ <H2>Other Alternatives to AntBuilder in the Ruby world</H2>
434
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Use
435
+ Rake</FONT></P>
436
+ <P STYLE="margin-bottom: 0cm"><BR>
437
+ </P>
438
+ <H2>Using the Ruby Eclipse plugin with JRuby (Experimental)</H2>
439
+ <P STYLE="margin-bottom: 0cm"><BR>
440
+ </P>
441
+ <P STYLE="margin-bottom: 0cm">Get eclipse 3.1 (or 3.2M3+)</P>
442
+ <P STYLE="margin-bottom: 0cm">Get the JRuby HEAD (The interpreter
443
+ from version 0.8.2 will NOT work in RDT)</P>
444
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Times New Roman, serif">Install
445
+ RDT nightly build from
446
+ </FONT><A HREF="http://rubyeclipse.sourceforge.net/nightlyBuild/updateSite/"><FONT FACE="Times New Roman, serif">http://rubyeclipse.sourceforge.net/nightlyBuild/updateSite/</FONT></A></P>
447
+ <P STYLE="margin-bottom: 0cm">Restart Eclipse</P>
448
+ <P STYLE="margin-bottom: 0cm">Windows-Preferences-Ruby-Installed-Interpreters
449
+ and add the JRuby jruby.bat as an interpreter.</P>
450
+ <P STYLE="margin-bottom: 0cm"><BR>
451
+ </P>
452
+ <P STYLE="margin-bottom: 0cm"><IMG SRC="index_html_7cda332d.jpg" NAME="graphics1" ALIGN=LEFT WIDTH=901 HEIGHT=692 BORDER=0><BR>
453
+ </P>
454
+ <P STYLE="margin-top: 0.42cm; page-break-after: avoid"><BR><BR>
455
+ </P>
456
+ <P STYLE="margin-top: 0.42cm; page-break-before: always"><BR><BR>
457
+ </P>
458
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
459
+ </P>
460
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
461
+ </P>
462
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
463
+ </P>
464
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
465
+ </P>
466
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
467
+ </P>
468
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
469
+ </P>
470
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
471
+ </P>
472
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
473
+ </P>
474
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
475
+ </P>
476
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
477
+ </P>
478
+ <P STYLE="margin-top: 0.42cm"><BR><BR>
479
+ </P>
480
+ <H2><FONT FACE="Times New Roman, serif"><BR></FONT>Eclipse 3.1
481
+ (Windows XP) AntBuilder Developer Setup</H2>
482
+ <P STYLE="margin-bottom: 0cm">Get eclipse 3.1 or 3.2M3+</P>
483
+ <P STYLE="margin-bottom: 0cm">Get the JRuby HEAD (The interpreter
484
+ from version 0.8.2 will NOT work in RDT)</P>
485
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier New, monospace">Install
486
+ RDT nightly build from
487
+ </FONT><A HREF="http://rubyeclipse.sourceforge.net/nightlyBuild/updateSite/"><FONT FACE="Courier New, monospace">http://rubyeclipse.sourceforge.net/nightlyBuild/updateSite/</FONT></A></P>
488
+ <P STYLE="margin-bottom: 0cm">Restart Eclipse</P>
489
+ <P STYLE="margin-bottom: 0cm">Windows-Preferences-Ruby-Installed-Interpreters
490
+ and add the JRuby jruby.bat as an interpreter.</P>
491
+ <P STYLE="margin-bottom: 0cm">Install cygwin (including ssh from
492
+ category &ldquo;Net&rdquo; - ssltools)</P>
493
+ <P STYLE="margin-bottom: 0cm">Open eclipse
494
+ </P>
495
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier New, monospace">Menu-Window-Preferences-Team-CVS-Ext
496
+ Connection Method</FONT></P>
497
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier New, monospace">CVS_RSH:=C:\cygwin\bin\ssh.exe</FONT></P>
498
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier New, monospace">Parameters:
499
+ -l anonymous rubyforge.org</FONT></P>
500
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier New, monospace">CVS
501
+ Server:cvs</FONT></P>
502
+ <P STYLE="margin-bottom: 0cm"><FONT FACE="Courier New, monospace">Then
503
+ open the CVS perspective and set up a new repository::
504
+ :extssh:</FONT><A HREF="mailto:anonymous@rubyforge.org"><FONT FACE="Courier New, monospace">anonymous@rubyforge.org</FONT></A><FONT FACE="Courier New, monospace">:/var/cvs/antbuilder</FONT></P>
505
+ <P STYLE="margin-bottom: 0cm">Expand HEAD and right click AntBuilder
506
+ and check out as project.</P>
507
+ <P STYLE="margin-bottom: 0cm">Run the examples
508
+ </P>
509
+ <P STYLE="margin-bottom: 0cm">If classes are missing, modify the
510
+ jruby.bat classpath</P>
511
+ <P STYLE="margin-bottom: 0cm"><BR>
512
+ </P>
513
+ <DL>
514
+ <DD STYLE="margin-bottom: 0.5cm"><FONT FACE="Times New Roman, serif"><BR><BR></FONT><BR><BR>
515
+ </DD></DL>
516
+ </BODY>
517
+ </HTML>