plugin_manager.rb 3.6 KB

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