class Glue::Tasks

Collects up results from running different tasks.

tasks can be added with +task.add(task_class)+

All .rb files in tasks/ will be loaded.

Attributes

tasks_run[R]

Public Class Methods

add(klass) click to toggle source

Add a task. This will call klass.new when running tests

# File lib/glue/tasks.rb, line 15
def self.add klass
  @tasks << klass unless @tasks.include? klass
end
add_optional(klass) click to toggle source

Add an optional task

# File lib/glue/tasks.rb, line 20
def self.add_optional klass
  @optional_tasks << klass unless @tasks.include? klass
end
initialize_tasks(task_directory = "") click to toggle source
# File lib/glue/tasks.rb, line 32
def self.initialize_tasks task_directory = ""
  #Load all files in task_directory
  Dir.glob(File.join(task_directory, "*.rb")).sort.each do |f|
    require f
  end
end
new(options = { }) click to toggle source

No need to use this directly.

# File lib/glue/tasks.rb, line 40
def initialize options = { }
  @warnings = []
  @tasks_run = []
end
optional_tasks() click to toggle source
# File lib/glue/tasks.rb, line 28
def self.optional_tasks
  @optional_tasks
end
run_tasks(target, stage, tracker) click to toggle source

Run all the tasks on the given Tracker. Returns a new instance of tasks with the results.

# File lib/glue/tasks.rb, line 52
def self.run_tasks(target, stage, tracker)
  task_runner = self.new

  trigger = Glue::Event.new(tracker.options[:appname])
  trigger.path = target

  self.tasks_to_run(tracker).each do |c|
    task_name = get_task_name c

    #Run or don't run task based on options
    #Now case-insensitive specifiers:  nodesecurityproject = Glue::NodeSecurityProject

    if tracker.options[:skip_tasks]
      skip_tasks = tracker.options[:skip_tasks].map {|task| task.downcase}
    end
    if (tracker.options[:run_tasks])
      run_tasks = tracker.options[:run_tasks].map {|task| task.downcase}
    end

    unless skip_tasks.include? task_name.downcase or
      (run_tasks and not run_tasks.include? task_name.downcase)

      task = c.new(trigger, tracker)
      begin
        if task.supported? and task.stage == stage
          if task.labels.intersect? tracker.options[:labels] or          # Only run tasks with labels
               ( run_tasks and run_tasks.include? task_name.downcase )   # or that are explicitly requested.
            Glue.notify "#{stage} - #{task_name} - #{task.labels}"
            task.run
            task.analyze
            task.findings.each do | finding |
              tracker.report finding
            end
         end
        end
      rescue => e
        Glue.notify e.message
        tracker.error e
      end

      task.warnings.each do |w|
        task_runner.add_warning w
      end

      #Maintain list of which tasks were run
      #mainly for reporting purposes
      task_runner.tasks_run << task_name[5..-1]
    end
  end

  task_runner
end
tasks() click to toggle source
# File lib/glue/tasks.rb, line 24
def self.tasks
  @tasks + @optional_tasks
end

Private Class Methods

get_task_name(task_class) click to toggle source
# File lib/glue/tasks.rb, line 108
def self.get_task_name task_class
  task_class.to_s.split("::").last
end
tasks_to_run(tracker) click to toggle source
# File lib/glue/tasks.rb, line 112
def self.tasks_to_run tracker
  if tracker.options[:run_all_tasks] or tracker.options[:run_tasks]
    @tasks + @optional_tasks
  else
    @tasks
  end
end

Public Instance Methods

add_warning(warning) click to toggle source

Add Warning to list of warnings to report.

# File lib/glue/tasks.rb, line 46
def add_warning warning
  @warnings << warning
end