Antwrap 0.6.0-java → 0.7.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,85 @@
1
+ # Copyright 2008 Caleb Powell
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and limitations
12
+ # under the License.
13
+
14
+ $LOAD_PATH.push(FileUtils::pwd + '/lib')
15
+ require 'rubygems'
16
+ require 'hoe'
17
+ require './lib/antwrap.rb'
18
+
19
+ def apply_default_hoe_properties(hoe)
20
+ hoe.remote_rdoc_dir = ''
21
+ hoe.rubyforge_name = 'antwrap'
22
+ hoe.author = 'Caleb Powell'
23
+ hoe.email = 'caleb.powell@gmail.com'
24
+ hoe.url = 'http://rubyforge.org/projects/antwrap/'
25
+ hoe.summary = 'A Ruby module that wraps the Apache Ant build tool. Antwrap can be used to invoke Ant Tasks from a Ruby or a JRuby script.'
26
+ hoe.description = hoe.paragraphs_of('README.txt', 2..5).join("\n\n")
27
+ hoe.changes = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
28
+ puts "Current changes in this release_______________ "
29
+ puts "#{hoe.changes}"
30
+ puts "----------------------------------------------"
31
+ end
32
+
33
+ #builds the MRI Gem
34
+ Hoe.new('Antwrap', Antwrap::VERSION) do |hoe|
35
+ apply_default_hoe_properties hoe
36
+ hoe.extra_deps << ["rjb", ">= 1.0.3"]
37
+ end
38
+
39
+ #builds the JRuby Gem
40
+ Hoe.new('Antwrap', Antwrap::VERSION) do |hoe|
41
+ apply_default_hoe_properties hoe
42
+ hoe.spec_extras = {:platform => 'java'}
43
+ end
44
+ #Gem::manage_gems
45
+ #require 'rake/gempackagetask'
46
+ #
47
+ #def create_spec(spec, platform)
48
+ # spec.name = 'Antwrap'
49
+ # spec.version = '0.6.0'
50
+ # spec.author = 'Caleb Powell'
51
+ # spec.email = 'caleb.powell@gmail.com'
52
+ # spec.homepage = 'http://rubyforge.org/projects/antwrap/'
53
+ # spec.platform = platform
54
+ # spec.summary = "A Ruby module that wraps the Apache Ant build tool, enabling Ant Tasks to be invoked from a Ruby/JRuby scripts."
55
+ # candidates = Dir.glob("{lib,test,docs}/**/*")
56
+ # spec.files = candidates.delete_if do |item|
57
+ # item.include?(".svn") || item.include?("apache-ant-1.7.0")
58
+ # end
59
+ # spec.require_path = 'lib'
60
+ # spec.autorequire = 'antwrap'
61
+ # spec.test_file = 'test/antwrap_test.rb'
62
+ # spec.has_rdoc = true
63
+ # spec.extra_rdoc_files = ['README', 'COPYING']
64
+ #end
65
+ #
66
+ #jruby_spec = Gem::Specification.new do |spec|
67
+ # create_spec(spec, 'java')
68
+ #end
69
+ #
70
+ #ruby_spec = Gem::Specification.new do |spec|
71
+ # create_spec(spec, Gem::Platform::RUBY)
72
+ # spec.add_dependency("rjb", ">= 1.0.3")
73
+ #end
74
+ #
75
+ #Rake::GemPackageTask.new(ruby_spec) do |pkg|
76
+ # puts "Creating Ruby Gem"
77
+ #end
78
+ #
79
+ #Rake::GemPackageTask.new(jruby_spec) do |pkg|
80
+ # puts "Creating JRuby Gem"
81
+ #end
82
+
83
+ #task :gems => [:pkg => '/Antwrap-0.5.1.gem']
84
+
85
+
@@ -1,133 +1,141 @@
1
- # ant_project.rb
2
- #
3
- # Copyright Caleb Powell 2007
4
- #
5
- # Licensed under the LGPL, see the file COPYING in the distribution
1
+ # Copyright 2008 Caleb Powell
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
6
5
  #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and limitations
12
+ # under the License.
7
13
 
8
- class AntProject
9
- require 'logger'
10
- require 'ant_task'
11
-
12
- private
13
- @@classes_loaded = false
14
-
15
- def init_project(options)
16
-
17
- @project= ApacheAnt::Project.new
18
- @project.setName(options[:name] || '')
19
- @project.setDefault('')
20
- @project.setBasedir(options[:basedir] || FileUtils::pwd)
21
- @project.init
22
- if options[:declarative] == nil
23
- @logger.debug("declarative is nil")
24
- self.declarative= true
25
- else
26
- @logger.debug("declarative is #{options[:declarative]}")
27
- self.declarative= options[:declarative]
28
- end
29
- default_logger = ApacheAnt::DefaultLogger.new
30
- default_logger.setMessageOutputLevel(2)
31
- default_logger.setOutputPrintStream(options[:outputstr] || JavaLang::System.out)
32
- default_logger.setErrorPrintStream(options[:errorstr] || JavaLang::System.err)
33
- default_logger.setEmacsMode(false)
34
- @project.addBuildListener(default_logger)
35
-
36
- end
37
-
38
- public
39
- attr :project, false
40
- attr :ant_version, false
41
- attr_accessor(:declarative, :logger)
42
-
43
- # Create an AntProject. Parameters are specified via a hash:
44
- # :ant_home=><em>Ant basedir</em>
45
- # -A String indicating the location of the ANT_HOME directory. If provided, Antwrap will
46
- # load the classes from the ANT_HOME/lib dir. If ant_home is not provided, the Ant jar files
47
- # must be available in the CLASSPATH.
48
- # :name=><em>project_name</em>
49
- # -A String indicating the name of this project.
50
- # :basedir=><em>project_basedir</em>
51
- # -A String indicating the basedir of this project. Corresponds to the 'basedir' attribute
52
- # on an Ant project.
53
- # :declarative=><em>declarative_mode</em>
54
- # -A boolean value indicating wether Ant tasks created by this project instance should
55
- # have their execute() method invoked during their creation. For example, with
56
- # the option :declarative=>true the following task would execute;
57
- # @antProject.echo(:message => "An Echo Task")
58
- # However, with the option :declarative=>false, the programmer is required to execute the
59
- # task explicitly;
60
- # echoTask = @antProject.echo(:message => "An Echo Task")
61
- # echoTask.execute()
62
- # Default value is <em>true</em>.
63
- # :logger=><em>Logger</em>
64
- # -A Logger instance. Defaults to Logger.new(STDOUT)
65
- # :loglevel=><em>The level to set the logger to</em>
66
- # -Defaults to Logger::ERROR
67
- def initialize(options=Hash.new)
14
+ module Antwrap
15
+ class AntProject
16
+ require 'logger'
17
+ require 'ant_task'
68
18
 
69
- @logger = options[:logger] || Logger.new(STDOUT)
70
- @logger.level = options[:loglevel] || Logger::ERROR
19
+ private
20
+ @@classes_loaded = false
71
21
 
72
- if(!@@classes_loaded && options[:ant_home])
73
- @logger.debug("loading ant jar files. Ant_Home: #{options[:ant_home]}")
74
- AntwrapClassLoader.load_ant_libs(options[:ant_home])
75
- @@classes_loaded = true
22
+ def init_project(options)
23
+
24
+ @project= Antwrap::ApacheAnt::Project.new
25
+ @project.setName(options[:name] || '')
26
+ @project.setDefault('')
27
+ @project.setBasedir(options[:basedir] || FileUtils::pwd)
28
+ @project.init
29
+ if options[:declarative] == nil
30
+ @logger.debug("declarative is nil")
31
+ self.declarative= true
32
+ else
33
+ @logger.debug("declarative is #{options[:declarative]}")
34
+ self.declarative= options[:declarative]
35
+ end
36
+ default_logger = ApacheAnt::DefaultLogger.new
37
+ default_logger.setMessageOutputLevel(2)
38
+ default_logger.setOutputPrintStream(options[:outputstr] || JavaLang::System.out)
39
+ default_logger.setErrorPrintStream(options[:errorstr] || JavaLang::System.err)
40
+ default_logger.setEmacsMode(false)
41
+ @project.addBuildListener(default_logger)
42
+
76
43
  end
77
44
 
78
- @logger.debug(ApacheAnt::Main.getAntVersion())
79
- @ant_version = ApacheAnt::Main.getAntVersion()[/\d\.\d\.\d/].to_f
80
- init_project(options)
45
+ public
46
+ attr :project, false
47
+ attr :ant_version, false
48
+ attr_accessor(:declarative, :logger)
81
49
 
82
- @task_stack = Array.new
83
-
84
- end
85
-
86
- def method_missing(sym, *args)
87
-
88
- begin
89
- task = AntTask.new(sym.to_s, self, args[0])
50
+ # Create an AntProject. Parameters are specified via a hash:
51
+ # :ant_home=><em>Ant basedir</em>
52
+ # -A String indicating the location of the ANT_HOME directory. If provided, Antwrap will
53
+ # load the classes from the ANT_HOME/lib dir. If ant_home is not provided, the Ant jar files
54
+ # must be available in the CLASSPATH.
55
+ # :name=><em>project_name</em>
56
+ # -A String indicating the name of this project.
57
+ # :basedir=><em>project_basedir</em>
58
+ # -A String indicating the basedir of this project. Corresponds to the 'basedir' attribute
59
+ # on an Ant project.
60
+ # :declarative=><em>declarative_mode</em>
61
+ # -A boolean value indicating wether Ant tasks created by this project instance should
62
+ # have their execute() method invoked during their creation. For example, with
63
+ # the option :declarative=>true the following task would execute;
64
+ # @antProject.echo(:message => "An Echo Task")
65
+ # However, with the option :declarative=>false, the programmer is required to execute the
66
+ # task explicitly;
67
+ # echoTask = @antProject.echo(:message => "An Echo Task")
68
+ # echoTask.execute()
69
+ # Default value is <em>true</em>.
70
+ # :logger=><em>Logger</em>
71
+ # -A Logger instance. Defaults to Logger.new(STDOUT)
72
+ # :loglevel=><em>The level to set the logger to</em>
73
+ # -Defaults to Logger::ERROR
74
+ def initialize(options=Hash.new)
90
75
 
91
- parent_task = @task_stack.last
92
- @task_stack << task
76
+ @logger = options[:logger] || Logger.new(STDOUT)
77
+ @logger.level = options[:loglevel] || Logger::ERROR
78
+
79
+ if(!@@classes_loaded && options[:ant_home])
80
+ @logger.debug("loading ant jar files. Ant_Home: #{options[:ant_home]}")
81
+ AntwrapClassLoader.load_ant_libs(options[:ant_home])
82
+ @@classes_loaded = true
83
+ end
93
84
 
94
- yield self if block_given?
85
+ @logger.debug(Antwrap::ApacheAnt::Main.getAntVersion())
86
+ @ant_version = Antwrap::ApacheAnt::Main.getAntVersion()[/\d\.\d\.\d/].to_f
87
+ init_project(options)
95
88
 
96
- parent_task.add(task) if parent_task
89
+ @task_stack = Array.new
97
90
 
98
- if @task_stack.nitems == 1
99
- if declarative == true
100
- @logger.debug("Executing #{task}")
101
- task.execute
102
- else
103
- @logger.debug("Returning #{task}")
104
- return task
105
- end
91
+ end
92
+
93
+ def method_missing(sym, *args)
94
+
95
+ begin
96
+ task = AntTask.new(sym.to_s, self, args[0])
97
+
98
+ parent_task = @task_stack.last
99
+ @task_stack << task
100
+
101
+ yield self if block_given?
102
+
103
+ parent_task.add(task) if parent_task
104
+
105
+ if @task_stack.nitems == 1
106
+ if declarative == true
107
+ @logger.debug("Executing #{task}")
108
+ task.execute
109
+ else
110
+ @logger.debug("Returning #{task}")
111
+ return task
112
+ end
113
+ end
114
+
115
+ rescue
116
+ @logger.error("Error instantiating '#{sym.to_s}' task: " + $!)
117
+ raise
118
+ ensure
119
+ @task_stack.pop
106
120
  end
121
+
122
+ end
107
123
 
108
- rescue
109
- @logger.error("Error instantiating '#{sym.to_s}' task: " + $!)
110
- raise
111
- ensure
112
- @task_stack.pop
124
+ #The Ant Project's name. Default is ''
125
+ def name
126
+ return @project.getName
113
127
  end
114
128
 
129
+ #The Ant Project's basedir. Default is '.'
130
+ def basedir
131
+ return @project.getBaseDir().getAbsolutePath();
132
+ end
133
+
134
+ #Displays the Class name followed by the AntProject name
135
+ # -e.g. AntProject[BigCoProject]
136
+ def to_s
137
+ return self.class.name + "[#{name}]"
138
+ end
139
+
115
140
  end
116
-
117
- #The Ant Project's name. Default is ''
118
- def name
119
- return @project.getName
120
- end
121
-
122
- #The Ant Project's basedir. Default is '.'
123
- def basedir
124
- return @project.getBaseDir().getAbsolutePath();
125
- end
126
-
127
- #Displays the Class name followed by the AntProject name
128
- # -e.g. AntProject[BigCoProject]
129
- def to_s
130
- return self.class.name + "[#{name}]"
131
- end
132
-
133
141
  end
@@ -1,118 +1,126 @@
1
- # ant_task.rb
2
- #
3
- # Copyright Caleb Powell 2007
4
- #
5
- # Licensed under the LGPL, see the file COPYING in the distribution
1
+ # Copyright 2008 Caleb Powell
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
6
5
  #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and limitations
12
+ # under the License.
7
13
 
8
- class AntTask
9
- attr_accessor :unknown_element, :project, :taskname, :logger, :executed
10
-
11
- public
12
- # Creates an AntTask
13
- # taskname
14
- # -A String representing the name of an Ant Task. This name should correspond to
15
- # the element name of the Ant xml task (e.g. javac, jar, war, etc).
16
- # antProject
17
- # -An instance of an AntProject
18
- # attributes
19
- # -A Hash of task name/values to be applied to the task.
20
- #
21
- # For example:
22
- # antProject = AntProject.new()
23
- # antTask = AntTask.new('javac', antProject, {:debug => 'on', :verbose => 'no', :fork => 'no'})
24
- def initialize(taskname, antProject, attributes)
25
-
26
- taskname = taskname[1, taskname.length-1] if taskname[0,1] == "_"
27
- @logger = antProject.logger
28
- @taskname = taskname
29
- @project_wrapper = antProject
30
- @project = antProject.project()
31
- @logger.debug(antProject.to_s)
32
- @unknown_element = create_unknown_element(@project, taskname)
33
- @logger.debug(to_s)
34
-
35
- add_attributes(attributes)
36
-
37
- end
38
-
39
- # Displays the Class name followed by the Task name
40
- # -e.g. AntTask[javac]
41
- def to_s
42
- return self.class.name + "[#{@taskname}]"
43
- end
44
-
45
- def create_unknown_element(project, taskname)
14
+ module Antwrap
15
+ class AntTask
16
+ attr_accessor :unknown_element, :project, :taskname, :logger, :executed
46
17
 
47
- element = ApacheAnt::UnknownElement.new(taskname)
48
- element.setProject(project)
49
- element.setOwningTarget(ApacheAnt::Target.new())
50
- element.setTaskName(taskname)
51
-
52
- #DNR. This initializes the Task's Wrapper object and prevents NullPointerExeption upon execution of the task
53
- element.getRuntimeConfigurableWrapper()
54
-
55
- if(@project_wrapper.ant_version >= 1.6)
56
- element.setTaskType(taskname)
57
- element.setNamespace('')
58
- element.setQName(taskname)
18
+ public
19
+ # Creates an AntTask
20
+ # taskname
21
+ # -A String representing the name of an Ant Task. This name should correspond to
22
+ # the element name of the Ant xml task (e.g. javac, jar, war, etc).
23
+ # antProject
24
+ # -An instance of an AntProject
25
+ # attributes
26
+ # -A Hash of task name/values to be applied to the task.
27
+ #
28
+ # For example:
29
+ # antProject = AntProject.new()
30
+ # antTask = AntTask.new('javac', antProject, {:debug => 'on', :verbose => 'no', :fork => 'no'})
31
+ def initialize(taskname, antProject, attributes)
32
+
33
+ taskname = taskname[1, taskname.length-1] if taskname[0,1] == "_"
34
+ @logger = antProject.logger
35
+ @taskname = taskname
36
+ @project_wrapper = antProject
37
+ @project = antProject.project()
38
+ @logger.debug(antProject.to_s)
39
+ @unknown_element = create_unknown_element(@project, taskname)
40
+ @logger.debug(to_s)
41
+
42
+ add_attributes(attributes)
43
+
59
44
  end
60
45
 
61
- return element
62
-
63
- end
64
-
65
- # Sets each attribute on the AntTask instance.
66
- # :attributes - is a Hash.
67
- def add_attributes(attributes)
68
-
69
- return if attributes == nil
46
+ # Displays the Class name followed by the Task name
47
+ # -e.g. AntTask[javac]
48
+ def to_s
49
+ return self.class.name + "[#{@taskname}]"
50
+ end
70
51
 
71
- wrapper = ApacheAnt::RuntimeConfigurable.new(@unknown_element, @unknown_element.getTaskName());
72
-
73
- if(@project_wrapper.ant_version >= 1.6)
74
- attributes.each do |key, val|
75
- apply_to_wrapper(wrapper, key.to_s, val){ |k,v| wrapper.setAttribute(k, v)}
52
+ def create_unknown_element(project, taskname)
53
+
54
+ element = ApacheAnt::UnknownElement.new(taskname)
55
+ element.setProject(project)
56
+ element.setOwningTarget(ApacheAnt::Target.new())
57
+ element.setTaskName(taskname)
58
+
59
+ #DNR. This initializes the Task's Wrapper object and prevents NullPointerExeption upon execution of the task
60
+ element.getRuntimeConfigurableWrapper()
61
+
62
+ if(@project_wrapper.ant_version >= 1.6)
63
+ element.setTaskType(taskname)
64
+ element.setNamespace('')
65
+ element.setQName(taskname)
76
66
  end
77
- else
78
- @unknown_element.setRuntimeConfigurableWrapper(wrapper)
79
- attribute_list = XmlSax::AttributeListImpl.new()
80
- attributes.each do |key, val|
81
- apply_to_wrapper(wrapper, key.to_s, val){ |k,v| attribute_list.addAttribute(k, 'CDATA', v)}
67
+
68
+ return element
69
+
70
+ end
71
+
72
+ # Sets each attribute on the AntTask instance.
73
+ # :attributes - is a Hash.
74
+ def add_attributes(attributes)
75
+
76
+ return if attributes == nil
77
+
78
+ wrapper = ApacheAnt::RuntimeConfigurable.new(@unknown_element, @unknown_element.getTaskName());
79
+
80
+ if(@project_wrapper.ant_version >= 1.6)
81
+ attributes.each do |key, val|
82
+ apply_to_wrapper(wrapper, key.to_s, val){ |k,v| wrapper.setAttribute(k, v)}
83
+ end
84
+ else
85
+ @unknown_element.setRuntimeConfigurableWrapper(wrapper)
86
+ attribute_list = XmlSax::AttributeListImpl.new()
87
+ attributes.each do |key, val|
88
+ apply_to_wrapper(wrapper, key.to_s, val){ |k,v| attribute_list.addAttribute(k, 'CDATA', v)}
89
+ end
90
+ wrapper.setAttributes(attribute_list)
82
91
  end
83
- wrapper.setAttributes(attribute_list)
92
+
84
93
  end
85
94
 
86
- end
87
-
88
- def apply_to_wrapper(wrapper, key, value)
89
-
90
- raise ArgumentError, "ArgumentError: You cannot use an Array as an argument. Use the :join method instead; i.e ['file1', 'file2'].join(File::PATH_SEPARATOR)." if value.is_a?(Array)
91
-
92
- begin
93
- if(key == 'pcdata')
94
- wrapper.addText(value.to_s)
95
- else
96
- yield key, value.to_s
95
+ def apply_to_wrapper(wrapper, key, value)
96
+
97
+ raise ArgumentError, "ArgumentError: You cannot use an Array as an argument. Use the :join method instead; i.e ['file1', 'file2'].join(File::PATH_SEPARATOR)." if value.is_a?(Array)
98
+
99
+ begin
100
+ if(key == 'pcdata')
101
+ wrapper.addText(value.to_s)
102
+ else
103
+ yield key, value.to_s
104
+ end
105
+ rescue StandardError
106
+ raise ArgumentError, "ArgumentError: Unable to set :#{key} attribute with value => '#{value}'"
97
107
  end
98
- rescue StandardError
99
- raise ArgumentError, "ArgumentError: Unable to set :#{key} attribute with value => '#{value}'"
108
+
100
109
  end
101
110
 
102
- end
111
+ # Add <em>child</em> as a child of this task.
112
+ def add(child)
113
+ @unknown_element.addChild(child.unknown_element())
114
+ @unknown_element.getRuntimeConfigurableWrapper().addChild(child.unknown_element().getRuntimeConfigurableWrapper())
115
+ end
116
+
117
+ # Invokes the AntTask.
118
+ def execute
119
+ @unknown_element.maybeConfigure
120
+ @unknown_element.execute
121
+ @executed = true
122
+ return nil
123
+ end
103
124
 
104
- # Add <em>child</em> as a child of this task.
105
- def add(child)
106
- @unknown_element.addChild(child.unknown_element())
107
- @unknown_element.getRuntimeConfigurableWrapper().addChild(child.unknown_element().getRuntimeConfigurableWrapper())
108
- end
109
-
110
- # Invokes the AntTask.
111
- def execute
112
- @unknown_element.maybeConfigure
113
- @unknown_element.execute
114
- @executed = true
115
- return nil
116
125
  end
117
-
118
- end
126
+ end