=begin Copyright (c) 2007 Pattern Park Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. TODO: Investigate jruby support, especially: http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=compilers_123_09.html =end module Sprout class MXMLCError < StandardError #:nodoc: end class ExecutionError < StandardError #:nodoc: end # The MXMLC task provides a rake front end to the Flex MXMLC command line compiler. # This task is integrated with the LibraryTask so that if any dependencies are # library tasks, they will be automatically added to the library_path or source_path # depending on whether they provide a swc or sources. # # The entire MXMLC advanced interface has been provided here. All parameter names should be # identical to what is available on the regular compiler except dashes have been replaced # by underscores. # # The following example can be pasted in a file named 'rakefile.rb' which should be placed in # the same folder as an ActionScript 3.0 class named 'SomeProject.as' that extends # flash.display.Sprite. # # # Create a remote library dependency on the corelib swc. # library :corelib # # # Alias the compilation task with one that is easier to type # task :compile => 'SomeProject.swf' # # # Create an MXMLCTask named for the output file that it creates. This task depends on the # # corelib library and will automatically add the corelib.swc to it's library_path # mxmlc 'SomeProject.swf' => :corelib do |t| # t.input = 'SomeProject.as' # t.default_size = '800 600' # t.default_background_color = "#FFFFFF" # end # # Note: Be sure to check out the features of the ToolTask to learn more about gem_version and preprocessor # class MXMLCTask < ToolTask # Use a running instance of the FCSH command shell to speed up compilation. # You need to run 'rake fcsh:start' in another terminal before turning on # this flag and compiling. attr_accessor :use_fcsh # Interface and descriptions found here: # http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001481.html def initialize_task @default_gem_name = 'sprout-flex3sdk-tool' @default_gem_path = 'bin/mxmlc' add_param(:accessible, :boolean) do |p| p.hidden_value = true p.description = "Enables accessibility features when compiling the Flex application or SWC file. The default value is false." end add_param(:actionscript_file_encoding, :string) do |p| p.description = "Sets the file encoding for ActionScript files. For more information see: http://livedocs.adobe.com/flex/2/docs/00001503.html#149244" end add_param(:allow_source_path_overlap, :boolean) do |p| p.hidden_value = true p.description = "Checks if a source-path entry is a subdirectory of another source-path entry. It helps make the package names of MXML components unambiguous. This is an advanced option." end # multiline strings won't work in stupid aptana! add_param(:as3, :boolean) do |p| p.value = true p.show_on_false = true p.description =< Specifies a product and a serial number. (repeatable) This is an advanced option. EOF end add_param(:library_path, :files) do |p| p.description =<,
, and  symbols showing linker dependencies in the final SWF file.

The file format output by this command can be used to write a file for input to the load-externs option.

For more information on the report, see Examining linker dependencies (http://livedocs.adobe.com/flex/2/docs/00001394.html#211202).

This is an advanced option.
EOF
      end
      
      add_param(:load_config, :file) do |p|
        p.description =<, 
, and  symbols to omit from linking when compiling a SWF file. The XML file uses the same syntax as the one produced by the link-report option. For more information on the report, see Examining linker dependencies (http://livedocs.adobe.com/flex/2/docs/00001394.html#211202).

This option provides compile-time link checking for external components that are dynamically linked.

For more information about dynamic linking, see About linking (http://livedocs.adobe.com/flex/2/docs/00001521.html#205852).

This is an advanced option.
EOF
      end
      
      add_param(:locale, :string) do |p|
        p.description =< fcsh_error
        raise fcsh_error
      rescue StandardError => std_error
        # TODO: Capture a more concrete error here...
        raise MXMLCError.new("[ERROR] There was a problem connecting to the Flex Compiler SHell, run 'rake fcsh:start' in another terminal.")
      end
    end
    
    def execute(*args)
      begin
        start = Time.now.to_i
        if(@use_fcsh)
          execute_with_fcsh(to_shell)
        else
          super
        end
        Log.puts "mxmlc finished compiling #{name} in #{Time.now.to_i - start} seconds"
      rescue ExecutionError => e
        if(e.message.index('Warning:'))
          # MXMLC sends warnings to stderr....
          Log.puts(e.message.gsub('[ERROR]', '[WARNING]'))
        else
          raise e
        end
      end
    end

  end
end

# Helper method for definining and accessing MXMLCTask instances in a rakefile
def mxmlc(args, &block)
  Sprout::MXMLCTask.define_task(args, &block)
end