# p4util/task.rb - Rake tasks require 'commands' require 'conventions' require 'fileutils' require 'ostruct' require 'rake/tasklib' module P4Util # Creates a few tasks to allow launching init and kill commands via rake # tasks, which should make it easy to script with test tasks, for example. # # Example: # # require 'p4util/tasks' # # P4Util::Tasks.new do |p4util| # p4util.version = 'r14.2' # Indicate p4d version to download # end # # Tasks: # - p4init # - p4kill # - p4reset class Tasks < Rake::TaskLib # The task base name, defaults to ':p4' attr_accessor :basename # P4 Version to use, defaults to 'r14.2' attr_accessor :version # The directory containing p4 init scripts, defaults to 'p4init' attr_accessor :p4_init_dir def initialize basename = :p4 @basename = basename @version = 'r14.2' @p4_init_dir = 'p4init' yield self if block_given? define_tasks end # Create the tasks defined by this task library def define_tasks desc init_task_description task init_task_name do options = OpenStruct.new options.params = [p4_init_dir, '--version', version] Commands.init(options) end desc kill_task_description task kill_task_name do options = OpenStruct.new options.params = ['--version', version] Commands.kill(options) end desc reset_task_description task reset_task_name => kill_task_name do FileUtils.rmtree(Conventions.p4droot_dir) end self end def init_task_description "Initializes a p4d instance, and ensures it's downloaded and running" end def init_task_name "#{basename}init" end def kill_task_description 'Halt any locally running p4d instance' end def kill_task_name "#{basename}kill" end def reset_task_description 'Cleans out the current p4droot working directory (after killing p4d)' end def reset_task_name "#{basename}reset" end end end