require 'fileutils' require_relative 'container/base' require_relative 'container/zip' require_relative 'container/dir' require_relative '../feature/base' require_relative '../feature/common/merge_exec' require_relative '../feature/common/merge_file' require_relative '../feature/common/merge_dir' require_relative '../feature/common/merge_deb' module IronWorkerNG module Code class Base attr_accessor :features attr_accessor :fixators attr_accessor :base_dir attr_accessor :dest_dir undef exec undef gem include IronWorkerNG::Feature::Common::MergeFile::InstanceMethods include IronWorkerNG::Feature::Common::MergeDir::InstanceMethods include IronWorkerNG::Feature::Common::MergeDeb::InstanceMethods def initialize(*args, &block) @features = [] @fixators = [] @base_dir = '' @dest_dir = '' @full_remote_build = false @runtime = nil @name = nil @exec = nil worker_files = [] if args.length == 1 && args[0].is_a?(String) if args[0].end_with?('.worker') @name = args[0].gsub(/\.worker$/, '') else @name = args[0] end elsif args.length == 1 && args[0].is_a?(Hash) @name = args[0][:name] || args[0]['name'] worker_file = args[0][:workerfile] || args[0]['workerfile'] worker_files << worker_file unless worker_file.nil? exec = args[0][:exec] || args[0]['exec'] || args[0][:worker] || args[0]['worker'] unless exec.nil? merge_exec(exec) end end if @name.nil? and (not @exec.nil?) @name = guess_name_for_path(@exec.path) end unless @name.nil? worker_files << @name + '.worker' end worker_files.each do |worker_file| IronWorkerNG::Fetcher.fetch(worker_file) do |content| unless content.nil? IronCore::Logger.info 'IronWorkerNG', "Found workerfile with path='#{worker_file}'" eval(content) @base_dir = File.dirname(worker_file) == '.' ? '' : File.dirname(worker_file) + '/' break end end end unless block.nil? instance_eval(&block) end if @name.nil? and (not @exec.nil?) @name = guess_name_for_path(@exec.path) end unless @name.nil? @name = File.basename(@name) end end def method_missing(name, *args, &block) if @runtime.nil? runtime(:ruby) send(name, *args, &block) else super(name, *args, &block) end end def guess_name_for_path(path) File.basename(path).gsub(/#{File.extname(path)}$/, '') 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 unless remote_build_command.nil? @remote_build_command end def remote_build_command=(remote_build_command) @remote_build_command = remote_build_command end alias :build :remote_build_command alias :build= :remote_build_command= def full_remote_build(full_remote_build = nil) @full_remote_build = full_remote_build unless full_remote_build.nil? @full_remote_build end def full_remote_build=(full_remote_build) @full_remote_build = full_remote_build end def runtime(runtime = nil) return @runtime unless runtime unless @runtime.nil? IronCore::Logger.error 'IronWorkerNG', "Runtime is already set to '#{@runtime}'", IronCore::Error end runtime_module = nil runtime = runtime.to_s begin runtime_module = IronWorkerNG::Code::Runtime.const_get(runtime.capitalize) rescue begin runtime_module = IronWorkerNG::Code::Runtime.const_get(runtime.upcase) rescue end end if runtime_module.nil? IronCore::Logger.error 'IronWorkerNG', "Can't find runtime '#{runtime}'" end self.extend(runtime_module) @runtime = runtime end def runtime=(runtime) runtime(runtime) end def fixate @fixators.each do |f| send(f) end end def runtime_bundle(container, local = false) end def runtime_run_code(local = false) '' end def bundle(container, local = false) @features.each do |feature| feature.bundle(container) end if local || ((not remote_build_command) && (not full_remote_build)) container.get_output_stream(@dest_dir + '__runner__.sh') do |runner| runner.write <