Class: Pipeline::Tasks
- Inherits:
-
Object
- Object
- Pipeline::Tasks
- Defined in:
- lib/pipeline/tasks.rb
Overview
Collects up results from running different tasks.
tasks can be added with task.add(task_class)
All .rb files in tasks/ will be loaded.
Instance Attribute Summary collapse
-
#tasks_run ⇒ Object
readonly
Returns the value of attribute tasks_run.
Class Method Summary collapse
-
.add(klass) ⇒ Object
Add a task.
-
.add_optional(klass) ⇒ Object
Add an optional task.
- .initialize_tasks(task_directory = "") ⇒ Object
- .optional_tasks ⇒ Object
-
.run_tasks(target, stage, tracker) ⇒ Object
Run all the tasks on the given Tracker.
- .tasks ⇒ Object
Instance Method Summary collapse
-
#add_warning(warning) ⇒ Object
Add Warning to list of warnings to report.
-
#initialize(options = { }) ⇒ Tasks
constructor
No need to use this directly.
Constructor Details
#initialize(options = { }) ⇒ Tasks
No need to use this directly.
40 41 42 43 |
# File 'lib/pipeline/tasks.rb', line 40 def initialize = { } @warnings = [] @tasks_run = [] end |
Instance Attribute Details
#tasks_run ⇒ Object (readonly)
Returns the value of attribute tasks_run.
12 13 14 |
# File 'lib/pipeline/tasks.rb', line 12 def tasks_run @tasks_run end |
Class Method Details
.add(klass) ⇒ Object
Add a task. This will call klass.new
when running tests
15 16 17 |
# File 'lib/pipeline/tasks.rb', line 15 def self.add klass @tasks << klass unless @tasks.include? klass end |
.add_optional(klass) ⇒ Object
Add an optional task
20 21 22 |
# File 'lib/pipeline/tasks.rb', line 20 def self.add_optional klass @optional_tasks << klass unless @tasks.include? klass end |
.initialize_tasks(task_directory = "") ⇒ Object
32 33 34 35 36 37 |
# File 'lib/pipeline/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 |
.optional_tasks ⇒ Object
28 29 30 |
# File 'lib/pipeline/tasks.rb', line 28 def self.optional_tasks @optional_tasks end |
.run_tasks(target, stage, tracker) ⇒ Object
Run all the tasks on the given Tracker. Returns a new instance of tasks with the results.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/pipeline/tasks.rb', line 52 def self.run_tasks(target, stage, tracker) task_runner = self.new trigger = Pipeline::Event.new(tracker.[: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 = Pipeline::NodeSecurityProject if tracker.[:skip_tasks] skip_tasks = tracker.[:skip_tasks].map {|task| task.downcase} end if (tracker.[:run_tasks]) run_tasks = tracker.[: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.[:labels] or # Only run tasks with labels ( run_tasks and run_tasks.include? task_name.downcase ) # or that are explicitly requested. Pipeline.notify "#{stage} - #{task_name} - #{task.labels}" task.run task.analyze task.findings.each do | finding | tracker.report finding end end end rescue => e Pipeline.notify e. 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 ⇒ Object
24 25 26 |
# File 'lib/pipeline/tasks.rb', line 24 def self.tasks @tasks + @optional_tasks end |
Instance Method Details
#add_warning(warning) ⇒ Object
Add Warning to list of warnings to report.
46 47 48 |
# File 'lib/pipeline/tasks.rb', line 46 def add_warning warning @warnings << warning end |