Antwrap 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/docs/index.html +8 -2
- data/lib/antwrap.rb +21 -12
- data/lib/antwrap_utilities.rb +2 -0
- data/lib/dsl.rb +163 -0
- data/lib/jruby_modules.rb +4 -0
- data/lib/rjb_modules.rb +4 -0
- data/test/tc_antwrap.rb +23 -41
- metadata +3 -2
data/docs/index.html
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
<html><head><title>Antwrap - Invoke Ant tasks from your Ruby/JRuby scripts!</title></head><body><ul>
|
2
|
+
<h1>Antwrap</h1>
|
3
|
+
<h3>Invoke Ant tasks from your Ruby/JRuby scripts!</h3><br/>
|
2
4
|
<pre><li>Sample code of the Antwrap library looks like this;
|
3
5
|
|
4
6
|
<code lang="ruby">
|
@@ -96,9 +98,13 @@ in order to instantiate Java objects.
|
|
96
98
|
</li></pre>
|
97
99
|
|
98
100
|
</ul>
|
99
|
-
|
101
|
+
<a href='http://rubyforge.org/projects/antwrap/'>Project Info</a><br/>
|
102
|
+
<a href='http://buildr.rubyforge.org/'>Buildr</a><br/>
|
103
|
+
<a href='http://rubyforge.org/projects/raven/'>Raven</a><br/>
|
104
|
+
Comments or Questions? <br/>
|
100
105
|
|
101
106
|
Caleb Powell <br>
|
102
107
|
caleb.powell@gmail.com <br>
|
103
108
|
|
104
|
-
</body
|
109
|
+
</body>
|
110
|
+
</html>
|
data/lib/antwrap.rb
CHANGED
@@ -5,10 +5,11 @@
|
|
5
5
|
# Licensed under the LGPL, see the file COPYING in the distribution
|
6
6
|
#
|
7
7
|
require 'antwrap_utilities'
|
8
|
+
require 'dsl'
|
8
9
|
|
9
10
|
class AntTask
|
10
11
|
@@task_stack = Array.new
|
11
|
-
attr_accessor
|
12
|
+
attr_accessor :unknown_element, :project, :taskname, :logger, :executed
|
12
13
|
|
13
14
|
public
|
14
15
|
def initialize(taskname, antProject, attributes, proc)
|
@@ -81,23 +82,33 @@ class AntTask
|
|
81
82
|
return if attributes == nil
|
82
83
|
|
83
84
|
wrapper = ApacheAnt::RuntimeConfigurable.new(@unknown_element, @unknown_element.getTaskName());
|
84
|
-
outer_func = lambda{ |key, val, tfunc| key == 'pcdata' ? wrapper.addText(val) : tfunc.call(key, val) }
|
85
85
|
|
86
86
|
if(@project_wrapper.ant_version >= 1.6)
|
87
87
|
attributes.each do |key, val|
|
88
|
-
|
88
|
+
apply_to_wrapper(wrapper, key.to_s, val.to_s){ |k,v| wrapper.setAttribute(k, v)}
|
89
89
|
end
|
90
90
|
else
|
91
91
|
@unknown_element.setRuntimeConfigurableWrapper(wrapper)
|
92
|
-
attribute_list =
|
92
|
+
attribute_list = XmlSax::AttributeListImpl.new()
|
93
93
|
attributes.each do |key, val|
|
94
|
-
|
94
|
+
apply_to_wrapper(wrapper, key.to_s, val.to_s){ |k,v| attribute_list.addAttribute(k, 'CDATA', v)}
|
95
95
|
end
|
96
96
|
wrapper.setAttributes(attribute_list)
|
97
97
|
end
|
98
|
-
|
99
98
|
end
|
100
99
|
|
100
|
+
def apply_to_wrapper(wrapper, key, value)
|
101
|
+
begin
|
102
|
+
if(key == 'pcdata')
|
103
|
+
wrapper.addText(value)
|
104
|
+
else
|
105
|
+
yield key, value
|
106
|
+
end
|
107
|
+
rescue StandardError
|
108
|
+
raise ArgumentError, "Unable to set :#{key} attribute with value => '#{value}'"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
101
112
|
#Add <em>child</em> as a child of this task.
|
102
113
|
def add(child)
|
103
114
|
@unknown_element.addChild(child.unknown_element())
|
@@ -113,7 +124,7 @@ class AntTask
|
|
113
124
|
|
114
125
|
end
|
115
126
|
|
116
|
-
class AntProject
|
127
|
+
class AntProject
|
117
128
|
require 'logger'
|
118
129
|
|
119
130
|
private
|
@@ -164,7 +175,6 @@ class AntProject
|
|
164
175
|
# :loglevel=><em>The level to set the logger to</em>
|
165
176
|
# -Defaults to Logger::ERROR
|
166
177
|
def initialize(options=Hash.new)
|
167
|
-
|
168
178
|
@logger = options[:logger] || Logger.new(STDOUT)
|
169
179
|
@logger.level = options[:loglevel] || Logger::ERROR
|
170
180
|
|
@@ -176,9 +186,8 @@ class AntProject
|
|
176
186
|
|
177
187
|
@logger.debug(ApacheAnt::Main.getAntVersion())
|
178
188
|
@ant_version = ApacheAnt::Main.getAntVersion()[/\d\.\d\.\d/].to_f
|
179
|
-
|
180
189
|
init_project(options)
|
181
|
-
|
190
|
+
|
182
191
|
end
|
183
192
|
|
184
193
|
def method_missing(sym, *args)
|
@@ -188,8 +197,8 @@ class AntProject
|
|
188
197
|
task.execute if declarative
|
189
198
|
return task
|
190
199
|
rescue
|
191
|
-
@logger.error("Error instantiating
|
192
|
-
|
200
|
+
@logger.error("Error instantiating '#{sym.to_s}' task; " + $!)
|
201
|
+
raise
|
193
202
|
end
|
194
203
|
end
|
195
204
|
|
data/lib/antwrap_utilities.rb
CHANGED
@@ -2,11 +2,13 @@ if(RUBY_PLATFORM == 'java')
|
|
2
2
|
require 'java'
|
3
3
|
autoload :ApacheAnt, 'jruby_modules.rb'
|
4
4
|
autoload :JavaLang, 'jruby_modules.rb'
|
5
|
+
autoload :XmlOrg, 'jruby_modules.rb'
|
5
6
|
else
|
6
7
|
require 'rubygems'
|
7
8
|
require 'rjb'
|
8
9
|
autoload :ApacheAnt, 'rjb_modules.rb'
|
9
10
|
autoload :JavaLang, 'rjb_modules.rb'
|
11
|
+
autoload :XmlOrg, 'rjb_modules.rb'
|
10
12
|
end
|
11
13
|
|
12
14
|
module AntwrapClassLoader
|
data/lib/dsl.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
# A Domain Specific Language is used to introduce a new scope with an embedded set of methods.
|
2
|
+
#
|
3
|
+
# The idea is to avoid polluting the global namespace. Instead of adding methods to Kernel, we
|
4
|
+
# add methods to a new DomainSpecificLanguage, and then we can evaluate code with the new language
|
5
|
+
# using the #eval class method or using the #with method added to Kernel.
|
6
|
+
#
|
7
|
+
# For a similar approach, see http://www.infoq.com/articles/eval-options-in-ruby
|
8
|
+
|
9
|
+
class DomainSpecificLanguage
|
10
|
+
|
11
|
+
# See http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
|
12
|
+
def metaclass; class << self; self; end; end
|
13
|
+
def meta_eval &blk; metaclass.instance_eval &blk; end
|
14
|
+
|
15
|
+
# Adds methods to a metaclass
|
16
|
+
def meta_def name, &blk
|
17
|
+
meta_eval { define_method name, &blk }
|
18
|
+
end
|
19
|
+
|
20
|
+
# See http://onestepback.org/index.cgi/Tech/Ruby/RubyBindings.rdoc
|
21
|
+
class ReadOnlyReference
|
22
|
+
def initialize(var_name, vars)
|
23
|
+
@getter = eval "lambda { #{var_name} }", vars
|
24
|
+
end
|
25
|
+
def value
|
26
|
+
@getter.call
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :outer_binding, :outer_self
|
31
|
+
|
32
|
+
# instances of a DomainSpecificLanguage are created each time
|
33
|
+
# a block is evaluated with that language. The instance is
|
34
|
+
# intialized with the block's binding.
|
35
|
+
|
36
|
+
def initialize(given_binding)
|
37
|
+
@outer_binding = given_binding
|
38
|
+
@outer_self = ReadOnlyReference.new(:self, given_binding)
|
39
|
+
end
|
40
|
+
|
41
|
+
# some jiggery-pokery to access methods defined in the block's
|
42
|
+
# scope, because when the block is evaluated with the DomainSpecificLanguage,
|
43
|
+
# we use #instance_eval to set <tt>self</tt> to the DomainSpecificLanguage
|
44
|
+
# instance.
|
45
|
+
def method_missing(symbol, *args, &block)
|
46
|
+
if args.empty?
|
47
|
+
r = ReadOnlyReference.new(symbol, outer_binding)
|
48
|
+
meta_def(symbol) { r.value }
|
49
|
+
r.value
|
50
|
+
else
|
51
|
+
outer_self.value.send symbol, *args, &block
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class << self
|
56
|
+
|
57
|
+
# Evaluates a block in the context of a new DomainSpecificlanguage
|
58
|
+
# instance.
|
59
|
+
def eval &block
|
60
|
+
new(block.binding).instance_eval(&block)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
# We open Kernel and add just one method for introducing DomainSpecificLanguages
|
68
|
+
|
69
|
+
module Kernel
|
70
|
+
|
71
|
+
# Evaluate a block with a DomainSpecificLanguage
|
72
|
+
|
73
|
+
def with dsl_class, &block
|
74
|
+
dsl_class.eval(&block)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
# Let is a DomainSpecificLanguage that actually creates DomainSpecificLanguages.
|
80
|
+
#
|
81
|
+
# Let works a lot like <tt>let</tt> in Scheme. Your provide a hash of names and value
|
82
|
+
# expressions. The value expressions are evaluated in the outer scope, and then we have
|
83
|
+
# a little domain specific language where the inner scope has the names all bound to the
|
84
|
+
# values. E.g.
|
85
|
+
# <tt>
|
86
|
+
# with Let do
|
87
|
+
# let :x => 100, :y => 50 do
|
88
|
+
# print "#{x + y} should equal fifty"
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
# </tt>
|
92
|
+
#
|
93
|
+
# Within the Let DomainSpecificLanguage, you can declare multiple <tt>let</tt> statements and nest
|
94
|
+
# them as you please.
|
95
|
+
#
|
96
|
+
# One important limitation: you cannot bind a value to a name that is already a local variable.
|
97
|
+
|
98
|
+
class Let < DomainSpecificLanguage
|
99
|
+
|
100
|
+
class Scope < DomainSpecificLanguage
|
101
|
+
|
102
|
+
# initializes a Scope. In addition to the outer binding, we also pass in the
|
103
|
+
# hash of names and values. Note the check to ensure we are not trying to
|
104
|
+
# override a lcoal variable.
|
105
|
+
|
106
|
+
def initialize given_binding, let_clauses = {}
|
107
|
+
let_clauses.each do |symbol, value|
|
108
|
+
var_name = symbol.to_s
|
109
|
+
raise ArgumentError.new("Cannot override local #{var_name}") if eval("local_variables", given_binding).detect { |local| local == var_name }
|
110
|
+
meta_eval { attr_accessor(var_name) }
|
111
|
+
send "#{var_name}=", value
|
112
|
+
end
|
113
|
+
super(given_binding)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
# Define a new Scope: you're really defining a new DomainSpecificLanguage
|
119
|
+
|
120
|
+
def let let_clauses = {}, &block
|
121
|
+
Scope.new(block.binding, let_clauses).instance_eval(&block)
|
122
|
+
end
|
123
|
+
|
124
|
+
class << self
|
125
|
+
|
126
|
+
# If you just want a one-off
|
127
|
+
# def eval let_clauses = {}, &block
|
128
|
+
# Scope.new(block.binding, let_clauses).instance_eval(&block)
|
129
|
+
# end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
# A DomainSpecificDelegator is a DSL that delegates methods to a class or object.
|
136
|
+
# The main use is to separate the mechanics of scoping from the methods of a utility
|
137
|
+
# class.
|
138
|
+
|
139
|
+
class DomainSpecificDelegator < DomainSpecificLanguage
|
140
|
+
|
141
|
+
class << self
|
142
|
+
|
143
|
+
# insert one or more #delegate_to calls in the class definition, giving a receiver
|
144
|
+
# and a hash. Each hash pair is of the form <tt>verb => method</tt> where verb is the
|
145
|
+
# name you will use in the DSL and method is the method in the receiver that will handle
|
146
|
+
# it.
|
147
|
+
def delegate_to receiver, method_hash
|
148
|
+
@@delegations ||= {}
|
149
|
+
method_hash.each { |verb, method_name| @@delegations[verb.to_s] = [receiver, method_name.to_s] }
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
def method_missing symbol, *args, &block
|
155
|
+
receiver, method_name = *@@delegations[symbol.to_s]
|
156
|
+
if receiver
|
157
|
+
receiver.send method_name, *args, &block
|
158
|
+
else
|
159
|
+
super(symbol, *args, &block)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
data/lib/jruby_modules.rb
CHANGED
data/lib/rjb_modules.rb
CHANGED
data/test/tc_antwrap.rb
CHANGED
@@ -9,42 +9,20 @@ require 'fileutils'
|
|
9
9
|
$LOAD_PATH.push(ENV['PWD'] + '/lib')
|
10
10
|
require 'antwrap'
|
11
11
|
require 'logger'
|
12
|
-
|
13
|
-
# attr_reader :last_line
|
14
|
-
#
|
15
|
-
# def initialise(out)
|
16
|
-
# self.super(out)
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# def println(s)
|
20
|
-
# puts "s"
|
21
|
-
# @last_line = s
|
22
|
-
# self.super(s)
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# def print(s)
|
26
|
-
# puts "s"
|
27
|
-
# @last_line = s
|
28
|
-
# self.super(s)
|
29
|
-
# end
|
30
|
-
#end
|
12
|
+
|
31
13
|
class TestAntwrap < Test::Unit::TestCase
|
32
14
|
|
33
15
|
def setup
|
34
16
|
@current_dir = ENV['PWD']
|
35
17
|
@output_dir = @current_dir + '/test/output'
|
36
18
|
@resource_dir = @current_dir + '/test/test-resources'
|
19
|
+
|
37
20
|
@ant_home = @resource_dir + "/apache-ant-1.7.0"
|
38
21
|
# @ant_home = "/Users/caleb/tools/apache-ant-1.6.5"
|
39
22
|
# @ant_home = "/Users/caleb/tools/apache-ant-1.5.4"
|
40
23
|
@ant_proj_props = {:name=>"testProject", :basedir=>@current_dir, :declarative=>true,
|
41
24
|
:logger=>Logger.new(STDOUT), :loglevel=>Logger::DEBUG, :ant_home => @ant_home}
|
42
25
|
@ant = AntProject.new(@ant_proj_props)
|
43
|
-
assert(@ant_proj_props[:name] == @ant.name())
|
44
|
-
|
45
|
-
assert(@ant_proj_props[:basedir] == @ant.basedir())
|
46
|
-
assert(@ant_proj_props[:declarative] == @ant.declarative())
|
47
|
-
|
48
26
|
|
49
27
|
if File.exists?(@output_dir)
|
50
28
|
FileUtils.remove_dir(@output_dir)
|
@@ -64,9 +42,7 @@ class TestAntwrap < Test::Unit::TestCase
|
|
64
42
|
|
65
43
|
def test_unzip_task
|
66
44
|
assert_absent @output_dir + '/parent/FooBarParent.class'
|
67
|
-
|
68
|
-
:dest => @output_dir)
|
69
|
-
|
45
|
+
@ant.unzip(:src => @resource_dir + '/parent.jar', :dest => @output_dir)
|
70
46
|
assert_exists @output_dir + '/parent/FooBarParent.class'
|
71
47
|
end
|
72
48
|
|
@@ -106,18 +82,18 @@ class TestAntwrap < Test::Unit::TestCase
|
|
106
82
|
assert_absent @output_dir + '/classes/foo/bar/FooBar.class'
|
107
83
|
@ant.property(:name => 'pattern', :value => '**/*.jar')
|
108
84
|
@ant.property(:name => 'resource_dir', :value => @resource_dir)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
}
|
85
|
+
@ant.path(:id => 'common.class.path'){
|
86
|
+
fileset(:dir => '${resource_dir}'){
|
87
|
+
include(:name => '${pattern}')
|
113
88
|
}
|
89
|
+
}
|
114
90
|
|
115
91
|
@ant.javac(:srcdir => @resource_dir + '/src',
|
116
92
|
:destdir => @output_dir + '/classes',
|
117
93
|
:debug => 'on',
|
118
|
-
:verbose =>
|
94
|
+
:verbose => true,
|
119
95
|
:fork => 'no',
|
120
|
-
:failonerror => '
|
96
|
+
:failonerror => 'blahblahblah',
|
121
97
|
:includes => 'foo/bar/**',
|
122
98
|
:excludes => 'foo/bar/baz/**',
|
123
99
|
:classpathref => 'common.class.path')
|
@@ -140,7 +116,7 @@ class TestAntwrap < Test::Unit::TestCase
|
|
140
116
|
def test_java_task
|
141
117
|
|
142
118
|
return if @ant.ant_version < 1.7
|
143
|
-
|
119
|
+
puts "executing java task"
|
144
120
|
FileUtils.mkdir(@output_dir + '/classes', :mode => 0775)
|
145
121
|
@ant.javac(:srcdir => @resource_dir + '/src',
|
146
122
|
:destdir => @output_dir + '/classes',
|
@@ -167,15 +143,10 @@ class TestAntwrap < Test::Unit::TestCase
|
|
167
143
|
end
|
168
144
|
|
169
145
|
def test_echo_task
|
170
|
-
# stream = TestStream.new(java.lang.System.out)
|
171
|
-
#
|
172
|
-
# @ant = AntProject.new({:name=>"testProject", :basedir=>@current_dir, :declarative=>true,
|
173
|
-
# :logger=>Logger.new(STDOUT), :loglevel=>Logger::DEBUG, :outputstr => stream})
|
174
146
|
msg = "Antwrap is running an Echo task"
|
175
147
|
@ant.echo(:message => msg, :level => 'info')
|
176
|
-
|
177
|
-
|
178
|
-
@ant.echo(:pcdata => "<foo&bar>")
|
148
|
+
@ant.echo(:message => 100000, :level => 'info')
|
149
|
+
@ant.echo(:pcdata => 1000)
|
179
150
|
end
|
180
151
|
|
181
152
|
def test_mkdir_task
|
@@ -255,6 +226,17 @@ class TestAntwrap < Test::Unit::TestCase
|
|
255
226
|
def test_tstamp
|
256
227
|
@ant.tstamp
|
257
228
|
end
|
229
|
+
|
230
|
+
# def test_open_pja
|
231
|
+
# @ant.taskdef(:name=>"mappingtool", :classname=>"org.apache.openjpa.jdbc.ant.MappingToolTask")
|
232
|
+
#
|
233
|
+
# @ant.mappingtool(:action => "buildSchema"){
|
234
|
+
# fileset(:dir => "."){
|
235
|
+
# include(:name => "**/*.jdo")
|
236
|
+
# }
|
237
|
+
# }
|
238
|
+
# end
|
239
|
+
|
258
240
|
private
|
259
241
|
def assert_exists(file_path)
|
260
242
|
assert(File.exists?(file_path), "Does not exist[#{file_path}]")
|
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.5.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.5.3
|
7
|
+
date: 2007-06-13
|
8
8
|
summary: "A Ruby module that wraps the Apache Ant build tool, enabling Ant Tasks to be
|
9
9
|
invoked from a Ruby/JRuby scripts."
|
10
10
|
require_paths:
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- lib/antwrap.rb
|
32
32
|
- lib/antwrap_utilities.rb
|
33
33
|
- lib/convert.rb
|
34
|
+
- lib/dsl.rb
|
34
35
|
- lib/jruby_modules.rb
|
35
36
|
- lib/rjb_modules.rb
|
36
37
|
- test/build.xml
|