Class: Antwrap::AntTask
- Inherits:
-
Object
- Object
- Antwrap::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'})
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ant_task.rb', line 31 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.
16 17 18 |
# File 'lib/ant_task.rb', line 16 def executed @executed end |
#logger ⇒ Object
Returns the value of attribute logger.
16 17 18 |
# File 'lib/ant_task.rb', line 16 def logger @logger end |
#project ⇒ Object
Returns the value of attribute project.
16 17 18 |
# File 'lib/ant_task.rb', line 16 def project @project end |
#taskname ⇒ Object
Returns the value of attribute taskname.
16 17 18 |
# File 'lib/ant_task.rb', line 16 def taskname @taskname end |
#unknown_element ⇒ Object
Returns the value of attribute unknown_element.
16 17 18 |
# File 'lib/ant_task.rb', line 16 def unknown_element @unknown_element end |
Instance Method Details
#add(child) ⇒ Object
Add child as a child of this task.
112 113 114 115 |
# File 'lib/ant_task.rb', line 112 def add(child) @unknown_element.addChild(child.unknown_element()) @unknown_element.getRuntimeConfigurableWrapper().addChild(child.unknown_element().getRuntimeConfigurableWrapper()) end |
#add_attributes(attributes) ⇒ Object
Sets each attribute on the AntTask instance. :attributes - is a Hash.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ant_task.rb', line 74 def add_attributes(attributes) return if attributes == nil wrapper = ApacheAnt::RuntimeConfigurable.new(@unknown_element, @unknown_element.getTaskName()); if(@project_wrapper.ant_version >= 1.6) attributes.each do |key, val| apply_to_wrapper(wrapper, key.to_s, val){ |k,v| wrapper.setAttribute(k, v)} end else @unknown_element.setRuntimeConfigurableWrapper(wrapper) attribute_list = XmlSax::AttributeListImpl.new() attributes.each do |key, val| apply_to_wrapper(wrapper, key.to_s, val){ |k,v| attribute_list.addAttribute(k, 'CDATA', v)} end wrapper.setAttributes(attribute_list) end end |
#apply_to_wrapper(wrapper, key, value) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ant_task.rb', line 95 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.addText(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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ant_task.rb', line 52 def create_unknown_element(project, taskname) element = ApacheAnt::UnknownElement.new(taskname) element.setProject(project) element.setOwningTarget(ApacheAnt::Target.new()) element.setTaskName(taskname) #DNR. This initializes the Task's Wrapper object and prevents NullPointerExeption upon execution of the task element.getRuntimeConfigurableWrapper() if(@project_wrapper.ant_version >= 1.6) element.setTaskType(taskname) element.setNamespace('') element.setQName(taskname) end return element end |
#execute ⇒ Object
Invokes the AntTask.
118 119 120 121 122 123 |
# File 'lib/ant_task.rb', line 118 def execute @unknown_element.maybeConfigure @unknown_element.execute @executed = true return nil end |
#to_s ⇒ Object
Displays the Class name followed by the Task name -e.g. AntTask
48 49 50 |
# File 'lib/ant_task.rb', line 48 def to_s return self.class.name + "[#{@taskname}]" end |