Class: RAW::AntTask
- Inherits:
-
Object
- Object
- RAW::AntTask
- Defined in:
- lib/ant_task.rb
Instance Attribute Summary collapse
-
#executed ⇒ Object
Returns the value of attribute executed.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#project ⇒ Object
Returns the value of attribute project.
-
#taskname ⇒ Object
Returns the value of attribute taskname.
-
#unknown_element ⇒ Object
Returns the value of attribute unknown_element.
Instance Method Summary collapse
-
#add(child) ⇒ Object
Add child as a child of this task.
-
#add_attributes(attributes) ⇒ Object
Sets each attribute on the AntTask instance.
- #apply_to_wrapper(wrapper, key, value) ⇒ Object
- #create_unknown_element(project, taskname) ⇒ Object
-
#execute ⇒ Object
Invokes the AntTask.
-
#initialize(taskname, antProject, attributes) ⇒ AntTask
constructor
Creates an AntTask taskname -A String representing the name of an Ant Task.
-
#to_s ⇒ Object
Displays the Class name followed by the Task name -e.g.
Constructor Details
#initialize(taskname, antProject, attributes) ⇒ AntTask
Creates an AntTask taskname
-A String representing the name of an Ant Task. This name should correspond to
the element name of the Ant xml task (e.g. javac, jar, war, etc).
antProject
-An instance of an AntProject
attributes
-A Hash of task name/values to be applied to the task.
For example:
antProject = AntProject.new()
antTask = AntTask.new('javac', antProject, {:debug => 'on', :verbose => 'no', :fork => 'no'})
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ant_task.rb', line 30 def initialize(taskname, antProject, attributes) taskname = taskname[1, taskname.length-1] if taskname[0, 1] == "_" @logger = antProject.logger @taskname = taskname @project_wrapper = antProject @project = antProject.project @logger.debug(antProject.to_s) @unknown_element = create_unknown_element(@project, taskname) @logger.debug(to_s) add_attributes(attributes) end |
Instance Attribute Details
#executed ⇒ Object
Returns the value of attribute executed.
15 16 17 |
# File 'lib/ant_task.rb', line 15 def executed @executed end |
#logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/ant_task.rb', line 15 def logger @logger end |
#project ⇒ Object
Returns the value of attribute project.
15 16 17 |
# File 'lib/ant_task.rb', line 15 def project @project end |
#taskname ⇒ Object
Returns the value of attribute taskname.
15 16 17 |
# File 'lib/ant_task.rb', line 15 def taskname @taskname end |
#unknown_element ⇒ Object
Returns the value of attribute unknown_element.
15 16 17 |
# File 'lib/ant_task.rb', line 15 def unknown_element @unknown_element end |
Instance Method Details
#add(child) ⇒ Object
Add child as a child of this task.
111 112 113 114 |
# File 'lib/ant_task.rb', line 111 def add(child) @unknown_element.add_child(child.unknown_element()) @unknown_element.runtime_configurable_wrapper.add_child(child.unknown_element().runtime_configurable_wrapper) end |
#add_attributes(attributes) ⇒ Object
Sets each attribute on the AntTask instance. :attributes - is a Hash.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ant_task.rb', line 73 def add_attributes(attributes) return if attributes == nil wrapper = ApacheAnt::RuntimeConfigurable.new(@unknown_element, @unknown_element.task_name) if (@project_wrapper.ant_version >= 1.6) attributes.each do |key, val| apply_to_wrapper(wrapper, key.to_s, val){ |k, v| wrapper.set_attribute(k, v)} end else @unknown_element.runtime_configurable_wrapper = wrapper attribute_list = XmlSax::AttributeListImpl.new() attributes.each do |key, val| apply_to_wrapper(wrapper, key.to_s, val){ |k, v| attribute_list.add_attribute(k, 'CDATA', v)} end wrapper.set_attributes(attribute_list) end end |
#apply_to_wrapper(wrapper, key, value) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ant_task.rb', line 94 def apply_to_wrapper(wrapper, key, value) 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) begin if (key == 'pcdata') wrapper.add_text(value.to_s) else yield key, value.to_s end rescue StandardError raise ArgumentError, "ArgumentError: Unable to set :#{key} attribute with value => '#{value}'" end end |
#create_unknown_element(project, taskname) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ant_task.rb', line 51 def create_unknown_element(project, taskname) element = ApacheAnt::UnknownElement.new(taskname) element.project = project element.owning_target = ApacheAnt::Target.new element.task_name = taskname #DNR. This initializes the Task's Wrapper object and prevents NullPointerExeption upon execution of the task element.runtime_configurable_wrapper if (@project_wrapper.ant_version >= 1.6) element.task_type = taskname element.namespace = '' element.qname = taskname end return element end |
#execute ⇒ Object
Invokes the AntTask.
117 118 119 120 121 122 123 |
# File 'lib/ant_task.rb', line 117 def execute @unknown_element.maybe_configure @unknown_element.execute build_instance_variable(@unknown_element.wrapper) @executed = true return nil end |
#to_s ⇒ Object
Displays the Class name followed by the Task name -e.g. AntTask
47 48 49 |
# File 'lib/ant_task.rb', line 47 def to_s return self.class.name + "[#{@taskname}]" end |