Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

moving plugins to boxgrinder-build-plugins repo finished

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

0 comments on commit 23f1299

Please sign in to comment.
Something went wrong with that request. Please try again.