Antwrap 0.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/docs/index.html CHANGED
@@ -38,7 +38,7 @@ upon the invocation of the execute() method (this is a more Object Oriented appr
38
38
  circumstances):
39
39
 
40
40
  <code lang="ruby">
41
- @ant = AntProject.new({:name=&gt"FooProject", :declarative=&gttrue})
41
+ @ant = AntProject.new({:name=&gt"FooProject", :declarative=&gt false})
42
42
 
43
43
  javac_task = @ant.javac(:srcdir =&gt; "test", :destdir =&gt; "classes"){
44
44
  classpath(:refid =&gt; "common.class.path")
data/lib/antwrap.rb CHANGED
@@ -5,26 +5,44 @@
5
5
  # Licensed under the LGPL, see the file COPYING in the distribution
6
6
  #
7
7
 
8
- module ApacheAnt
9
- require 'java'
10
- include_class "org.apache.tools.ant.DefaultLogger"
11
- include_class "org.apache.tools.ant.Main"
12
- include_class "org.apache.tools.ant.Project"
13
- include_class "org.apache.tools.ant.RuntimeConfigurable"
14
- include_class "org.apache.tools.ant.Target"
15
- include_class "org.apache.tools.ant.UnknownElement"
16
- end
17
-
18
- module JavaLang
19
- require 'java'
20
- include_class "java.lang.System"
8
+ if(RUBY_PLATFORM == 'java')
9
+ require 'jruby_modules.rb'
10
+ else
11
+ require 'rjb_modules.rb'
21
12
  end
22
13
 
23
14
  class AntTask
24
15
  private
25
16
  @@task_stack = Array.new
26
- attr_reader :unknown_element, :project, :taskname, :logger, :executed
17
+ attr_accessor(:unknown_element, :project, :taskname, :logger, :executed)
18
+
19
+ def create_unknown_element(project, taskname)
20
+
21
+ element = ApacheAnt::UnknownElement.new(taskname)
22
+ element.setProject(project)
23
+ element.setOwningTarget(ApacheAnt::Target.new())
24
+ element.setTaskName(taskname)
25
+
26
+ if(@project_wrapper.ant_version >= 1.6)
27
+ element.setTaskType(taskname)
28
+ element.setNamespace('')
29
+ element.setQName(taskname)
30
+ end
31
+
32
+ return element
33
+
34
+ end
27
35
 
36
+ def method_missing(sym, *args)
37
+ begin
38
+ @logger.debug("AntTask.method_missing sym[#{sym.to_s}]")
39
+ task = AntTask.new(sym.to_s, @project_wrapper, args[0], block_given? ? Proc.new : nil)
40
+ self.add(task)
41
+ rescue StandardError
42
+ @logger.error("AntTask.method_missing error:" + $!)
43
+ end
44
+ end
45
+
28
46
  public
29
47
  def initialize(taskname, antProject, attributes, proc)
30
48
  taskname = taskname[1, taskname.length-1] if taskname[0,1] == "_"
@@ -39,7 +57,7 @@ class AntTask
39
57
  addAttributes(attributes)
40
58
 
41
59
  if proc
42
- @logger.debug("task_stack.push #{taskname} >> #{@@task_stack}")
60
+ # @logger.debug("task_stack.push #{taskname} >> #{@@task_stack}")
43
61
  @@task_stack.push self
44
62
 
45
63
  singleton_class = class << proc; self; end
@@ -54,23 +72,9 @@ class AntTask
54
72
 
55
73
  end
56
74
 
57
- def create_unknown_element(project, taskname)
58
-
59
- unknown_element = ApacheAnt::UnknownElement.new(taskname)
60
- unknown_element.project= project
61
- unknown_element.owningTarget= ApacheAnt::Target.new()
62
- unknown_element.taskName= taskname
63
-
64
- if(@project_wrapper.ant_version >= 1.6)
65
- unknown_element.taskType= taskname
66
- unknown_element.namespace= ''
67
- unknown_element.QName= taskname
68
- end
69
-
70
- return unknown_element
71
-
72
- end
73
75
 
76
+ # Sets each attribute on the AntTask instance.
77
+ # :attributes - is a Hash.
74
78
  def addAttributes(attributes)
75
79
 
76
80
  return if attributes == nil
@@ -93,22 +97,17 @@ class AntTask
93
97
 
94
98
  end
95
99
 
96
- def method_missing(sym, *args)
97
- begin
98
- @logger.debug("AntTask.method_missing sym[#{sym.to_s}]")
99
- task = AntTask.new(sym.to_s, @project_wrapper, args[0], block_given? ? Proc.new : nil)
100
- self.add(task)
101
- rescue StandardError
102
- @logger.error("AntTask.method_missing error:" + $!)
103
- end
104
- end
105
-
100
+ #Add <em>child</em> as a child of this task.
106
101
  def add(child)
107
- @logger.debug("adding child[#{child.taskname}] to [#{@taskname}]")
108
- @unknown_element.addChild(child.unknown_element())
109
- @unknown_element.getRuntimeConfigurableWrapper().addChild(child.unknown_element().getRuntimeConfigurableWrapper())
102
+ # @logger.debug("adding child[#{child.taskname()}] to [#{@taskname}]")
103
+ @unknown_element.addChild(child.getUnknownElement())
104
+ @unknown_element.getRuntimeConfigurableWrapper().addChild(child.getUnknownElement().getRuntimeConfigurableWrapper())
110
105
  end
111
106
 
107
+ def getUnknownElement
108
+ return @unknown_element
109
+ end
110
+ #Invokes the AntTask.
112
111
  def execute
113
112
  @unknown_element.maybeConfigure
114
113
  @unknown_element.execute
@@ -152,17 +151,17 @@ class AntProject
152
151
  # -Defaults to Logger::ERROR
153
152
  def initialize(options=Hash.new)
154
153
  @project= ApacheAnt::Project.new
155
- @project.name= options[:name] || ''
156
- @project.default= ''
157
- @project.basedir= options[:basedir] || '.'
154
+ @project.setName(options[:name] || '')
155
+ @project.setDefault('')
156
+ @project.setBasedir(options[:basedir] || '.')
158
157
  @project.init
159
158
  self.declarative= options[:declarative] || true
160
159
  default_logger = ApacheAnt::DefaultLogger.new
161
- default_logger.messageOutputLevel= 2
162
- default_logger.outputPrintStream= options[:outputstr] || JavaLang::System.out
163
- default_logger.errorPrintStream= options[:errorstr] || JavaLang::System.err
164
- default_logger.emacsMode= false
165
- @project.addBuildListener default_logger
160
+ default_logger.setMessageOutputLevel(2)
161
+ default_logger.setOutputPrintStream(options[:outputstr] || JavaLang::System.out)
162
+ default_logger.setErrorPrintStream(options[:errorstr] || JavaLang::System.err)
163
+ default_logger.setEmacsMode(false)
164
+ @project.addBuildListener(default_logger)
166
165
  @version = ApacheAnt::Main.getAntVersion
167
166
  @ant_version = @version[/\d\.\d\.\d/].to_f
168
167
  @logger = options[:logger] || Logger.new(STDOUT)
@@ -171,8 +170,8 @@ class AntProject
171
170
  end
172
171
 
173
172
  def create_task(taskname, attributes, proc)
174
- @logger.debug("Antproject.create_task.taskname = " + taskname)
175
- @logger.debug("Antproject.create_task.attributes = " + attributes.to_s)
173
+ @logger.debug("AntProject.create_task.taskname = " + taskname)
174
+ @logger.debug("AntProject.create_task.attributes = " + attributes.to_s)
176
175
 
177
176
  task = AntTask.new(taskname, self, attributes, proc)
178
177
  task.execute if declarative
@@ -188,18 +187,20 @@ class AntProject
188
187
  end
189
188
  end
190
189
 
190
+ #The Ant Project's name. Default is ''.
191
191
  def name()
192
- return @project.name
192
+ return @project.getName
193
193
  end
194
194
 
195
+ #The Ant Project's basedir. Default is '.'.
195
196
  def basedir()
196
197
  return @project.getBaseDir().getAbsolutePath();
197
198
  end
198
199
 
199
200
  def to_s
200
- return self.class.name + "[#{@project.name}]"
201
+ return self.class.name + "[#{@project.getName()}]"
201
202
  end
202
-
203
+
203
204
  #This method invokes create_task. It is here to prevent conflicts wth the JRuby library
204
205
  #over the 'java' symbol.
205
206
  def java(attributes=Hash.new)
@@ -0,0 +1,14 @@
1
+ module ApacheAnt
2
+ require 'java'
3
+ include_class "org.apache.tools.ant.DefaultLogger"
4
+ include_class "org.apache.tools.ant.Main"
5
+ include_class "org.apache.tools.ant.Project"
6
+ include_class "org.apache.tools.ant.RuntimeConfigurable"
7
+ include_class "org.apache.tools.ant.Target"
8
+ include_class "org.apache.tools.ant.UnknownElement"
9
+ end
10
+
11
+ module JavaLang
12
+ require 'java'
13
+ include_class "java.lang.System"
14
+ end
@@ -0,0 +1,16 @@
1
+ module ApacheAnt
2
+ require 'rubygems'
3
+ require 'rjb'
4
+ DefaultLogger = Rjb::import("org.apache.tools.ant.DefaultLogger")
5
+ Main = Rjb::import("org.apache.tools.ant.Main")
6
+ Project = Rjb::import("org.apache.tools.ant.Project")
7
+ RuntimeConfigurable = Rjb::import("org.apache.tools.ant.RuntimeConfigurable")
8
+ Target = Rjb::import("org.apache.tools.ant.Target")
9
+ UnknownElement = Rjb::import("org.apache.tools.ant.UnknownElement")
10
+ end
11
+
12
+ module JavaLang
13
+ require 'rubygems'
14
+ require 'rjb'
15
+ System = Rjb::import("java.lang.System")
16
+ end
data/test/tc_antwrap.rb CHANGED
@@ -6,40 +6,37 @@
6
6
  #
7
7
  require 'test/unit'
8
8
  require 'fileutils'
9
- require '../lib/antwrap.rb'
10
- require 'java'
11
- class TestStream < java.io.PrintStream
12
- attr_reader :last_line
13
-
14
- def initialise(out)
15
- self.super(out)
16
- end
17
-
18
- def println(s)
19
- puts "s"
20
- @last_line = s
21
- self.super(s)
22
- end
23
-
24
- def print(s)
25
- puts "s"
26
- @last_line = s
27
- self.super(s)
28
- end
29
- end
30
-
9
+ $LOAD_PATH.push(ENV['PWD'] + '/lib')
10
+ require 'antwrap'
11
+ require 'logger'
12
+ #class TestStream < java.io.PrintStream
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
31
31
  class TestAntwrap < Test::Unit::TestCase
32
32
 
33
33
  def setup
34
- # ENV is broken as of JRuby 0.9.2 but patched in 0.9.3 (see: http://jira.codehaus.org/browse/JRUBY-349)
35
- # @output_dir = ENV['PWD'] + '/output'
36
- # @resource_dir = ENV['PWD'] + '/test-resources'
37
- # The following is a workaround
38
- @current_dir = Java::java.lang.System.getProperty("user.dir")
34
+ @current_dir = ENV['PWD']
39
35
  @ant_proj_props = {:name=>"testProject", :basedir=>@current_dir, :declarative=>true,
40
36
  :logger=>Logger.new(STDOUT), :loglevel=>Logger::DEBUG}
41
37
  @ant = AntProject.new(@ant_proj_props)
42
38
  assert(@ant_proj_props[:name] == @ant.name())
39
+
43
40
  assert(@ant_proj_props[:basedir] == @ant.basedir())
44
41
  assert(@ant_proj_props[:declarative] == @ant.declarative())
45
42
 
@@ -106,11 +103,11 @@ class TestAntwrap < Test::Unit::TestCase
106
103
  assert_absent @output_dir + '/classes/foo/bar/FooBar.class'
107
104
  @ant.property(:name => 'pattern', :value => '**/*.jar')
108
105
  @ant.property(:name => 'resource_dir', :value => @resource_dir)
109
- @ant.path(:id => 'common.class.path'){
110
- fileset(:dir => '${resource_dir}'){
111
- include(:name => '${pattern}')
106
+ @ant.path(:id => 'common.class.path'){
107
+ fileset(:dir => '${resource_dir}'){
108
+ include(:name => '${pattern}')
109
+ }
112
110
  }
113
- }
114
111
 
115
112
  @ant.javac(:srcdir => @resource_dir + '/src',
116
113
  :destdir => @output_dir + '/classes',
metadata CHANGED
@@ -3,10 +3,10 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: Antwrap
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.4"
7
- date: 2007-03-04
8
- summary: "A JRuby module that wraps the Apache Ant build tool, enabling Ant Tasks to be
9
- invoked from a JRuby script."
6
+ version: 0.5.0
7
+ date: 2007-03-15
8
+ summary: "A Ruby module that wraps the Apache Ant build tool, enabling Ant Tasks to be
9
+ invoked from a Ruby/JRuby scripts."
10
10
  require_paths:
11
11
  - lib
12
12
  email: caleb.powell@gmail.com
@@ -16,7 +16,7 @@ description:
16
16
  autorequire: antwrap
17
17
  default_executable:
18
18
  bindir: bin
19
- has_rdoc: false
19
+ has_rdoc: true
20
20
  required_ruby_version: !ruby/object:Gem::Version::Requirement
21
21
  requirements:
22
22
  -
@@ -29,8 +29,8 @@ authors:
29
29
  - Caleb Powell
30
30
  files:
31
31
  - lib/antwrap.rb
32
- - lib/convert.rb
33
- - lib/rakefile.rb
32
+ - lib/jruby_modules.rb
33
+ - lib/rjb_modules.rb
34
34
  - test/output
35
35
  - test/tc_antwrap.rb
36
36
  - test/tc_convert.rb
@@ -64,4 +64,14 @@ extra_rdoc_files:
64
64
  executables: []
65
65
  extensions: []
66
66
  requirements: []
67
- dependencies: []
67
+ dependencies:
68
+ - !ruby/object:Gem::Dependency
69
+ name: rjb
70
+ version_requirement:
71
+ version_requirements: !ruby/object:Gem::Version::Requirement
72
+ requirements:
73
+ -
74
+ - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.3
77
+ version:
data/lib/convert.rb DELETED
@@ -1,104 +0,0 @@
1
- # antwrap
2
- #
3
- # Copyright Caleb Powell 2007
4
- #
5
- # Licensed under the LGPL, see the file COPYING in the distribution
6
- #
7
- require 'rexml/document'
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', 'java']
21
-
22
- xml = REXML::Document.new(@antfile)
23
-
24
- puts "Converting from Ant build script[#{@antfile.path}] == to ==> \n Rakefile[#{@rakefile.path}]"
25
-
26
- def create_symbol(str)
27
- str = rubyize(str)
28
- return str.gsub(/(\w*[^,\s])/, ':\1')
29
- end
30
-
31
- def rubyize(str)
32
- if (str == nil)
33
- str = ''
34
- elsif (@@reserved_words.index(str) != nil)
35
- str = '_' + str
36
- else
37
- str = str.gsub(/(\w*)[\-|\.](\w*)/, '\1_\2')
38
- end
39
- return str
40
- end
41
-
42
-
43
- @rakefile.print "require_gem 'Antwrap'\n"
44
- @rakefile.print "@ant = AntProject.new()\n"
45
- @one_tab= ' '
46
- def print_task(task, tab=@one_tab, prefix='')
47
- task_name = rubyize(task.name)
48
- @rakefile.print "#{tab}#{prefix}#{task_name}("
49
-
50
- if(task_name == 'macrodef')
51
- task.attributes['name'] = rubyize(task.attributes['name'])
52
- elsif(task_name == 'java')
53
- task_name = 'jvm'
54
- end
55
-
56
- isFirst = true;
57
- task.attributes.each do |key, value|
58
- if !isFirst
59
- @rakefile.print(",\n#{tab+@one_tab}")
60
- end
61
- @rakefile.print ":#{key} => \"#{value}\""
62
- isFirst = false;
63
- end
64
-
65
- if task.has_text?
66
- pcdata = task.texts().join
67
- if(pcdata.strip() != '')
68
- @rakefile.print ":pcdata => \"#{pcdata}\""
69
- end
70
- end
71
- @rakefile.print ")"
72
-
73
-
74
- if task.elements.size > 0
75
- @rakefile.print "{"
76
- task.elements.each do |child|
77
- @rakefile.print "\n"
78
- print_task(child, (tab+@one_tab), '')
79
- end
80
- @rakefile.print "\n#{tab}}"
81
- end
82
- end
83
-
84
- xml.elements.each("/project/*") do |node|
85
- if node.name != 'target'
86
- print_task(node, '', '@ant.')
87
- @rakefile.print "\n\n"
88
- end
89
- end
90
-
91
- xml.elements.each("/project/target") do |node|
92
-
93
- task = "\ntask " + create_symbol(node.attributes['name']) +
94
- " => [" + create_symbol(node.attributes['depends']) + "] do\n"
95
-
96
- @rakefile.print task
97
-
98
- node.elements.each do |child|
99
- print_task(child, @one_tab, '@ant.')
100
- @rakefile.print "\n"
101
- end
102
- @rakefile.print "end\n"
103
- end
104
-
data/lib/rakefile.rb DELETED
@@ -1,101 +0,0 @@
1
- require 'antwrap.rb'
2
-
3
- module Raven
4
-
5
- # The AntBuilderTask lets you execute Ant tasks directly from
6
- # your rakefile. For example:
7
- #
8
- # ant 'runant' do
9
- # echo(:text => "Using echo Ant task.")
10
- # end
11
- #
12
- # This task is different from other Raven tasks because its
13
- # body (or block if you prefer) isn't executed by Rake but
14
- # within the Ant interpreter (AntBuilder). Therefore the
15
- # task object isn't available within the code block as with
16
- # other tasks.
17
- #
18
- # For more information about the syntax to use to call Ant
19
- # tasks see http://antbuilder.rubyforge.org/
20
- class AntBuilderTask < Rake::Task
21
- attr_writer :body
22
-
23
- def execute
24
- super
25
- current_dir = application.original_dir()
26
- ant_project = AntProject.new({:name=>"testProject", :basedir=>current_dir, :declarative=>true,
27
- :logger=>Logger.new(STDOUT), :loglevel=>Logger::ERROR})
28
- ant_project.instance_eval(&@body)
29
- end
30
- end
31
- end
32
-
33
- def ant(args, &block)
34
- ant_task = Raven::AntBuilderTask.define_task(args)
35
- ant_task.body = block
36
- end
37
-
38
- ant 'runant' do
39
- mkdir(:dir => 'foo')
40
- echo(:message => "Using echo Ant task.")
41
- echo(:pcdata => "Using echo Ant task.")
42
- end
43
-
44
- ant :ant_echo do
45
- echo(:message => "Calling Ant <echo> task")
46
- end
47
-
48
- ant 'antcontrib' do
49
- taskdef(:resource => "net/sf/antcontrib/antlib.xml")
50
-
51
- property(:name => "bar", :value => "bar")
52
- _if(){
53
- equals(:arg1 => "${bar}", :arg2 => "bar")
54
- _then(){
55
- echo(:message => "if 1 is equal")
56
- }
57
- _else(){
58
- echo(:message => "if 1 is not equal")
59
- }
60
- }
61
-
62
- property(:name => "baz", :value => "foo")
63
- _if(){
64
- equals(:arg1 => "${baz}", :arg2 => "bar")
65
- _then(){
66
- echo(:message => "if 2 is equal")
67
- }
68
- _else(){
69
- echo(:message => "if 2 is not equal")
70
- }
71
- }
72
- end
73
-
74
- ant 'macrodef' do
75
- dir = 'foo'
76
-
77
- assert_absent dir
78
-
79
- macrodef(:name => 'testmacrodef'){
80
- attribute(:name => 'destination')
81
- sequential(){
82
- echo(:message => "Creating @{destination}")
83
- _mkdir(:dir => "@{destination}")
84
- }
85
- }
86
- testmacrodef(:destination => dir)
87
- assert_exists dir
88
-
89
- puts "Cleaning up and deleting #{dir}"
90
-
91
- Dir.delete dir
92
-
93
- end
94
-
95
- def assert_exists(file_path)
96
- puts "Does not exist[#{file_path}]" if !File.exists?(file_path)
97
- end
98
-
99
- def assert_absent(file_path)
100
- puts "Should not exist[#{file_path}]" if File.exists?(file_path)
101
- end