| Class | BoxGrinder::BasePlugin |
| In: |
lib/boxgrinder-build/plugins/base-plugin.rb
lib/boxgrinder-build/plugins/base-plugin.rb |
| Parent: | Object |
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 32
32: def initialize
33: @plugin_config = {}
34:
35: @deliverables = OpenCascade.new
36: @supported_oses = OpenCascade.new
37: @target_deliverables = OpenCascade.new
38: @dir = OpenCascade.new
39: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 32
32: def initialize
33: @plugin_config = {}
34:
35: @deliverables = OpenCascade.new
36: @supported_oses = OpenCascade.new
37: @target_deliverables = OpenCascade.new
38: @dir = OpenCascade.new
39: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 101
101: def current_platform
102: platform = :raw
103:
104: if @previous_plugin_info[:type] == :platform
105: platform = @previous_plugin_info[:name]
106: end unless @previous_plugin_info.nil?
107:
108: platform.to_s
109: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 101
101: def current_platform
102: platform = :raw
103:
104: if @previous_plugin_info[:type] == :platform
105: platform = @previous_plugin_info[:name]
106: end unless @previous_plugin_info.nil?
107:
108: platform.to_s
109: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 165
165: def deliverables
166: @target_deliverables
167: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 165
165: def deliverables
166: @target_deliverables
167: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 150
150: def deliverables_exists?
151: raise "You can only check deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
152:
153: exists = true
154:
155: @target_deliverables.each_value do |file|
156: unless File.exists?(file)
157: exists = false
158: break
159: end
160: end
161:
162: exists
163: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 150
150: def deliverables_exists?
151: raise "You can only check deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
152:
153: exists = true
154:
155: @target_deliverables.each_value do |file|
156: unless File.exists?(file)
157: exists = false
158: break
159: end
160: end
161:
162: exists
163: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 119
119: def execute(args = nil)
120: raise "You can only execute the plugin after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
121: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 119
119: def execute(args = nil)
120: raise "You can only execute the plugin after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
121: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 41
41: def init(config, appliance_config, options = {})
42: @config = config
43: @appliance_config = appliance_config
44: @options = options
45: @log = options[:log] || LogHelper.new
46: @exec_helper = options[:exec_helper] || ExecHelper.new(:log => @log)
47: @image_helper = options[:image_helper] || ImageHelper.new(@config, @appliance_config, :log => @log)
48: @previous_plugin_info = options[:previous_plugin_info]
49: @previous_deliverables = options[:previous_deliverables] || OpenCascade.new
50:
51: @plugin_info = options[:plugin_info]
52:
53: @dir.base = "#{@appliance_config.path.build}/#{@plugin_info[:name]}-plugin"
54: @dir.tmp = "#{@dir.base}/tmp"
55:
56: read_plugin_config
57: merge_plugin_config
58:
59: @move_deliverables = true
60: @initialized = true
61:
62: after_init
63:
64: self
65: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 41
41: def init(config, appliance_config, options = {})
42: @config = config
43: @appliance_config = appliance_config
44: @options = options
45: @log = options[:log] || LogHelper.new
46: @exec_helper = options[:exec_helper] || ExecHelper.new(:log => @log)
47: @image_helper = options[:image_helper] || ImageHelper.new(@config, @appliance_config, :log => @log)
48: @previous_plugin_info = options[:previous_plugin_info]
49: @previous_deliverables = options[:previous_deliverables] || OpenCascade.new
50:
51: @plugin_info = options[:plugin_info]
52:
53: @dir.base = "#{@appliance_config.path.build}/#{@plugin_info[:name]}-plugin"
54: @dir.tmp = "#{@dir.base}/tmp"
55:
56: read_plugin_config
57: merge_plugin_config
58:
59: @move_deliverables = true
60: @initialized = true
61:
62: after_init
63:
64: self
65: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 84
84: def is_supported_os?
85: return true if @supported_oses.empty?
86: return false unless !@supported_oses[@appliance_config.os.name].nil? and @supported_oses[@appliance_config.os.name].include?(@appliance_config.os.version)
87: true
88: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 84
84: def is_supported_os?
85: return true if @supported_oses.empty?
86: return false unless !@supported_oses[@appliance_config.os.name].nil? and @supported_oses[@appliance_config.os.name].include?(@appliance_config.os.version)
87: true
88: end
This merges the plugin config with configuration provided in command line
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 180
180: def merge_plugin_config
181: config =
182: case @plugin_info[:type]
183: when :os
184: @config.os_config
185: when :platform
186: @config.platform_config
187: when :delivery
188: @config.delivery_config
189: end
190:
191: @plugin_config.merge!(config)
192: end
This merges the plugin config with configuration provided in command line
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 180
180: def merge_plugin_config
181: config =
182: case @plugin_info[:type]
183: when :os
184: @config.os_config
185: when :platform
186: @config.platform_config
187: when :delivery
188: @config.delivery_config
189: end
190:
191: @plugin_config.merge!(config)
192: end
This reads the plugin config from file
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 174
174: def read_plugin_config
175: return if @config[:plugins].nil? or @config[:plugins][@plugin_info[:name].to_s].nil?
176: @plugin_config = @config[:plugins][@plugin_info[:name].to_s]
177: end
This reads the plugin config from file
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 174
174: def read_plugin_config
175: return if @config[:plugins].nil? or @config[:plugins][@plugin_info[:name].to_s].nil?
176: @plugin_config = @config[:plugins][@plugin_info[:name].to_s]
177: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 67
67: def register_deliverable(deliverable)
68: raise "You can only register deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
69: raise "Please specify deliverables as Hash, not #{deliverable.class}." unless deliverable.is_a?(Hash)
70:
71: deliverable.each do |name, path|
72: @deliverables[name] = "#{@dir.tmp}/#{path}"
73: @target_deliverables[name] = "#{@dir.base}/#{path}"
74: end
75: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 67
67: def register_deliverable(deliverable)
68: raise "You can only register deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
69: raise "Please specify deliverables as Hash, not #{deliverable.class}." unless deliverable.is_a?(Hash)
70:
71: deliverable.each do |name, path|
72: @deliverables[name] = "#{@dir.tmp}/#{path}"
73: @target_deliverables[name] = "#{@dir.base}/#{path}"
74: end
75: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 77
77: def register_supported_os(name, versions)
78: raise "You can register supported operating system only after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
79:
80: @supported_oses[name] = OpenCascade.new if @supported_oses[name].nil?
81: @supported_oses[name] = versions
82: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 77
77: def register_supported_os(name, versions)
78: raise "You can register supported operating system only after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
79:
80: @supported_oses[name] = OpenCascade.new if @supported_oses[name].nil?
81: @supported_oses[name] = versions
82: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 123
123: def run(*args)
124: unless is_supported_os?
125: @log.error "#{@plugin_info[:full_name]} plugin supports following operating systems: #{supported_oses}. Your appliance contains #{@appliance_config.os.name} #{@appliance_config.os.version} operating system which is not supported by this plugin, sorry."
126: return
127: end
128:
129: FileUtils.rm_rf @dir.tmp
130: FileUtils.mkdir_p @dir.tmp
131:
132: execute(*args)
133:
134: # TODO execute post commands for platform plugins here?
135:
136: @deliverables.each do |name, path|
137: @log.trace "Moving '#{path}' deliverable to target destination '#{@target_deliverables[name]}'..."
138: FileUtils.mv(path, @target_deliverables[name])
139: end if @move_deliverables
140:
141: FileUtils.rm_rf @dir.tmp
142: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 123
123: def run(*args)
124: unless is_supported_os?
125: @log.error "#{@plugin_info[:full_name]} plugin supports following operating systems: #{supported_oses}. Your appliance contains #{@appliance_config.os.name} #{@appliance_config.os.version} operating system which is not supported by this plugin, sorry."
126: return
127: end
128:
129: FileUtils.rm_rf @dir.tmp
130: FileUtils.mkdir_p @dir.tmp
131:
132: execute(*args)
133:
134: # TODO execute post commands for platform plugins here?
135:
136: @deliverables.each do |name, path|
137: @log.trace "Moving '#{path}' deliverable to target destination '#{@target_deliverables[name]}'..."
138: FileUtils.mv(path, @target_deliverables[name])
139: end if @move_deliverables
140:
141: FileUtils.rm_rf @dir.tmp
142: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 169
169: def set_default_config_value(key, value)
170: @plugin_config[key] = @plugin_config[key].nil? ? value : @plugin_config[key]
171: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 169
169: def set_default_config_value(key, value)
170: @plugin_config[key] = @plugin_config[key].nil? ? value : @plugin_config[key]
171: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 90
90: def supported_oses
91: supported = ""
92:
93: @supported_oses.sort.each do |name, versions|
94: supported << ", " unless supported.empty?
95: supported << "#{name} (versions: #{versions.join(", ")})"
96: end
97:
98: supported
99: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 90
90: def supported_oses
91: supported = ""
92:
93: @supported_oses.sort.each do |name, versions|
94: supported << ", " unless supported.empty?
95: supported << "#{name} (versions: #{versions.join(", ")})"
96: end
97:
98: supported
99: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 111
111: def validate_plugin_config(fields = [], doc = nil)
112: more_info = doc.nil? ? '' : "See #{doc} for more info"
113:
114: fields.each do |field|
115: raise PluginValidationError, "Please specify a valid '#{field}' key in BoxGrinder configuration file: '#{@config.file}' or use CLI '--#{@plugin_info[:type]}-config #{field}:DATA' argument. #{more_info}" if @plugin_config[field].nil?
116: end
117: end
# File lib/boxgrinder-build/plugins/base-plugin.rb, line 111
111: def validate_plugin_config(fields = [], doc = nil)
112: more_info = doc.nil? ? '' : "See #{doc} for more info"
113:
114: fields.each do |field|
115: raise PluginValidationError, "Please specify a valid '#{field}' key in BoxGrinder configuration file: '#{@config.file}' or use CLI '--#{@plugin_info[:type]}-config #{field}:DATA' argument. #{more_info}" if @plugin_config[field].nil?
116: end
117: end