plugin_manager.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. require 'ceedling/constants'
  2. class PluginManager
  3. constructor :configurator, :plugin_manager_helper, :streaminator, :reportinator, :system_wrapper
  4. def setup
  5. @build_fail_registry = []
  6. @plugin_objects = [] # so we can preserve order
  7. end
  8. def load_plugin_scripts(script_plugins, system_objects)
  9. environment = []
  10. script_plugins.each do |plugin|
  11. # protect against instantiating object multiple times due to processing config multiple times (option files, etc)
  12. next if (@plugin_manager_helper.include?(@plugin_objects, plugin))
  13. begin
  14. @system_wrapper.require_file( "#{plugin}.rb" )
  15. object = @plugin_manager_helper.instantiate_plugin_script( camelize(plugin), system_objects, plugin )
  16. @plugin_objects << object
  17. environment += object.environment
  18. # add plugins to hash of all system objects
  19. system_objects[plugin.downcase.to_sym] = object
  20. rescue
  21. puts "Exception raised while trying to load plugin: #{plugin}"
  22. raise
  23. end
  24. end
  25. yield( { :environment => environment } ) if (environment.size > 0)
  26. end
  27. def plugins_failed?
  28. return (@build_fail_registry.size > 0)
  29. end
  30. def print_plugin_failures
  31. if (@build_fail_registry.size > 0)
  32. report = @reportinator.generate_banner('BUILD FAILURE SUMMARY')
  33. @build_fail_registry.each do |failure|
  34. report += "#{' - ' if (@build_fail_registry.size > 1)}#{failure}\n"
  35. end
  36. report += "\n"
  37. @streaminator.stderr_puts(report, Verbosity::ERRORS)
  38. end
  39. end
  40. def register_build_failure(message)
  41. @build_fail_registry << message if (message and not message.empty?)
  42. end
  43. #### execute all plugin methods ####
  44. def pre_mock_generate(arg_hash); execute_plugins(:pre_mock_generate, arg_hash); end
  45. def post_mock_generate(arg_hash); execute_plugins(:post_mock_generate, arg_hash); end
  46. def pre_runner_generate(arg_hash); execute_plugins(:pre_runner_generate, arg_hash); end
  47. def post_runner_generate(arg_hash); execute_plugins(:post_runner_generate, arg_hash); end
  48. def pre_compile_execute(arg_hash); execute_plugins(:pre_compile_execute, arg_hash); end
  49. def post_compile_execute(arg_hash); execute_plugins(:post_compile_execute, arg_hash); end
  50. def pre_link_execute(arg_hash); execute_plugins(:pre_link_execute, arg_hash); end
  51. def post_link_execute(arg_hash); execute_plugins(:post_link_execute, arg_hash); end
  52. def pre_test_fixture_execute(arg_hash); execute_plugins(:pre_test_fixture_execute, arg_hash); end
  53. def post_test_fixture_execute(arg_hash)
  54. # special arbitration: raw test results are printed or taken over by plugins handling the job
  55. @streaminator.stdout_puts(arg_hash[:shell_result][:output]) if (@configurator.plugins_display_raw_test_results)
  56. execute_plugins(:post_test_fixture_execute, arg_hash)
  57. end
  58. def pre_test(test); execute_plugins(:pre_test, test); end
  59. def post_test(test); execute_plugins(:post_test, test); end
  60. def pre_release; execute_plugins(:pre_release); end
  61. def post_release; execute_plugins(:post_release); end
  62. def pre_build; execute_plugins(:pre_build); end
  63. def post_build; execute_plugins(:post_build); end
  64. def post_error; execute_plugins(:post_error); end
  65. def summary; execute_plugins(:summary); end
  66. private ####################################
  67. def camelize(underscored_name)
  68. return underscored_name.gsub(/(_|^)([a-z0-9])/) {$2.upcase}
  69. end
  70. def execute_plugins(method, *args)
  71. @plugin_objects.each do |plugin|
  72. begin
  73. plugin.send(method, *args) if plugin.respond_to?(method)
  74. rescue
  75. puts "Exception raised in plugin: #{plugin.name}, in method #{method}"
  76. raise
  77. end
  78. end
  79. end
  80. end