module Airake # Project settings for AIR app class Project attr_reader :project_name, :mxmlc_path, :adt_path attr_reader :base_dir, :bin_dir, :src_dir, :lib_dir, :test_dir attr_reader :mxml_path, :appxml_path, :air_path, :swf_path attr_reader :debug def initialize(base_dir, mxml_path, options = {}) @mxmlc_path = "mxmlc" @adt_path = "adt" @base_dir = base_dir @bin_dir = File.join(base_dir, "bin") @src_dir = File.join(base_dir, "src") @lib_dir = File.join(base_dir, "lib") @test_dir = File.join(base_dir, "test") @project_name = File.basename(mxml_path, ".mxml") @mxml_path = mxml_path mxml_dir = File.expand_path(File.dirname(mxml_path)) @appxml_path = options[:appxml_path] || "#{mxml_dir}/#{project_name}-app.xml" # Dest package files @air_path = options[:air_path] || "#{@bin_dir}/#{project_name}.air" @swf_path = options[:swf_path] || "#{@bin_dir}/#{project_name}.swf" @debug = options[:debug] || false end def run_adt run(adt_command) end def run_mxmlc run(mxmlc_command) end def run_adl run(adl_command) end def mxmlc_command "#{@mxmlc_path} +configname=air #{source_path_option} -library-path+=#{@lib_dir} -output #{@swf_path} #{debug_option} -disable-incremental-optimizations=true -- #{@mxml_path}" end def adt_command "#{@adt_path} -package #{relative_path(@air_path)} #{relative_path(@appxml_path)} #{relative_path(@swf_path)}" end def adl_command "adl #{@appxml_path} #{@base_dir}" end # Create project from ENV (for rake tasks) def self.new_from_rake(env, is_test = false) base_dir = env["BASE_DIR"] mxml = is_test ? env["MXML_TEST"] : env["MXML"] options = { :debug => env["DEBUG"] } self.new(base_dir, mxml, options) end protected def lib_source_paths Dir["#{@lib_dir}/*"].collect { |f| f if File.directory?(f) }.compact + [ @test_dir, @src_dir ] end def source_path_option @source_paths ||= lib_source_paths @source_paths.empty? ? "" : "-source-path #{@source_paths.join(" ")}" end def debug_option "-debug=#{@debug}" if @debug end def relative_path(path) Pathname.new(path).relative_path_from(Pathname.new(@base_dir)) end def fail(cmd, error_status) fail_message = <<-EOS The '#{cmd.split.first}' command failed to run. This could be because this executable isn't in the path. To include mxmlc, adl and adt (from Flex Builder): export PATH="/Applications/Adobe Flex Builder 3/sdks/moxie/bin:$PATH" To include adl and adt (from Apollo SDK): export PATH="/Applications/ApolloSDK/bin:$PATH" EOS puts fail_message raise "[#{error_status}] Failed to run command: #{cmd}" end def run(cmd) puts "Running: #{cmd}" system cmd or fail(cmd, $?) end end end