mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-09 10:27:26 +00:00
Fixed race condition that occurs when 'requiring' plugins
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
|
require 'thread'
|
||||||
|
|
||||||
class CMockPluginManager
|
class CMockPluginManager
|
||||||
|
|
||||||
attr_accessor :plugins
|
attr_accessor :plugins
|
||||||
@@ -14,14 +16,7 @@ class CMockPluginManager
|
|||||||
plugins_to_load.each do |plugin|
|
plugins_to_load.each do |plugin|
|
||||||
plugin_name = plugin.to_s
|
plugin_name = plugin.to_s
|
||||||
object_name = "CMockGeneratorPlugin" + camelize(plugin_name)
|
object_name = "CMockGeneratorPlugin" + camelize(plugin_name)
|
||||||
begin
|
self.class.plugin_require_mutex.synchronize { load_plugin(plugin_name, object_name, config, utils) }
|
||||||
unless (Object.const_defined? object_name)
|
|
||||||
require "#{File.expand_path(File.dirname(__FILE__))}/cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
|
||||||
end
|
|
||||||
@plugins << eval("#{object_name}.new(config, utils)")
|
|
||||||
rescue
|
|
||||||
raise "ERROR: CMock unable to load plugin '#{plugin_name}'"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@plugins.sort! {|a,b| a.priority <=> b.priority }
|
@plugins.sort! {|a,b| a.priority <=> b.priority }
|
||||||
end
|
end
|
||||||
@@ -37,4 +32,24 @@ class CMockPluginManager
|
|||||||
def camelize(lower_case_and_underscored_word)
|
def camelize(lower_case_and_underscored_word)
|
||||||
lower_case_and_underscored_word.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
lower_case_and_underscored_word.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def self.plugin_require_mutex
|
||||||
|
@mutex ||= Mutex.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_plugin(plugin_name, object_name, config, utils)
|
||||||
|
begin
|
||||||
|
unless (Object.const_defined? object_name)
|
||||||
|
file_name = "#{File.expand_path(File.dirname(__FILE__))}/cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
||||||
|
require file_name
|
||||||
|
end
|
||||||
|
class_name = Object.const_get(object_name)
|
||||||
|
@plugins << class_name.new(config, utils)
|
||||||
|
rescue
|
||||||
|
file_name = "#{File.expand_path(File.dirname(__FILE__))}/cmock_generator_plugin_#{plugin_name.downcase}.rb"
|
||||||
|
raise "ERROR: CMock unable to load plugin '#{plugin_name}' '#{object_name}' #{file_name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user