class Warbler::Task
Warbler
Rake task. Allows defining multiple configurations inside the same Rakefile by using different task names.
To define multiple Warbler
configurations in a single project, use code like the following in a Rakefile:
Warbler::Task.new("war1", Warbler::Config.new do |config| config.jar_name = "war1" # ... end Warbler::Task.new("war2", Warbler::Config.new do |config| config.jar_name = "war2" # ... end
With this setup, you can create two separate war files two different configurations by running rake war1 war2
.
Attributes
config[RW]
jar[RW]
name[RW]
Task
name
war[RW]
Public Class Methods
new(name = nil, config = nil) { |self| ... }
click to toggle source
# File lib/warbler/task.rb, line 43 def initialize(name = nil, config = nil) @config = config if @config.nil? && File.exists?(Config::FILE) @config = eval(File.read(Config::FILE), binding, Config::FILE, 0) end @config ||= Config.new unless @config.kind_of? Config warn "Warbler::Config not provided by override in initializer or #{Config::FILE}; using defaults" @config = Config.new end @name = name || @config.jar_extension @jar = Warbler::Jar.new yield self if block_given? define_tasks end
Private Instance Methods
define_clean_task()
click to toggle source
# File lib/warbler/task.rb, line 99 def define_clean_task desc "Remove the project #{config.jar_extension} file" task "clean" do rm_f "#{config.jar_name}.#{config.jar_extension}" end task "clear" => "#{name}:clean" end
define_compiled_task()
click to toggle source
# File lib/warbler/task.rb, line 107 def define_compiled_task task "compiled" do jar.compile(config) task @name do rm_f config.compiled_ruby_files.map {|f| f.sub(/\.rb$/, '.class') } end end end
define_config_task()
click to toggle source
# File lib/warbler/task.rb, line 149 def define_config_task task "config" do if File.exists?(Warbler::Config::FILE) && ENV["FORCE"].nil? puts "There's another bird sitting on my favorite branch" puts "(file '#{Warbler::Config::FILE}' already exists. Pass argument FORCE=1 to override)" elsif !File.directory?("config") puts "I'm confused; my favorite branch is missing" puts "(directory 'config' is missing)" else cp "#{Warbler::WARBLER_HOME}/warble.rb", Warbler::Config::FILE end end end
define_debug_task()
click to toggle source
# File lib/warbler/task.rb, line 128 def define_debug_task desc "Dump diagnostic information" task "debug" => "files" do require 'yaml' puts config.dump jar.files.each {|k,v| puts "#{k} -> #{String === v ? v : '<blob>'}"} end task "debug:includes" => "files" do puts "", "included files:" puts( *war.app_filelist.include ) end task "debug:excludes" => "files" do puts "", "excluded files:" puts( *war.app_filelist.exclude ) end end
define_extra_tasks()
click to toggle source
# File lib/warbler/task.rb, line 145 def define_extra_tasks @config.define_tasks end
define_files_task()
click to toggle source
# File lib/warbler/task.rb, line 116 def define_files_task task "files" do jar.apply(config) end end
define_jar_task()
click to toggle source
# File lib/warbler/task.rb, line 122 def define_jar_task task "jar" do jar.create(config) end end
define_main_task()
click to toggle source
# File lib/warbler/task.rb, line 78 def define_main_task desc "Create the project #{config.jar_extension} file" task @name do unless @config.features.empty? @config.features.each do |feature| t = "#@name:#{feature}" unless Rake.application.lookup(t) warn "unknown feature `#{feature}', ignoring" next end Rake::Task[t].invoke end end # Invoke this way so custom dependencies can be defined before # the file find routine is run ["#{@name}:files", "#{@name}:jar"].each do |t| Rake::Task[t].invoke end end end
define_pluginize_task()
click to toggle source
# File lib/warbler/task.rb, line 163 def define_pluginize_task task "pluginize" do if !Dir["lib/tasks/warbler*"].empty? && ENV["FORCE"].nil? puts "I found an old nest in lib/tasks; please trash it so I can make a new one" puts "(directory lib/tasks/warbler* exists)" else rm_rf FileList["lib/tasks/warbler*"], :verbose => false mkdir_p "lib/tasks/warbler" File.open("lib/tasks/warbler/warbler.rake", "w") do |f| f.puts "require 'warbler'" f.puts "Warbler::Task.new" end end end end
define_tasks()
click to toggle source
# File lib/warbler/task.rb, line 63 def define_tasks define_main_task namespace name do define_clean_task define_compiled_task define_files_task define_jar_task define_debug_task define_config_task define_pluginize_task define_version_task define_extra_tasks end end
define_version_task()
click to toggle source
# File lib/warbler/task.rb, line 179 def define_version_task task "version" do puts "Warbler version #{Warbler::VERSION}" end end