Permalink
Browse files

moving plugins to boxgrinder-build-plugins repo finished

  • Loading branch information...
1 parent 430a59d commit 23f12998367da2d4e32a4119db169491decd30c7 @goldmann goldmann committed Jul 5, 2010
View
1 .gitignore
@@ -13,4 +13,5 @@ wizard
.idea
*.gem
appliances
+coverage
View
12 bin/boxgrinder-build
@@ -23,6 +23,7 @@
require 'rubygems'
require 'commander/import'
require 'boxgrinder-core/helpers/log-helper'
+require 'boxgrinder-build/managers/plugin-manager'
require 'boxgrinder-build/helpers/plugin-helper'
require 'boxgrinder-build/appliance'
@@ -39,7 +40,7 @@ gem 'commander', '>= 4.0.3'
#$stderr.reopen('/dev/null')
program :name, 'BoxGrinder Build'
-program :version, '0.4.1'
+program :version, '0.4.2'
program :description, 'A tool for building VM images from simple definition files.'
program :help, 'Hompeage', 'http://www.jboss.org/stormgrind/projects/boxgrinder/build.html'
default_command :build
@@ -75,13 +76,14 @@ module BoxGrinder
raise "Appliance definition file '#{appliance_definition_file}' could not be found" unless File.exists?( appliance_definition_file )
log = LogHelper.new( :threshold => $log_level)
-
+
PluginHelper.new( :options => options, :log => log ).load_plugins
+ PluginManager.instance.log = log
- raise "Not known platform: #{options.platform}. Available platforms: #{PlatformPluginManager.instance.plugins.keys.join(', ')}." if PlatformPluginManager.instance.plugins[options.platform].nil? and options.platform != :none
- raise "Not known delivery type: #{options.delivery}. Available types: #{DeliveryPluginManager.instance.types.keys.join(', ')}." if DeliveryPluginManager.instance.types.keys.include?(options.delivery).nil? and options.delivery != :none
+ raise "Not known platform: #{options.platform}. #{PluginManager.instance.plugins[:platform].empty? ? 'There are no platform plugins, please install one or more.' : "Available types: #{PluginManager.instance.plugin_types( :platform ).join(', ')}."}" if PluginManager.instance.plugins[:platform][options.platform].nil? and options.platform != :none
+ raise "Not known delivery type: #{options.delivery}. #{PluginManager.instance.plugins[:delivery].empty? ? 'There are no delivery plugins, please install one or more.' : "Available types: #{PluginManager.instance.plugin_types( :delivery ).join(', ')}."}" if PluginManager.instance.plugin_types( :delivery ).include?(options.delivery).nil? and options.delivery != :none
-# Appliance.new( appliance_definition_file, :options => options, :log => log ).create
+ Appliance.new( appliance_definition_file, :options => options, :log => log ).create
end
end
end
View
4 boxgrinder-build.gemspec
@@ -3,15 +3,15 @@ require 'rubygems'
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = "boxgrinder-build"
- s.version = "0.4.1"
+ s.version = "0.4.2"
s.author = "BoxGrinder Project"
s.homepage = "http://www.jboss.org/stormgrind/projects/boxgrinder.html"
s.email = "info@boxgrinder.org"
s.summary = "BoxGrinder Build files"
s.files = Dir['lib/boxgrinder-build/**/*'] + Dir['docs/**/*'] << 'README' << 'LICENSE'
s.executables << 'boxgrinder-build'
- s.add_dependency('boxgrinder-core', '>= 0.0.11')
+ s.add_dependency('boxgrinder-core', '>= 0.0.12')
s.add_dependency('aws-s3', '>= 0.6.2')
s.add_dependency('amazon-ec2', '>= 0.9.6')
s.add_dependency('net-sftp', '>= 2.0.4')
View
12 lib/boxgrinder-build/appliance.rb
@@ -44,7 +44,7 @@ def create
@appliance_config = appliance_config_helper.merge(appliance_config.clone.init_arch).initialize_paths
- ApplianceConfigValidator.new( @appliance_config, :os_plugins => OperatingSystemPluginManager.instance.plugins ).validate
+ ApplianceConfigValidator.new( @appliance_config, :os_plugins => PluginManager.instance.plugins[:os] ).validate
if @options.force
@log.info "Removing previous builds for #{@appliance_config.name} appliance..."
@@ -59,11 +59,11 @@ def create
end
def execute_os_plugin
- os_plugin = OperatingSystemPluginManager.instance.plugins[@appliance_config.os.name.to_sym]
+ os_plugin, os_plugin_info = PluginManager.instance.initialize_plugin(:os, @appliance_config.os.name.to_sym )
os_plugin.init( @config, @appliance_config, :log => @log )
if deliverables_exists( os_plugin.deliverables )
- @log.info "Deliverables for #{os_plugin.info[:name]} operating system plugin exists, skipping."
+ @log.info "Deliverables for #{os_plugin_info[:name]} operating system plugin exists, skipping."
return os_plugin.deliverables
end
@@ -80,11 +80,11 @@ def execute_platform_plugin( deliverables )
return deliverables
end
- platform_plugin = PlatformPluginManager.instance.plugins[@options.platform]
+ platform_plugin, platform_plugin_info = PluginManager.instance.initialize_plugin(:platform, @options.platform.to_sym )
platform_plugin.init( @config, @appliance_config, :log => @log )
if deliverables_exists( platform_plugin.deliverables )
- @log.info "Deliverables for #{platform_plugin.info[:name]} platform plugin exists, skipping."
+ @log.info "Deliverables for #{platform_plugin_info[:name]} platform plugin exists, skipping."
return platform_plugin.deliverables
end
@@ -101,7 +101,7 @@ def execute_delivery_plugin( deliverables )
return deliverables
end
- delivery_plugin = DeliveryPluginManager.instance.types[@options.delivery]
+ delivery_plugin, delivery_plugin_info = PluginManager.instance.initialize_plugin(:delivery, @options.delivery.to_sym )
delivery_plugin.init( @config, @appliance_config, :log => @log )
delivery_plugin.execute( deliverables, @options.delivery )
end
View
62 lib/boxgrinder-build/helpers/plugin-helper.rb
@@ -18,64 +18,22 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-require 'boxgrinder-build/managers/operating-system-plugin-manager'
-require 'boxgrinder-build/managers/platform-plugin-manager'
-require 'boxgrinder-build/managers/delivery-plugin-manager'
-require 'boxgrinder-build/managers/delivery-plugin-manager'
+require 'boxgrinder-build/managers/plugin-manager'
require 'rubygems'
module BoxGrinder
- module Plugins
- def plugin( args )
- PluginReader.instance.register_plugin( args )
- end
- end
-end
-
-include BoxGrinder::Plugins
-
-module BoxGrinder
- class PluginReader
- include Singleton
-
- attr_writer :log
-
- def register_plugin( args )
- validate_plugin_args( args )
-
- #TODO add here logger!
- case args[:type]
- when :os
- OperatingSystemPluginManager.instance.initialize_plugin( args, :log => @log )
- when :platform
- PlatformPluginManager.instance.initialize_plugin( args, :log => @log )
- when :delivery
- DeliveryPluginManager.instance.initialize_plugin( args, :log => @log )
- else
- raise "Unsupported type of plugin: #{args[:type]}"
- end
- end
-
- def validate_plugin_args(args)
- raise "No class specified" if args[:class].nil?
- raise "No type specified" if args[:type].nil?
- end
- end
-
class PluginHelper
def initialize( options = {} )
@log = options[:log] || Logger.new(STDOUT)
@options = options[:options]
end
def load_plugins
- PluginReader.instance.log = @log
-
read_and_require
- @os_plugins = OperatingSystemPluginManager.instance.plugins
- @platform_plugins = PlatformPluginManager.instance.plugins
- @delivery_plugins = DeliveryPluginManager.instance.plugins
+ @os_plugins = PluginManager.instance.plugins[:os]
+ @platform_plugins = PluginManager.instance.plugins[:platform]
+ @delivery_plugins = PluginManager.instance.plugins[:delivery]
print_plugins( 'os' ) { @os_plugins }
print_plugins( 'platform' ) { @platform_plugins }
@@ -96,13 +54,17 @@ def parse_plugin_list
end
def read_and_require
- plugins = parse_plugin_list || %w(boxgrinder-build-fedora-os-plugin boxgrinder-build-rhel-os-plugin boxgrinder-build-centos-os-plugin boxgrinder-build-ec2-platform-plugin)
+ plugins = parse_plugin_list || %w(boxgrinder-build-fedora-os-plugin boxgrinder-build-rhel-os-plugin boxgrinder-build-centos-os-plugin boxgrinder-build-ec2-platform-plugin boxgrinder-build-vmware-platform-plugin boxgrinder-build-s3-delivery-plugin boxgrinder-build-sftp-delivery-plugin boxgrinder-build-local-delivery-plugin)
plugins.each do |plugin|
@log.trace "Requiring plugin '#{plugin}'..."
- gem plugin
- require plugin
+ begin
+ gem plugin
+ require plugin
+ rescue Gem::LoadError
+ @log.warn "Specified gem: '#{plugin}' wasn't found. Make sure its name is correct, skipping..." unless plugin.match(/^boxgrinder-build-(.*)-plugin/)
+ end
end
end
@@ -114,7 +76,7 @@ def print_plugins( type )
@log.debug "We have #{plugins.size} #{type} plugin(s) registered"
plugins.each_value do |plugin_info|
- @log.debug "- plugin for #{plugin_info[:info][:full_name]}."
+ @log.debug "- plugin for #{plugin_info[:full_name]}."
end
@log.debug "Plugins loaded."
View
71 lib/boxgrinder-build/helpers/rake-helper.rb
@@ -1,71 +0,0 @@
-# JBoss, Home of Professional Open Source
-# Copyright 2009, Red Hat Middleware LLC, and individual contributors
-# by the @authors tag. See the copyright.txt in the distribution for a
-# full listing of individual contributors.
-#
-# This is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This software is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this software; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-
-require 'rubygems'
-require 'boxgrinder-build/boxgrinder'
-require 'boxgrinder-core/helpers/log-helper'
-
-gem 'amazon-ec2', '>= 0.9.6'
-gem 'aws-s3', '>= 0.6.2'
-gem 'net-sftp', '>= 2.0.4'
-gem 'net-ssh', '>= 2.0.20'
-
-module Rake
- class Task
- alias_method :execute_original_boxgrinder, :execute
-
- def execute( args = nil )
- begin
- execute_original_boxgrinder( args )
- rescue => e
- log = BoxGrinder::LOG
- log.fatal e.info
- log.fatal "Aborting: #{e.message}. See previous errors for more information."
- abort
- end
- end
- end
-end
-
-module BoxGrinder
-
- LOG = LogHelper.new
-
- class RakeHelper
- def initialize( project_config = {} )
- log = LOG
- begin
- log.debug "Running new Rake session..."
- @config = BoxGrinder.new( project_config ).config
- rescue ValidationError => e
- log.fatal "ValidationError: #{e.message}."
- abort
- rescue => e
- log.fatal e
- log.fatal "Aborting: #{e.message}. See previous errors for more information."
- abort
- end
- end
-
- attr_reader :config
- end
-end
-
-
View
39 lib/boxgrinder-build/managers/delivery-plugin-manager.rb
@@ -1,39 +0,0 @@
-# JBoss, Home of Professional Open Source
-# Copyright 2009, Red Hat Middleware LLC, and individual contributors
-# by the @authors tag. See the copyright.txt in the distribution for a
-# full listing of individual contributors.
-#
-# This is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This software is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this software; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-
-require 'boxgrinder-build/managers/base-plugin-manager'
-
-module BoxGrinder
- class DeliveryPluginManager < BasePluginManager
- def types
- t = {}
-
- @plugins.each_value do |plugin|
- plugin.info[:type].each do |type|
- t[type] = plugin
- end
-
- end
-
- t
- end
-
- end
-end
View
6 lib/boxgrinder-build/managers/operating-system-plugin-manager.rb
@@ -1,6 +0,0 @@
-require 'boxgrinder-build/managers/base-plugin-manager'
-
-module BoxGrinder
- class OperatingSystemPluginManager < BasePluginManager
- end
-end
View
26 lib/boxgrinder-build/managers/platform-plugin-manager.rb
@@ -1,26 +0,0 @@
-# JBoss, Home of Professional Open Source
-# Copyright 2009, Red Hat Middleware LLC, and individual contributors
-# by the @authors tag. See the copyright.txt in the distribution for a
-# full listing of individual contributors.
-#
-# This is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation; either version 2.1 of
-# the License, or (at your option) any later version.
-#
-# This software is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this software; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-
-require 'boxgrinder-build/managers/base-plugin-manager'
-
-module BoxGrinder
- class PlatformPluginManager < BasePluginManager
- end
-end
View
51 ...der-build/managers/base-plugin-manager.rb → ...xgrinder-build/managers/plugin-manager.rb
@@ -21,29 +21,64 @@
require 'singleton'
module BoxGrinder
- class BasePluginManager
+ module Plugins
+ def plugin( args )
+ PluginManager.instance.register_plugin( args )
+ end
+ end
+end
+
+include BoxGrinder::Plugins
+
+module BoxGrinder
+ class PluginManager
include Singleton
def initialize
- @plugins = {}
+ @plugins = { :delivery => {}, :os => {}, :platform => {}}
end
- def initialize_plugin( info, options = {} )
+ def register_plugin( info )
+ validate_plugin_info( info )
+
raise "We already have registered plugin for #{info[:name]}." unless @plugins[info[:name]].nil?
+ @plugins[info[:type]][info[:name]] = info
+ self
+ end
+
+ def validate_plugin_info( info )
+ raise "No name specified for your plugin" if info[:name].nil?
+ raise "No class specified for your plugin" if info[:class].nil?
+ raise "No type specified for your plugin" if info[:type].nil?
+ end
+
+ def initialize_plugin( type, name, options = {} )
begin
- plugin = info[:class].new
+ plugin = @plugins[type][name][:class].new
rescue => e
- raise "Error while initializing #{info[:class]} plugin.", e
+ raise "Error while initializing #{@plugins[type][name][:class]} plugin.", e
end
- plugin.instance_variable_set( :@log, options[:log] ) unless options[:log].nil?
+ [ plugin, @plugins[type][name] ]
+ end
+
+ def plugin_types( type )
+ types = []
- @plugins[info[:name]] = { :info => info, :plugin => plugin }
+ available_plugins_for_selected_type = @plugins[type]
- self
+ unless available_plugins_for_selected_type.nil?
+ available_plugins_for_selected_type.each_value do |info|
+ types << info[:types] unless info[:types].nil?
+ types << info[:name]
+ end
+ end
+
+ types.flatten
end
attr_reader :plugins
+ attr_accessor :log
end
end
View
1 lib/boxgrinder-build/plugins/base-operating-system-plugin.rb
@@ -18,7 +18,6 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-require 'boxgrinder-build/managers/operating-system-plugin-manager'
require 'boxgrinder-build/plugins/base-plugin'
module BoxGrinder
View
1 lib/boxgrinder-build/plugins/base-platform-plugin.rb
@@ -18,7 +18,6 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-require 'boxgrinder-build/managers/platform-plugin-manager'
require 'boxgrinder-build/plugins/base-plugin'
module BoxGrinder
View
4 spec/Rakefile
@@ -5,6 +5,8 @@ desc "Run all examples"
Spec::Rake::SpecTask.new('examples') do |t|
t.libs.unshift "../../boxgrinder-core/lib"
t.libs.unshift "../../boxgrinder-core/spec"
-
+
t.spec_files = FileList['**/*-spec.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'spec']
end
View
6 spec/helpers/appliance-customize-helper-spec.rb
@@ -0,0 +1,6 @@
+require 'boxgrinder-build/helpers/appliance-customize-helper'
+
+module BoxGrinder
+ describe ApplianceCustomizeHelper do
+ end
+end
View
6 spec/helpers/guestfs-helper-spec.rb
@@ -0,0 +1,6 @@
+require 'boxgrinder-build/helpers/guestfs-helper'
+
+module BoxGrinder
+ describe GuestFSHelper do
+ end
+end
View
6 spec/helpers/package-helper-spec.rb
@@ -0,0 +1,6 @@
+require 'boxgrinder-build/helpers/package-helper'
+
+module BoxGrinder
+ describe PackageHelper do
+ end
+end
View
2 spec/helpers/plugin-helper-spec.rb
@@ -34,7 +34,7 @@ module BoxGrinder
end
it "should require default plugins" do
- plugins = %w(boxgrinder-build-fedora-os-plugin boxgrinder-build-rhel-os-plugin boxgrinder-build-centos-os-plugin boxgrinder-build-ec2-platform-plugin)
+ plugins = %w(boxgrinder-build-fedora-os-plugin boxgrinder-build-rhel-os-plugin boxgrinder-build-centos-os-plugin boxgrinder-build-ec2-platform-plugin boxgrinder-build-vmware-platform-plugin boxgrinder-build-s3-delivery-plugin boxgrinder-build-sftp-delivery-plugin boxgrinder-build-local-delivery-plugin)
plugins.each do |plugin|
@plugin_helper.should_receive(:gem).ordered.with(plugin)
View
6 spec/managers/plugin-manager-spec.rb
@@ -0,0 +1,6 @@
+require 'boxgrinder-build/managers/plugin-manager'
+
+module BoxGrinder
+ describe PluginManager do
+ end
+end
View
6 spec/plugins/base-plugin-spec.rb
@@ -0,0 +1,6 @@
+require 'boxgrinder-build/plugins/base-plugin'
+
+module BoxGrinder
+ describe BasePlugin do
+ end
+end
View
1 spec/tests.rb
@@ -1 +0,0 @@
-require 'helpers/plugin-helper-spec'

0 comments on commit 23f1299

Please sign in to comment.