require 'tmpdir' require 'zip/zip' require_relative '../feature/base' require_relative '../feature/common/merge_file' require_relative '../feature/common/merge_dir' module IronWorkerNG module Code class Base attr_reader :features attr_accessor :base_dir attr_accessor :dest_dir @@registered_types = [] def self.registered_types @@registered_types end def self.register_type(type) @@registered_types << type end @@registered_features = [] def self.registered_features @@registered_features end def self.register_feature(feature) return if feature[:for_klass].to_s == 'IronWorkerNG::Code::Builder' @@registered_features << feature end include IronWorkerNG::Code::Initializer::InstanceMethods include IronWorkerNG::Feature::Common::MergeFile::InstanceMethods include IronWorkerNG::Feature::Common::MergeDir::InstanceMethods def initialize(*args, &block) @features = [] @base_dir = '' @dest_dir = '' initialize_code(*args, &block) end def name(name = nil) @name = name if name @name end def name=(name) @name = name end def remote_build_command(remote_build_command = nil) @remote_build_command = remote_build_command if remote_build_command @remote_build_command end def remote_build_command=(remote_build_command) @remote_build_command = remote_build_command end def runtime(*args) end def runtime=(runtime) end def fixate IronWorkerNG::Code::Base.registered_features.each do |rf| if (rf[:for_klass] == self.class || self.class == IronWorkerNG::Code::Builder) && respond_to?(rf[:name] + '_fixate') send(rf[:name] + '_fixate') end end end def hash_string fixate Digest::MD5.hexdigest(@features.map { |f| f.hash_string }.join) end def bundle(zip) @features.each do |feature| feature.bundle(zip) end unless self.class == IronWorkerNG::Code::Base zip.get_output_stream(@dest_dir + '__runner__.sh') do |runner| runner.write <