Permalink
Browse files

Move PluginRegistry functionality into PluginRunner

Test plan:
- Unit tests pass

Change-Id: Ibccbcbee4d271e547ea307db522cfb4de981c32c
  • Loading branch information...
mpage
mpage committed Oct 24, 2011
1 parent 3a58232 commit 0d85e28d6c5594dc52559648bc7cd1dda348a2b1
@@ -3,7 +3,6 @@
require 'vcap/stager/errors'
require 'vcap/stager/plugin_action_proxy'
require 'vcap/stager/plugin_runner'
-require 'vcap/stager/plugin_registry'
require 'vcap/stager/task'
require 'vcap/stager/task_logger'
require 'vcap/stager/task_manager'
@@ -1,35 +0,0 @@
-module VCAP
- module Stager
- end
-end
-
-# This is a simple container class for all plugins that should be invoked during
-# staging. The contract between the stager and plugins is simple:
-#
-# A staging plugin MUST call VCAP::Stager::PluginRegistry.register_plugin() with
-# an instance of itself when it is required.
-class VCAP::Stager::PluginRegistry
- class << self
- def method_missing(method, *args, &block)
- @registry ||= VCAP::Stager::PluginRegistry.new
- @registry.send(method, *args, &block)
- end
- end
-
- def initialize
- @plugins = []
- end
-
- attr_reader :plugins
-
- # Registers a plugin to be invoked during staging.
- #
- # @param Object Instance of a class implementing the staging plugin interface
- def register_plugin(plugin)
- @plugins << plugin
- end
-
- def reset
- @plugins = []
- end
-end
@@ -7,7 +7,6 @@
require 'vcap/stager/errors'
require 'vcap/stager/droplet'
require 'vcap/stager/plugin_action_proxy'
-require 'vcap/stager/plugin_registry'
module VCAP
module Stager
@@ -17,6 +16,20 @@ module Stager
# Responsible for orchestrating the execution of all staging plugins selected
# by the user.
class VCAP::Stager::PluginRunner
+ class << self
+ attr_reader :registered_plugins
+
+ def register_plugins(*plugins)
+ @registered_plugins ||= []
+ plugins.each {|plugin| @registered_plugins << plugin }
+ end
+
+ # Testing only
+ def reset_registered_plugins
+ @registered_plugins = []
+ end
+ end
+
# @param source_dir String Directory containing application source
# @param dest_dir String Directory where the staged droplet should live
# @param app_properties
@@ -41,9 +54,6 @@ def run_plugins
end
framework_plugin, feature_plugins = collect_plugins
- unless framework_plugin
- raise VCAP::Stager::MissingFrameworkPluginError, "No framework plugin found"
- end
@logger.info("Setting up base droplet structure")
@droplet.create_skeleton(@source_dir)
@@ -71,7 +81,7 @@ def run_plugins
def collect_plugins
framework_plugin = nil
feature_plugins = []
- for plugin in VCAP::Stager::PluginRegistry.plugins
+ for plugin in self.class.registered_plugins
ptype = plugin.plugin_type
case ptype
when :framework
@@ -91,6 +101,9 @@ def collect_plugins
end
end
+ unless framework_plugin
+ raise VCAP::Stager::MissingFrameworkPluginError, "No framework plugin found"
+ end
[framework_plugin, feature_plugins]
end
@@ -27,7 +27,7 @@
'fds' => 1024,
}
}
- VCAP::Stager::PluginRegistry.reset()
+ VCAP::Stager::PluginRunner.reset_registered_plugins()
end
after :each do
@@ -53,8 +53,9 @@
it 'should raise an error if > 1 framework plugins are supplied' do
plugins = []
2.times do |i|
- p = create_mock_plugin("plugin_#{i}", :framework)
- VCAP::Stager::PluginRegistry.register_plugin(p)
+ name = "plugin_#{i}"
+ p = create_mock_plugin(name, :framework)
+ VCAP::Stager::PluginRunner.register_plugins(p)
end
orch = VCAP::Stager::PluginRunner.new(@src_dir, @dst_dir, @app_props, @cc_info)
expect do
@@ -64,7 +65,7 @@
it 'should raise an error if a plugin of unknown type is supplied' do
p = create_mock_plugin(:plugin0, :invalid_plugin_type)
- VCAP::Stager::PluginRegistry.register_plugin(p)
+ VCAP::Stager::PluginRunner.register_plugins(p)
orch = VCAP::Stager::PluginRunner.new(@src_dir, @dst_dir, @app_props, @cc_info)
expect do
orch.run_plugins
@@ -74,9 +75,10 @@
it 'should call stage on each of the registered plugins' do
plugin_types = [:framework, :feature, :feature]
plugin_types.each_with_index do |ptype, ii|
- p = create_mock_plugin("plugin_#{ii}", ptype)
+ name = "plugin_#{ii}"
+ p = create_mock_plugin(name, ptype)
p.should_receive(:stage).with(any_args())
- VCAP::Stager::PluginRegistry.register_plugin(p)
+ VCAP::Stager::PluginRunner.register_plugins(p)
end
orch = VCAP::Stager::PluginRunner.new(@src_dir, @dst_dir, @app_props, @cc_info)
orch.run_plugins

0 comments on commit 0d85e28

Please sign in to comment.