Class BoxGrinder::BasePlugin
In: lib/boxgrinder-build/plugins/base-plugin.rb
lib/boxgrinder-build/plugins/base-plugin.rb
Parent: Object

Methods

Public Class methods

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 31
31:     def initialize
32:       @plugin_config = {}
33: 
34:       @deliverables = OpenCascade.new
35:       @supported_oses = OpenCascade.new
36:       @target_deliverables = OpenCascade.new
37:       @dir = OpenCascade.new
38:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 31
31:     def initialize
32:       @plugin_config = {}
33: 
34:       @deliverables = OpenCascade.new
35:       @supported_oses = OpenCascade.new
36:       @target_deliverables = OpenCascade.new
37:       @dir = OpenCascade.new
38:     end

Public Instance methods

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 146
146:     def after_execute
147:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 146
146:     def after_execute
147:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 143
143:     def after_init
144:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 143
143:     def after_init
144:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 100
100:     def current_platform
101:       platform = :raw
102: 
103:       if @previous_plugin_info[:type] == :platform
104:         platform = @previous_plugin_info[:name]
105:       end unless @previous_plugin_info.nil?
106: 
107:       platform.to_s
108:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 100
100:     def current_platform
101:       platform = :raw
102: 
103:       if @previous_plugin_info[:type] == :platform
104:         platform = @previous_plugin_info[:name]
105:       end unless @previous_plugin_info.nil?
106: 
107:       platform.to_s
108:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 164
164:     def deliverables
165:       @target_deliverables
166:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 164
164:     def deliverables
165:       @target_deliverables
166:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 149
149:     def deliverables_exists?
150:       raise "You can only check deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
151: 
152:       exists = true
153: 
154:       @target_deliverables.each_value do |file|
155:         unless File.exists?(file)
156:           exists = false
157:           break
158:         end
159:       end
160: 
161:       exists
162:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 149
149:     def deliverables_exists?
150:       raise "You can only check deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
151: 
152:       exists = true
153: 
154:       @target_deliverables.each_value do |file|
155:         unless File.exists?(file)
156:           exists = false
157:           break
158:         end
159:       end
160: 
161:       exists
162:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 118
118:     def execute(args = nil)
119:       raise "You can only execute the plugin after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
120:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 118
118:     def execute(args = nil)
119:       raise "You can only execute the plugin after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
120:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 40
40:     def init(config, appliance_config, options = {})
41:       @config = config
42:       @appliance_config = appliance_config
43:       @options = options
44:       @log = options[:log] || Logger.new(STDOUT)
45:       @exec_helper = options[:exec_helper] || ExecHelper.new(:log => @log)
46:       @image_helper = options[:image_helper] || ImageHelper.new(@config, @appliance_config, :log => @log)
47:       @previous_plugin_info = options[:previous_plugin_info]
48:       @previous_deliverables = options[:previous_deliverables] || OpenCascade.new
49: 
50:       @plugin_info = options[:plugin_info]
51: 
52:       @dir.base = "#{@appliance_config.path.build}/#{@plugin_info[:name]}-plugin"
53:       @dir.tmp = "#{@dir.base}/tmp"
54: 
55:       read_plugin_config
56:       merge_plugin_config
57: 
58:       @move_deliverables = true
59:       @initialized = true
60: 
61:       after_init
62: 
63:       self
64:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 40
40:     def init(config, appliance_config, options = {})
41:       @config = config
42:       @appliance_config = appliance_config
43:       @options = options
44:       @log = options[:log] || Logger.new(STDOUT)
45:       @exec_helper = options[:exec_helper] || ExecHelper.new(:log => @log)
46:       @image_helper = options[:image_helper] || ImageHelper.new(@config, @appliance_config, :log => @log)
47:       @previous_plugin_info = options[:previous_plugin_info]
48:       @previous_deliverables = options[:previous_deliverables] || OpenCascade.new
49: 
50:       @plugin_info = options[:plugin_info]
51: 
52:       @dir.base = "#{@appliance_config.path.build}/#{@plugin_info[:name]}-plugin"
53:       @dir.tmp = "#{@dir.base}/tmp"
54: 
55:       read_plugin_config
56:       merge_plugin_config
57: 
58:       @move_deliverables = true
59:       @initialized = true
60: 
61:       after_init
62: 
63:       self
64:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 83
83:     def is_supported_os?
84:       return true if @supported_oses.empty?
85:       return false unless !@supported_oses[@appliance_config.os.name].nil? and @supported_oses[@appliance_config.os.name].include?(@appliance_config.os.version)
86:       true
87:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 83
83:     def is_supported_os?
84:       return true if @supported_oses.empty?
85:       return false unless !@supported_oses[@appliance_config.os.name].nil? and @supported_oses[@appliance_config.os.name].include?(@appliance_config.os.version)
86:       true
87:     end

This merges the plugin config with configuration provided in command line

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 179
179:     def merge_plugin_config
180:       config =
181:           case @plugin_info[:type]
182:             when :os
183:               @config.os_config
184:             when :platform
185:               @config.platform_config
186:             when :delivery
187:               @config.delivery_config
188:           end
189: 
190:       @plugin_config.merge!(config)
191:     end

This merges the plugin config with configuration provided in command line

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 179
179:     def merge_plugin_config
180:       config =
181:           case @plugin_info[:type]
182:             when :os
183:               @config.os_config
184:             when :platform
185:               @config.platform_config
186:             when :delivery
187:               @config.delivery_config
188:           end
189: 
190:       @plugin_config.merge!(config)
191:     end

This reads the plugin config from file

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 173
173:     def read_plugin_config
174:       return if @config[:plugins].nil? or @config[:plugins][@plugin_info[:name].to_s].nil?
175:       @plugin_config = @config[:plugins][@plugin_info[:name].to_s]
176:     end

This reads the plugin config from file

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 173
173:     def read_plugin_config
174:       return if @config[:plugins].nil? or @config[:plugins][@plugin_info[:name].to_s].nil?
175:       @plugin_config = @config[:plugins][@plugin_info[:name].to_s]
176:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 66
66:     def register_deliverable(deliverable)
67:       raise "You can only register deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
68:       raise "Please specify deliverables as Hash, not #{deliverable.class}." unless deliverable.is_a?(Hash)
69: 
70:       deliverable.each do |name, path|
71:         @deliverables[name] = "#{@dir.tmp}/#{path}"
72:         @target_deliverables[name] = "#{@dir.base}/#{path}"
73:       end
74:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 66
66:     def register_deliverable(deliverable)
67:       raise "You can only register deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
68:       raise "Please specify deliverables as Hash, not #{deliverable.class}." unless deliverable.is_a?(Hash)
69: 
70:       deliverable.each do |name, path|
71:         @deliverables[name] = "#{@dir.tmp}/#{path}"
72:         @target_deliverables[name] = "#{@dir.base}/#{path}"
73:       end
74:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 76
76:     def register_supported_os(name, versions)
77:       raise "You can register supported operating system only after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
78: 
79:       @supported_oses[name] = OpenCascade.new if @supported_oses[name].nil?
80:       @supported_oses[name] = versions
81:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 76
76:     def register_supported_os(name, versions)
77:       raise "You can register supported operating system only after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
78: 
79:       @supported_oses[name] = OpenCascade.new if @supported_oses[name].nil?
80:       @supported_oses[name] = versions
81:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 122
122:     def run(*args)
123:       unless is_supported_os?
124:         @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."
125:         return
126:       end
127: 
128:       FileUtils.rm_rf @dir.tmp
129:       FileUtils.mkdir_p @dir.tmp
130: 
131:       execute(*args)
132: 
133:       # TODO execute post commands for platform plugins here?
134: 
135:       @deliverables.each do |name, path|
136:         @log.trace "Moving '#{path}' deliverable to target destination '#{@target_deliverables[name]}'..."
137:         FileUtils.mv(path, @target_deliverables[name])
138:       end if @move_deliverables
139: 
140:       FileUtils.rm_rf @dir.tmp
141:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 122
122:     def run(*args)
123:       unless is_supported_os?
124:         @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."
125:         return
126:       end
127: 
128:       FileUtils.rm_rf @dir.tmp
129:       FileUtils.mkdir_p @dir.tmp
130: 
131:       execute(*args)
132: 
133:       # TODO execute post commands for platform plugins here?
134: 
135:       @deliverables.each do |name, path|
136:         @log.trace "Moving '#{path}' deliverable to target destination '#{@target_deliverables[name]}'..."
137:         FileUtils.mv(path, @target_deliverables[name])
138:       end if @move_deliverables
139: 
140:       FileUtils.rm_rf @dir.tmp
141:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 168
168:     def set_default_config_value(key, value)
169:       @plugin_config[key] = @plugin_config[key].nil? ? value : @plugin_config[key]
170:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 168
168:     def set_default_config_value(key, value)
169:       @plugin_config[key] = @plugin_config[key].nil? ? value : @plugin_config[key]
170:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 89
89:     def supported_oses
90:       supported = ""
91: 
92:       @supported_oses.sort.each do |name, versions|
93:         supported << ", " unless supported.empty?
94:         supported << "#{name} (versions: #{versions.join(", ")})"
95:       end
96: 
97:       supported
98:     end

[Source]

    # File lib/boxgrinder-build/plugins/base-plugin.rb, line 89
89:     def supported_oses
90:       supported = ""
91: 
92:       @supported_oses.sort.each do |name, versions|
93:         supported << ", " unless supported.empty?
94:         supported << "#{name} (versions: #{versions.join(", ")})"
95:       end
96: 
97:       supported
98:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 110
110:     def validate_plugin_config(fields = [], doc = nil)
111:       more_info = doc.nil? ? '' : "See #{doc} for more info"
112: 
113:       fields.each do |field|
114:         raise "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?
115:       end
116:     end

[Source]

     # File lib/boxgrinder-build/plugins/base-plugin.rb, line 110
110:     def validate_plugin_config(fields = [], doc = nil)
111:       more_info = doc.nil? ? '' : "See #{doc} for more info"
112: 
113:       fields.each do |field|
114:         raise "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?
115:       end
116:     end

[Validate]