AntBuilder 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ cd \dev\DynamicFun\AntBuilder\docs
2
+ C:\cygwin\bin\scp.exe index.html rubyforge.org:/var/www/gforge-projects/antbuilder/
3
+ C:\cygwin\bin\scp.exe index_html_7cda332d.jpg rubyforge.org:/var/www/gforge-projects/antbuilder/
4
+ pause
@@ -0,0 +1,6 @@
1
+ require 'builder/antbuilder'
2
+
3
+ ant = Builder::AntBuilder.new
4
+ ant.echo(:text => "AntBuilder installed ok")
5
+
6
+
@@ -0,0 +1,361 @@
1
+ require 'builder/antbuilder'
2
+ require 'date'
3
+
4
+
5
+ class Build < Builder::AntBuilder
6
+
7
+ # JRuby is a pure Java implementation of a Ruby interpreter.
8
+
9
+ def initialize
10
+
11
+ super() # super(:debug=>true)
12
+
13
+ @basedir = "."
14
+
15
+ # First try to load machine-specific properties.
16
+ property(:file=>"build.properties")
17
+
18
+ #And then load the defaults. It seems backwards to set defaults AFTER setting local overrides, but that's how Ant works
19
+ property(:file=>"default.build.properties")
20
+
21
+ mkdir(:dir=> @lib_dir) # Not in original build
22
+
23
+ path(:id =>"build.classpath") {
24
+ fileset(:dir => @lib_dir, :includes => "*.jar", :excludes => "built_by_antbuilder.jruby.jar jruby.jar")
25
+ }
26
+
27
+ patternset(:id => "java.src.pattern") {
28
+ include(:name=>"**/*.java")
29
+ exclude(:unless=>"bsf.present", :name=>"org/jruby/javasupport/bsf/**/*.java")
30
+ exclude(:unless=>"jdk1.4+", :name=>"**/XmlAstMarshal.java")
31
+ exclude(:unless=>"jdk1.4+", :name=>"**/AstPersistenceDelegates.java")
32
+ }
33
+
34
+ patternset(:id => "ruby.src.pattern") {
35
+ include(:name=>"**/*.rb")
36
+ }
37
+
38
+ end
39
+
40
+ def init
41
+
42
+ depends # depends on nothing - (this will just print "init:")
43
+
44
+ # Copied from the original build.xml - ant properties will also be declared as ruby instance variables
45
+ xmlproperty(:file=>"build-config.xml", :keeproot=>"false", :collapseAttributes=>"true")
46
+
47
+ # Copied from the original build.xml as closely as possible. The ant property version.ruby will get copied to @version_ruby
48
+ # Note that you can't say ${version.ruby.major}.${version.ruby.minor} below
49
+ property(:name=>"version.ruby", :value=>"#{@version_ruby_major}.#{@version_ruby_minor}")
50
+ # equivalent to:
51
+ # property(:name=>"version_ruby", :value=>"#{@version_ruby_major}#{@version_ruby_minor}")
52
+ # equivalent to:
53
+ # @version_ruby = "#{@version_ruby_major}#{@version_ruby_minor}"
54
+
55
+ # The tstamp was tricky to get working : 'format' is a kernel module alias for sprintf - so we have to undefine 'format' explicitly
56
+ # (Or just use this instead: @build_date = Date.today.to_s)
57
+
58
+ tstamp{
59
+ format(:property=>"build.date", :pattern=>"yyyy-MM-dd")
60
+ }
61
+
62
+ # this will define a load of ruby instance variables called env_CLASSPATH, env_JAVA_HOME etc.
63
+ property(:environment=>"env")
64
+
65
+ @ruby_home = @env_RUBY_HOME if @ruby_home == nil
66
+ end
67
+
68
+ def prepare
69
+
70
+ depends :init
71
+
72
+ # Creates the directories needed for building
73
+ mkdir(:dir=> @build_dir)
74
+ mkdir(:dir=> @classes_dir)
75
+ mkdir(:dir=> @jruby_classes_dir)
76
+ mkdir(:dir=> @test_classes_dir)
77
+ mkdir(:dir=> @test_results_dir)
78
+ mkdir(:dir=> @html_test_results_dir)
79
+ mkdir(:dir=> @docs_dir)
80
+ mkdir(:dir=> @api_docs_dir)
81
+
82
+ end
83
+
84
+ def check_for_optional_packages # check if specific libs and versions are avaiable
85
+
86
+ depends :init
87
+
88
+ available(:property=>"jdk1.4+", :classname=>"java.lang.CharSequence")
89
+ available(:property=>"jdk1.5+", :classname=>"java.lang.StringBuilder")
90
+ available(:property=>"bsf.present", :classname=>"org.apache.bsf.BSFManager", :classpathref=>"build.classpath")
91
+ available(:property=>"junit.present", :classname=>"junit.framework.TestCase", :classpathref=>"build.classpath")
92
+ available(:property=>"cglib.present", :classname=>"net.sf.cglib.reflect.FastClass", :classpathref=>"build.classpath")
93
+
94
+ end
95
+
96
+ def compile_tasks # Builds the Ant tasks that we need later on in the build
97
+
98
+ depends :prepare
99
+
100
+ javac(
101
+ :destdir => @jruby_classes_dir,
102
+ :debug => "true",
103
+ :srcdir => @src_dir,
104
+ :includes => "org/jruby/util/ant/**/*.java" ,
105
+ :source => @javac_version,
106
+ :failonerror=>"true",
107
+ :classpathref => "build.classpath"
108
+ )
109
+
110
+ taskdef(:name =>"jruby_serialize", :classname=>"org.jruby.util.ant.JRubySerialize") {
111
+ # NB AntBuilder ignores the classpath entry because leafcutter does not use it, so you have to make sure that the class is on the claspath already
112
+ classpath(:path => @jruby_classes_dir)
113
+ }
114
+
115
+ copy(:todir => @jruby_classes_dir) {
116
+ fileset(:dir => @src_dir, :includes => "**/*.properties")
117
+ }
118
+
119
+ end
120
+
121
+ def compile # Compile the source files for the project
122
+
123
+ depends :compile_tasks, :check_for_optional_packages
124
+
125
+ javac(
126
+ :destdir => @jruby_classes_dir,
127
+ :debug => "true",
128
+ :source=> @javac_version
129
+ ) {
130
+ src(:path => @src_dir)
131
+ classpath(:refid => "build.classpath" )
132
+ patternset(:refid => "java.src.pattern")
133
+ }
134
+
135
+ end
136
+
137
+ def serialize # Serializes builting Ruby libraries into Java format
138
+
139
+ depends :compile
140
+
141
+ jruby_serialize(:destdir => @jruby_classes_dir, :verbose=>"true") {
142
+ fileset(:dir => @src_dir) {
143
+ patternset(:refid=>"ruby.src.pattern")
144
+ }
145
+ }
146
+ end
147
+
148
+
149
+ def serialize_rubylib # Serializes the core Ruby library into Java format
150
+
151
+ depends :compile
152
+
153
+ jruby_serialize(:destdir =>@jruby_classes_dir, :verbose=>"true") {
154
+ fileset(:dir =>"#{@ruby_home}/lib/ruby/1.8") {
155
+ patternset(:refid=>"ruby.src.pattern")
156
+ }
157
+ }
158
+ end
159
+
160
+ # Can't call this method "jar" because we want to call the ant jar task and they can't have the same name !!!!
161
+ def create_jar # Create the jruby.jar file
162
+
163
+ depends :serialize
164
+
165
+ jar(:destfile => "#{@lib_dir}/built_by_antbuilder.jruby.jar") {
166
+ fileset(:dir => "#{@jruby_classes_dir}") {
167
+ include(:name => "**/*.class")
168
+ include(:name => "**/*.properties")
169
+ include(:name => "**/*.rb.ast.ser")
170
+ exclude(:name => "org/jruby/util/ant/**/*.class")
171
+ }
172
+ manifest{
173
+ attribute(:name => "Built-By", :value => "AntBuilder")
174
+ attribute(:name => "Main-Class", :value => "org.jruby.Main")
175
+ }
176
+ }
177
+ end
178
+
179
+ def create_jar_standalone # Create a standalone jruby.jar file using libraries from RUBY_HOME/lib/ruby/1.8"
180
+
181
+ depends :serialize, :serialize_rubylib, :create_jar
182
+
183
+ end
184
+
185
+ def compile_test # Compile the unit tests
186
+
187
+ depends :create_jar
188
+
189
+ javac(
190
+ :destdir => @test_classes_dir,
191
+ :deprecation=>"true",
192
+ :debug => "true",
193
+ :source=> @javac_version,
194
+ :classpathref => "build.classpath"
195
+ ) {
196
+ classpath(){
197
+ # moved to classpathref: path refid="build.classpath"
198
+ # path(:refid =>"build.classpath")
199
+ pathelement(:path => "#{@jruby_classes_dir}")
200
+ pathelement(:path => "#{@lib_dir}/built_by_antbuilder.jruby.jar")
201
+ }
202
+ src(:path => @test_dir)
203
+ patternset(:refid => "java.src.pattern")
204
+ }
205
+
206
+ end
207
+
208
+ def copy_test_files
209
+ # Make tests fails available as resources
210
+ depends :compile_test
211
+
212
+ copy(:todir => @test_classes_dir) {
213
+ fileset(:dir => @test_dir, :includes => "org/**/*.rb")
214
+ }
215
+ end
216
+
217
+ def do_test #runs junit tests
218
+
219
+ depends :copy_test_files
220
+
221
+ junit(:fork=> "yes", :haltonfailure=> "false", :dir => @basedir) {
222
+ classpath{
223
+ # tried moving "path(:refid => "build.classpath")" to classpathref but its not supported in the junit task
224
+ # so just inline the "build.classpath" definition
225
+ fileset(:dir => @lib_dir, :includes => "*.jar", :excludes => "built_by_antbuilder.jruby.jar")
226
+ pathelement(:path => "#{@lib_dir}/built_by_antbuilder.jruby.jar")
227
+ pathelement(:path => "#{@test_classes_dir}")
228
+ pathelement(:path => "#{@test_dir}/requireTest.jar")
229
+ }
230
+ sysproperty(:key => "jruby_base", :value => @basedir)
231
+ sysproperty(:key => "jruby_home", :value => @basedir)
232
+ sysproperty(:key => "jruby_lib", :value => @lib_dir)
233
+
234
+ formatter(:type => "xml")
235
+ formatter(:type => "brief", :usefile => "false")
236
+
237
+ test(:name => "org.jruby.test.MainTestSuite", :todir => @test_results_dir)
238
+ }
239
+
240
+
241
+ # The following does not work with leafcutter so that code above is used. Not sure why this doesn't work.
242
+ # path(:id =>"test.classpath") {
243
+ # fileset(:dir => @lib_dir, :includes => "*.jar", :excludes => "built_by_antbuilder.jruby.jar jruby.jar")
244
+ # pathelement(:path => "#{@lib_dir}/built_by_antbuilder.jruby.jar")
245
+ # pathelement(:path => "#{@test_classes_dir}")
246
+ # pathelement(:path => "#{@test_dir}/requireTest.jar")
247
+ # }
248
+ #
249
+ # junit(:fork=> "yes", :haltonfailure=> "false", :dir => @basedir) {
250
+ # classpath(:refid => "test.classpath" )
251
+ # sysproperty(:key => "jruby_base", :value => @basedir)
252
+ # sysproperty(:key => "jruby_home", :value => @basedir)
253
+ # sysproperty(:key => "jruby_lib", :value => @lib_dir)
254
+ #
255
+ # formatter(:type => "xml")
256
+ # formatter(:type => "brief", :usefile => "false")
257
+ #
258
+ # test(:name => "org.jruby.test.MainTestSuite", :todir => @test_results_dir)
259
+ # }
260
+
261
+ junitreport(:todir => @test_results_dir){
262
+ fileset(:dir => @test_results_dir, :includes => "TEST-*.xml")
263
+ report(:format => "frames", :todir => @html_test_results_dir)
264
+ }
265
+ end
266
+
267
+ def create_apidocs # Creates the Java API docs
268
+
269
+ depends :prepare
270
+
271
+ javadoc(:destdir=> @api_docs_dir, :author=>"true", :version=>"true", :use=>"true", :windowtitle=>"JRuby API", :source => @javac_version) {
272
+ fileset(:dir => @src_dir)
273
+ fileset(:dir => @test_dir)
274
+ doctitle(
275
+ :text => "<h1>JRuby</h1>"
276
+ )
277
+ bottom(
278
+ :text => "<i>Copyright &#169; 2002-2005 JRuby Team. All Rights Reserved.</i>"
279
+ )
280
+ }
281
+ end
282
+
283
+ def dist_bin
284
+
285
+ depends :create_jar
286
+
287
+ tar(:destfile=>"jruby-bin-#{@version_jruby}.tar.gz", :compression=>"gzip") {
288
+ tarfileset(:dir => ".", :mode => "755", :prefix => "jruby_#{@version_jruby}") {
289
+ include(:name => "bin/**")
290
+ }
291
+ tarfileset(:dir=>".", :prefix=>"jruby_#{@version_jruby}") {
292
+ include(:name=>"lib/**")
293
+ include(:name=>"samples/**")
294
+ include(:name=>"docs/**")
295
+ include(:name=>"COPYING*")
296
+ include(:name=>"README")
297
+ # Just in case we have link to real ruby dist
298
+ exclude(:name=>"lib/ruby/**")
299
+ exclude(:name=>"lib/ant.jar")
300
+ }
301
+ }
302
+ end
303
+
304
+ def dist_src
305
+
306
+ depends :create_jar
307
+
308
+ tar(:destfile=>"jruby-src-#{@version_jruby}.tar.gz", :compression=>"gzip") {
309
+ tarfileset(:dir => ".", :mode => "755", :prefix => "jruby_#{@version_jruby}") {
310
+ include(:name => "bin/**")
311
+ }
312
+ tarfileset(:dir=>".", :prefix=>"jruby_#{@version_jruby}") {
313
+ include(:name=>"lib/**")
314
+ include(:name=>"samples/**")
315
+ include(:name=>"docs/**")
316
+ include(:name=>"src/**")
317
+ include(:name=>"test/**")
318
+ include(:name=>"build.xml")
319
+ include(:name=>"build-config.xml")
320
+ include(:name=>"COPYING*")
321
+ include(:name=>"README")
322
+ include(:name=>".project")
323
+ include(:name=>".classpath")
324
+ include(:name=>"default.build.properties")
325
+ # Just in case we have link to real ruby dist
326
+ exclude(:name=>"lib/ruby/**")
327
+ exclude(:name=>"lib/ant.jar")
328
+ }
329
+ }
330
+ end
331
+
332
+ def dist
333
+ depends :dist_bin, :dist_src
334
+ end
335
+
336
+ def clean # clean almost everything
337
+
338
+ depends :init
339
+
340
+ delete(:dir => @build_dir)
341
+ delete(:file => "#{@lib_dir}/built_by_antbuilder.jruby.jar", :quiet=>"true")
342
+ delete(:dir => @api_docs_dir)
343
+
344
+ end
345
+
346
+ # required for tstamp task which uses the format keyword..
347
+ undef_method :format
348
+
349
+
350
+ # To run a standard jruby build, from the command line run
351
+ # jruby build.rb clean serialize create_jar_standalone
352
+ run_targets_from_command_line
353
+
354
+ # Or hard code a specific build e.g. =>
355
+ # 'Standard build'
356
+ # builder = Build.new
357
+ # builder.clean
358
+ # builder.serialize
359
+ # builder.create_jar_standalone
360
+
361
+ end
@@ -0,0 +1,14 @@
1
+ build.rb is can be used to build JRuby using JRuby
2
+ steps.
3
+ - check out the CVS HEAD of JRuby
4
+ - copy the AntBuilder 'builder' directory to the lib/ruby/site_ruby directory of the JRuby project
5
+ - copy the AntBuilder 'build.rb' file to the root of the JRuby project
6
+ - Open a command prompt in the root of the Jruby project and make sure you can run "jruby --version" (e.g. add jruby/bin to your path)
7
+ - put leafcutter.jar (from the AntBuilder project) on the classpath
8
+ - put tools.jar from your jdk on the classpath (required for the javac ant task)
9
+ - put the JRuby jruby\build\classes\jruby directory on the classpath (required by the JRubySerialize task)
10
+ - Open a command prompt in the root of the Jruby project and run: 'jruby build.rb clean serialize create_jar_standalone'
11
+
12
+
13
+
14
+
@@ -0,0 +1,16 @@
1
+ update_version.rb is an example jruby script that uses AntBuilder
2
+ ============================================================
3
+
4
+ + Gest the last Version Number from version.txt
5
+ + Updates the environment.xml file in each environment.jar file in each subdirectory of env
6
+ so that the versionNNNN part in <VersionInformation environment="..." buildVersion="versionNNNN"/>
7
+ is updated with last Version Number from version.txt
8
+
9
+ Setup steps.
10
+ - See the docs for JRuby install instructions
11
+ - Add a new entry with a new 'Project Version' to the end of version.txt
12
+ - Run 'jruby update_version.rb'
13
+ - Check that the 3 environment.jar files contain an environment.xml file with the correct version number
14
+
15
+
16
+
@@ -0,0 +1,91 @@
1
+ require 'builder/antbuilder'
2
+
3
+ #
4
+ # Gets the last Version Number from version.txt
5
+ # Updates the environment.xml file in each environment.jar file in each subdirectory of env
6
+ # so that the versionNNNN part in <VersionInformation environment="..." buildVersion="versionNNNN"/>
7
+ # is updated with last Version Number from version.txt
8
+
9
+
10
+ def get_version
11
+ ################################
12
+ # get the version number out of QuotesClient/version.txt
13
+ ################################
14
+
15
+ search1 = /Project Version *: *([A-Za-z0-9\-_.]*)/
16
+ versionFileName = "version.txt"
17
+ versionNumber = ""
18
+
19
+ File.foreach(versionFileName) { |line| versionNumber = $1 if line =~ search1 }
20
+
21
+ raise "Can't get a version number from #{versionFileName}" if versionNumber == ""
22
+
23
+ puts "Found version number #{versionNumber}. Press enter to continue.................................."
24
+ gets
25
+ return versionNumber
26
+
27
+ end
28
+
29
+ def replace_in_file(filename, searchPattern, replaceString)
30
+
31
+ new_filename = filename + ".new"
32
+
33
+ File.open(new_filename, "w") do |new_file|
34
+ File.foreach(filename) do |line|
35
+ line.sub!(searchPattern) { eval('"' + replaceString + '"') }
36
+ new_file.puts line
37
+ end
38
+ end
39
+
40
+
41
+ File.rename(new_filename, filename)
42
+
43
+ # ant.delete(:file => filename)
44
+ # ant.move(:file => newFilename, :tofile => filename)
45
+
46
+
47
+ end
48
+
49
+
50
+ versionNumber = get_version
51
+
52
+
53
+ ################################
54
+ # Define paths
55
+ ################################
56
+
57
+ root = "."
58
+ envdirs = "#{root}/env/"
59
+
60
+ ant = Builder::AntBuilder.new
61
+
62
+ ################################
63
+ # Updates the environment.xml file in each environment.jar file in each subdirectory of env
64
+ # so that the versionNNNN part in <VersionInformation environment="..." buildVersion="versionNNNN"/>
65
+ # is updated with versionNumber from version.txt
66
+ ################################
67
+
68
+ Dir.foreach(envdirs) do |dirname|
69
+ # ignore . and ..
70
+ next if File.basename(dirname) =~ /^\.+/
71
+
72
+ dirname = "#{envdirs}#{dirname}/"
73
+ xmlFileName = dirname + "environment.xml"
74
+ jarFileName = dirname + "environment.jar"
75
+
76
+ ant.unjar(:src => jarFileName, :dest => dirname)
77
+
78
+ # replace the versionNumber in the file with the new version number found in the version.txt file
79
+ # the single quotes around '#{$1}' rather than double quotes, stop the immediate evaluation of $1
80
+ replace_in_file(xmlFileName, /(<VersionInformation.*buildVersion.*=").*(".*$)/, '#{$1}'+ versionNumber + '#{$2}')
81
+
82
+
83
+ ant.delete(:file => jarFileName)
84
+
85
+ # Jar up the environment.xml to environment.jar
86
+ # use ant.zip rather than ant.jar because ant.jar creates a manifest file in the jar, whreas zip doesn't
87
+ ant.zip(:basedir => dirname, :destfile => jarFileName)
88
+
89
+ ant.delete(:file => xmlFileName)
90
+
91
+ end