Class: Antwrap::AntProject
- Inherits:
-
Object
- Object
- Antwrap::AntProject
- Defined in:
- lib/ant_project.rb
Instance Attribute Summary collapse
-
#ant_version ⇒ Object
Returns the value of attribute ant_version.
-
#declarative ⇒ Object
Returns the value of attribute declarative.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
-
#basedir ⇒ Object
The Ant Project’s basedir.
-
#initialize(options = Hash.new) ⇒ AntProject
constructor
Create an AntProject.
- #java(*args, &block) ⇒ Object
- #method_missing(sym, *args) ⇒ Object
-
#name ⇒ Object
The Ant Project’s name.
-
#to_s ⇒ Object
Displays the Class name followed by the AntProject name -e.g.
Constructor Details
#initialize(options = Hash.new) ⇒ AntProject
Create an AntProject. Parameters are specified via a hash: :ant_home=>Ant basedir
-A String indicating the location of the ANT_HOME directory. If provided, Antwrap will
load the classes from the ANT_HOME/lib dir. If ant_home is not provided, the Ant jar files
must be available in the CLASSPATH.
:name=>project_name
-A String indicating the name of this project.
:basedir=>project_basedir
-A String indicating the basedir of this project. Corresponds to the 'basedir' attribute
on an Ant project.
:declarative=>declarative_mode
-A boolean value indicating wether Ant tasks created by this project instance should
have their execute() method invoked during their creation. For example, with
the option :declarative=>true the following task would execute;
@antProject.echo(:message => "An Echo Task")
However, with the option :declarative=>false, the programmer is required to execute the
task explicitly;
echoTask = @antProject.echo(:message => "An Echo Task")
echoTask.execute()
Default value is <em>true</em>.
:logger=>Logger
-A Logger instance. Defaults to Logger.new(STDOUT)
:loglevel=>The level to set the logger to
-Defaults to Logger::ERROR
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ant_project.rb', line 72 def initialize(=Hash.new) @logger = [:logger] || Logger.new(STDOUT) @logger.level = [:loglevel] || Logger::ERROR if(!@@classes_loaded && [:ant_home]) @logger.debug("loading ant jar files. Ant_Home: #{[:ant_home]}") AntwrapClassLoader.load_ant_libs([:ant_home]) @@classes_loaded = true end @logger.debug(Antwrap::ApacheAnt::Main.getAntVersion()) @ant_version = Antwrap::ApacheAnt::Main.getAntVersion()[/\d\.\d\.\d/].to_f init_project() @task_stack = Array.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ant_project.rb', line 95 def method_missing(sym, *args) begin task = AntTask.new(sym.to_s, self, args[0]) parent_task = @task_stack.last @task_stack << task yield self if block_given? parent_task.add(task) if parent_task if @task_stack.size == 1 if declarative == true @logger.debug("Executing #{task}") task.execute else @logger.debug("Returning #{task}") return task end end rescue @logger.error("Error instantiating '#{sym.to_s}' task: " + $!.to_s) raise ensure @task_stack.pop end end |
Instance Attribute Details
#ant_version ⇒ Object
Returns the value of attribute ant_version.
46 47 48 |
# File 'lib/ant_project.rb', line 46 def ant_version @ant_version end |
#declarative ⇒ Object
Returns the value of attribute declarative.
46 47 48 |
# File 'lib/ant_project.rb', line 46 def declarative @declarative end |
#logger ⇒ Object
Returns the value of attribute logger.
46 47 48 |
# File 'lib/ant_project.rb', line 46 def logger @logger end |
#project ⇒ Object
Returns the value of attribute project.
46 47 48 |
# File 'lib/ant_project.rb', line 46 def project @project end |
Instance Method Details
#basedir ⇒ Object
The Ant Project’s basedir. Default is ‘.’
132 133 134 |
# File 'lib/ant_project.rb', line 132 def basedir return @project.getBaseDir().getAbsolutePath(); end |
#java(*args, &block) ⇒ Object
91 92 93 |
# File 'lib/ant_project.rb', line 91 def java(*args, &block) method_missing(:java, *args, &block) end |
#name ⇒ Object
The Ant Project’s name. Default is ”
127 128 129 |
# File 'lib/ant_project.rb', line 127 def name return @project.getName end |
#to_s ⇒ Object
Displays the Class name followed by the AntProject name -e.g. AntProject
138 139 140 |
# File 'lib/ant_project.rb', line 138 def to_s return self.class.name + "[#{name}]" end |