Antwrap 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/antwrap.rb +6 -39
- data/lib/convert.rb +33 -16
- data/test/output/classes/foo/bar/FooBar.class +0 -0
- data/test/tc_antwrap.rb +45 -0
- data/test/test-resources/build.xml +30 -0
- metadata +6 -6
- data/test/output/META-INF/MANIFEST.MF +0 -3
- data/test/output/parent/FooBarParent.class +0 -0
data/lib/antwrap.rb
CHANGED
@@ -20,7 +20,7 @@ module JavaLang
|
|
20
20
|
end
|
21
21
|
|
22
22
|
@@log = Logger.new(STDOUT)
|
23
|
-
@@log.level = Logger::
|
23
|
+
@@log.level = Logger::ERROR
|
24
24
|
|
25
25
|
class AntTask
|
26
26
|
private
|
@@ -29,6 +29,9 @@ class AntTask
|
|
29
29
|
|
30
30
|
public
|
31
31
|
def initialize(taskname, project, attributes, proc)
|
32
|
+
if(taskname[0,1] == "_")
|
33
|
+
taskname = taskname[1, taskname.length-1]
|
34
|
+
end
|
32
35
|
@taskname = taskname
|
33
36
|
@project = project
|
34
37
|
@unknown_element = ApacheAnt::UnknownElement.new(taskname)
|
@@ -87,6 +90,7 @@ class AntTask
|
|
87
90
|
def was_executed?
|
88
91
|
@executed
|
89
92
|
end
|
93
|
+
|
90
94
|
end
|
91
95
|
|
92
96
|
class AntProject
|
@@ -114,13 +118,11 @@ class AntProject
|
|
114
118
|
task.execute if declarative
|
115
119
|
if taskname == 'macrodef'
|
116
120
|
@@log.debug("Pushing #{attributes[:name]} to tasks")
|
117
|
-
@@tasks.push(attributes[:name])
|
118
121
|
end
|
119
122
|
task
|
120
123
|
end
|
121
124
|
|
122
125
|
def method_missing(sym, *args)
|
123
|
-
if(@@tasks.include?(sym.to_s) || @@types.include?(sym.to_s))
|
124
126
|
begin
|
125
127
|
@@log.info("AntProject.method_missing sym[#{sym.to_s}]")
|
126
128
|
proc = block_given? ? Proc.new : nil
|
@@ -128,9 +130,6 @@ class AntProject
|
|
128
130
|
rescue
|
129
131
|
@@log.error("Error instantiating task[#{sym.to_s}]" + $!)
|
130
132
|
end
|
131
|
-
else
|
132
|
-
@@log.error("Not an Ant Task[#{sym.to_s}]")
|
133
|
-
end
|
134
133
|
end
|
135
134
|
|
136
135
|
#overridden. 'mkdir' conflicts wth the rake library.
|
@@ -144,40 +143,8 @@ class AntProject
|
|
144
143
|
end
|
145
144
|
|
146
145
|
#overridden. 'java' conflicts wth the JRuby library.
|
147
|
-
def jvm(attributes)
|
146
|
+
def jvm(attributes=Hash.new)
|
148
147
|
create_task('java', attributes, (block_given? ? Proc.new : nil))
|
149
148
|
end
|
150
149
|
|
151
|
-
@@tasks = [
|
152
|
-
# standard ant tasks
|
153
|
-
'mkdir', 'javac', 'chmod', 'delete', 'copy', 'move', 'jar', 'rmic', 'cvs', 'get', 'unzip',
|
154
|
-
'unjar', 'unwar', 'echo', 'javadoc', 'zip', 'gzip', 'gunzip', 'replace', 'java', 'tstamp', 'property',
|
155
|
-
'xmlproperty', 'taskdef', 'ant', 'exec', 'tar', 'untar', 'available', 'filter', 'fixcrlf', 'patch',
|
156
|
-
'style', 'xslt', 'touch', 'signjar', 'genkey', 'antstructure', 'execon', 'antcall', 'sql', 'mail',
|
157
|
-
'fail', 'war', 'uptodate', 'apply', 'record', 'cvspass', 'typedef', 'sleep', 'pathconvert', 'ear',
|
158
|
-
'parallel', 'sequential', 'condition', 'dependset', 'bzip2', 'bunzip2', 'checksum', 'waitfor', 'input',
|
159
|
-
'loadfile', 'manifest', 'loadproperties', 'basename', 'dirname', 'cvschangelog', 'cvsversion', 'buildnumber',
|
160
|
-
'concat', 'cvstagdiff', 'tempfile', 'import', 'whichresource', 'subant', 'sync', 'defaultexcludes', 'presetdef',
|
161
|
-
'macrodef', 'nice', 'length',
|
162
|
-
# optional tasks
|
163
|
-
'image', 'script', 'netrexxc', 'renameext', 'ejbc', 'ddcreator', 'wlrun', 'wlstop', 'vssadd', 'vsscheckin', 'vsscheckout',
|
164
|
-
'vsscp', 'vsscreate', 'vssget', 'vsshistory', 'vsslabel', 'ejbjar', 'mparse', 'mmetrics', 'maudit', 'junit', 'cab',
|
165
|
-
'ftp', 'icontract', 'javacc', 'jjdoc', 'jjtree', 'stcheckout', 'stcheckin', 'stlabel', 'stlist', 'wljspc', 'jlink',
|
166
|
-
'native2ascii', 'propertyfile', 'depend', 'antlr', 'vajload', 'vajexport', 'vajimport', 'telnet', 'csc', 'ilasm',
|
167
|
-
'WsdlToDotnet', 'wsdltodotnet', 'importtypelib', 'stylebook', 'test', 'pvcs', 'p4change', 'p4delete', 'p4label', 'p4labelsync',
|
168
|
-
'p4have', 'p4sync', 'p4edit', 'p4integrate', 'p4resolve', 'p4submit', 'p4counter', 'p4revert', 'p4reopen', 'p4fstat', 'javah',
|
169
|
-
'ccupdate', 'cccheckout', 'cccheckin', 'ccuncheckout', 'ccmklbtype', 'ccmklabel', 'ccrmtype', 'cclock', 'ccunlock', 'ccmkbl',
|
170
|
-
'ccmkattr', 'ccmkelem', 'ccmkdir', 'sound', 'junitreport', 'blgenclient', 'rpm', 'xmlvalidate', 'iplanet-ejbc', 'jdepend',
|
171
|
-
'mimemail', 'ccmcheckin', 'ccmcheckout', 'ccmcheckintask', 'ccmreconfigure', 'ccmcreatetask', 'jpcoverage', 'jpcovmerge',
|
172
|
-
'jpcovreport', 'p4add', 'jspc', 'replaceregexp', 'translate', 'sosget', 'soscheckin','soscheckout','soslabel', 'echoproperties',
|
173
|
-
'splash', 'serverdeploy', 'jarlib-display', 'jarlib-manifest', 'jarlib-available', 'jarlib-resolve', 'setproxy', 'vbc', 'symlink',
|
174
|
-
'chgrp', 'chown', 'attrib', 'scp', 'sshexec', 'jsharpc', 'rexec', 'scriptdef', 'ildasm',
|
175
|
-
# deprecated ant tasks (kept for back compatibility)
|
176
|
-
'starteam', 'javadoc2', 'copydir', 'copyfile', 'deltree', 'rename']
|
177
|
-
|
178
|
-
@@types = [ 'classfileset', 'description', 'dirset', 'filelist', 'fileset', 'filterchain', 'filterreader', 'filterset', 'mapper', 'redirector',
|
179
|
-
'identitymapper', 'flattenmapper', 'globmapper', 'mergemapper', 'regexpmapper', 'packagemapper', 'unpackagemapper', 'compositemapper',
|
180
|
-
'chainedmapper', 'filtermapper', 'path', 'patternset', 'regexp', 'substitution', 'xmlcatalog', 'extensionSet', 'extension', 'libfileset',
|
181
|
-
'selector', 'zipfileset', 'scriptfilter', 'propertyset', 'assertions', 'concatfilter', 'isfileselected' ]
|
182
|
-
|
183
150
|
end
|
data/lib/convert.rb
CHANGED
@@ -5,17 +5,34 @@
|
|
5
5
|
# Licensed under the LGPL, see the file COPYING in the distribution
|
6
6
|
#
|
7
7
|
require 'rexml/document'
|
8
|
-
@outfile = File.new('/Users/caleb/projects/antwrap/test/output/Rakefile.rb', 'w+')
|
9
|
-
xml = REXML::Document.new(File.open('/Users/caleb/projects/antwrap/test/test-resources/build.xml'))
|
10
8
|
|
9
|
+
if ARGV.empty?
|
10
|
+
puts "Usage: #{$0} [antfile] [rakefile]"
|
11
|
+
exit! 1
|
12
|
+
end
|
13
|
+
|
14
|
+
@antfile = File.open(ARGV[0])
|
15
|
+
@rakefile = File.new(ARGV[1], 'w+')
|
16
|
+
@@reserved_words = ['alias', 'and', 'BEGIN', 'begin', 'break', 'case', 'class',
|
17
|
+
'def', 'defined', 'do', 'else', 'elsif', 'END', 'end', 'ensure',
|
18
|
+
'false', 'for', 'if', 'in', 'module', 'next', 'nil', 'not', 'or',
|
19
|
+
'redo', 'rescue', 'retry', 'return', 'self', 'super', 'then', 'true',
|
20
|
+
'undef', 'unless', 'until', 'when', 'while', 'yield']
|
21
|
+
|
22
|
+
xml = REXML::Document.new(@antfile)
|
23
|
+
|
24
|
+
puts "Converting from Ant build script[#{@antfile.path}] == to ==> \n Rakefile[#{@rakefile.path}]"
|
11
25
|
|
12
26
|
def create_symbol(str)
|
13
27
|
str = rubyize(str)
|
14
28
|
return str.gsub(/(\w*[^,\s])/, ':\1')
|
15
29
|
end
|
30
|
+
|
16
31
|
def rubyize(str)
|
17
32
|
if (str == nil)
|
18
33
|
str = ''
|
34
|
+
elsif (@@reserved_words.index(str) != nil)
|
35
|
+
str = '_' + str
|
19
36
|
else
|
20
37
|
str = str.gsub(/(\w*)[\-|\.](\w*)/, '\1_\2')
|
21
38
|
end
|
@@ -23,12 +40,12 @@ def rubyize(str)
|
|
23
40
|
end
|
24
41
|
|
25
42
|
|
26
|
-
@
|
27
|
-
@
|
43
|
+
@rakefile.print "require_gem 'Antwrap'\n"
|
44
|
+
@rakefile.print "@ant = AntProject.new()\n"
|
28
45
|
@one_tab= ' '
|
29
46
|
def print_task(task, tab=@one_tab, prefix='')
|
30
47
|
task_name = rubyize(task.name)
|
31
|
-
@
|
48
|
+
@rakefile.print "#{tab}#{prefix}#{task_name}("
|
32
49
|
|
33
50
|
if(task_name == 'macrodef')
|
34
51
|
task.attributes['name'] = rubyize(task.attributes['name'])
|
@@ -36,35 +53,35 @@ def print_task(task, tab=@one_tab, prefix='')
|
|
36
53
|
isFirst = true;
|
37
54
|
task.attributes.each do |key, value|
|
38
55
|
if !isFirst
|
39
|
-
@
|
56
|
+
@rakefile.print(",\n#{tab+@one_tab}")
|
40
57
|
end
|
41
|
-
@
|
58
|
+
@rakefile.print ":#{key} => \"#{value}\""
|
42
59
|
isFirst = false;
|
43
60
|
end
|
44
61
|
|
45
62
|
if task.has_text?
|
46
63
|
pcdata = task.texts().join
|
47
64
|
if(pcdata.strip() != '')
|
48
|
-
@
|
65
|
+
@rakefile.print ":pcdata => \"#{pcdata}\""
|
49
66
|
end
|
50
67
|
end
|
51
|
-
@
|
68
|
+
@rakefile.print ")"
|
52
69
|
|
53
70
|
|
54
71
|
if task.elements.size > 0
|
55
|
-
@
|
72
|
+
@rakefile.print "{"
|
56
73
|
task.elements.each do |child|
|
57
|
-
@
|
74
|
+
@rakefile.print "\n"
|
58
75
|
print_task(child, (tab+@one_tab), '')
|
59
76
|
end
|
60
|
-
@
|
77
|
+
@rakefile.print "\n#{tab}}"
|
61
78
|
end
|
62
79
|
end
|
63
80
|
|
64
81
|
xml.elements.each("/project/*") do |node|
|
65
82
|
if node.name != 'target'
|
66
83
|
print_task(node, '', '@ant.')
|
67
|
-
@
|
84
|
+
@rakefile.print "\n\n"
|
68
85
|
end
|
69
86
|
end
|
70
87
|
|
@@ -73,12 +90,12 @@ xml.elements.each("/project/target") do |node|
|
|
73
90
|
task = "\ntask " + create_symbol(node.attributes['name']) +
|
74
91
|
" => [" + create_symbol(node.attributes['depends']) + "] do\n"
|
75
92
|
|
76
|
-
@
|
93
|
+
@rakefile.print task
|
77
94
|
|
78
95
|
node.elements.each do |child|
|
79
96
|
print_task(child, @one_tab, '@ant.')
|
80
|
-
@
|
97
|
+
@rakefile.print "\n"
|
81
98
|
end
|
82
|
-
@
|
99
|
+
@rakefile.print "end\n"
|
83
100
|
end
|
84
101
|
|
Binary file
|
data/test/tc_antwrap.rb
CHANGED
@@ -197,6 +197,51 @@ class TestAntwrap < Test::Unit::TestCase
|
|
197
197
|
@ant.echo(:pcdata => "Foobar & <><><>")
|
198
198
|
end
|
199
199
|
|
200
|
+
def test_ant_contrib
|
201
|
+
#<if>
|
202
|
+
# <equals arg1="${foo}" arg2="bar" />
|
203
|
+
# <then>
|
204
|
+
# <echo message="The value of property foo is 'bar'" />
|
205
|
+
# </then>
|
206
|
+
#
|
207
|
+
# <elseif>
|
208
|
+
# <equals arg1="${foo}" arg2="foo" />
|
209
|
+
# <then>
|
210
|
+
# <echo message="The value of property foo is 'foo'" />
|
211
|
+
# </then>
|
212
|
+
# </elseif>
|
213
|
+
#
|
214
|
+
#
|
215
|
+
# <else>
|
216
|
+
# <echo message="The value of property foo is not 'foo' or 'bar'" />
|
217
|
+
# </else>
|
218
|
+
#</if>
|
219
|
+
#
|
220
|
+
@ant.taskdef(:resource => "net/sf/antcontrib/antlib.xml")
|
221
|
+
|
222
|
+
@ant.property(:name => "bar", :value => "bar")
|
223
|
+
@ant._if(){
|
224
|
+
_equals(:arg1 => "${bar}", :arg2 => "bar")
|
225
|
+
_then(){
|
226
|
+
echo(:message => "if 1 is equal")
|
227
|
+
}
|
228
|
+
_else(){
|
229
|
+
echo(:message => "if 1 is not equal")
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
@ant.property(:name => "baz", :value => "foo")
|
234
|
+
@ant._if(){
|
235
|
+
_equals(:arg1 => "${baz}", :arg2 => "bar")
|
236
|
+
_then(){
|
237
|
+
echo(:message => "if 2 is equal")
|
238
|
+
}
|
239
|
+
_else(){
|
240
|
+
echo(:message => "if 2 is not equal")
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
end
|
200
245
|
private
|
201
246
|
def assert_exists(file_path)
|
202
247
|
assert(File.exists?(file_path), "Does not exist[#{file_path}]")
|
@@ -307,4 +307,34 @@
|
|
307
307
|
</sequential>
|
308
308
|
</macrodef>
|
309
309
|
|
310
|
+
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
|
311
|
+
<target name="ant-contrib">
|
312
|
+
<if>
|
313
|
+
<equals arg1="bar" arg2="bar" />
|
314
|
+
<then>
|
315
|
+
<echo message="if 1 is equal" />
|
316
|
+
</then>
|
317
|
+
<else>
|
318
|
+
<echo message="if 1 is not equal" />
|
319
|
+
</else>
|
320
|
+
</if>
|
321
|
+
<if>
|
322
|
+
<equals arg1="${foo}" arg2="bar" />
|
323
|
+
<then>
|
324
|
+
<echo message="if 2 is equal" />
|
325
|
+
</then>
|
326
|
+
|
327
|
+
<elseif>
|
328
|
+
<equals arg1="foo" arg2="foo" />
|
329
|
+
<then>
|
330
|
+
<echo message="if 2.1 is equal" />
|
331
|
+
</then>
|
332
|
+
</elseif>
|
333
|
+
<else>
|
334
|
+
<echo message="The value of property foo is not 'foo' or 'bar'" />
|
335
|
+
</else>
|
336
|
+
</if>
|
337
|
+
|
338
|
+
</target>
|
339
|
+
|
310
340
|
</project>
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: Antwrap
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2007-01-
|
6
|
+
version: "0.2"
|
7
|
+
date: 2007-01-30
|
8
8
|
summary: A JRuby module that wraps the Apache Ant build tool
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -33,10 +33,10 @@ files:
|
|
33
33
|
- test/tc_antwrap.rb
|
34
34
|
- test/tc_convert.rb
|
35
35
|
- test/test-resources
|
36
|
-
- test/output/
|
37
|
-
- test/output/
|
38
|
-
- test/output/
|
39
|
-
- test/output/
|
36
|
+
- test/output/classes
|
37
|
+
- test/output/classes/foo
|
38
|
+
- test/output/classes/foo/bar
|
39
|
+
- test/output/classes/foo/bar/FooBar.class
|
40
40
|
- test/test-resources/build.xml
|
41
41
|
- test/test-resources/foo.txt
|
42
42
|
- test/test-resources/foo.zip
|
Binary file
|