airake 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,35 +18,36 @@ module Airake #:nodoc:
18
18
  def initialize(options = {})
19
19
  @path = options[:acompc_path] || "acompc"
20
20
  @extra_opts = options[:acompc_extra_opts]
21
- with_options(options, { :source_path => "src" })
22
-
23
- raise "No output path specified" unless output_path
21
+ with_options(options, { :source_path => "src" })
22
+ assert_required([ :path, :source_path, :output_path, :include_packages ])
23
+ @include_classes = include_classes
24
24
  end
25
25
 
26
- def include_classes_option
26
+ # Find classes list from packages, raises error if result is empty
27
+ def include_classes
27
28
  classes = []
28
29
  paths = []
29
- include_packages.each do |include_package|
30
- path = File.join(source_path, include_package.gsub(".", "/")) + "/**/*.as"
30
+ @include_packages.each do |include_package|
31
+ path = File.join(@source_path, include_package.gsub(".", "/")) + "/**/*.as"
31
32
  paths << path
32
33
  Dir[path].each do |file|
33
34
  classes << include_package + "." + File.basename(file).gsub(".as", "")
34
35
  end
35
36
  end
36
37
  raise "No classes found at:\n\t#{paths.join("\n\t")}" if classes.empty?
37
- classes.join(" ")
38
+ classes
38
39
  end
39
40
 
40
41
  # Get the acompc compile command
41
42
  def compile
42
43
  command = []
43
- command << path
44
+ command << @path
44
45
  command << "-source-path"
45
- command << source_path
46
+ command << @source_path
46
47
  command << "-include-classes"
47
- command << include_classes_option
48
+ command << @include_classes.join(" ")
48
49
  command << "-output"
49
- command << output_path
50
+ command << @output_path
50
51
  process(command)
51
52
  end
52
53
 
@@ -9,20 +9,21 @@ module Airake #:nodoc:
9
9
 
10
10
  attr_reader :project, :path, :extra_opts, :appxml_path, :root_dir
11
11
 
12
- # options:: :adl_path, adl_extra_opts, :appxml_path, :root_dir
12
+ # options:: :adl_path, :adl_extra_opts, :appxml_path, :root_dir
13
13
  def initialize(options = {})
14
14
  @path = options[:adl_path] || "adl"
15
15
  @extra_opts = options[:adl_extra_opts]
16
16
  with_options(options)
17
+ assert_required([ :path, :appxml_path, :root_dir ])
17
18
  end
18
19
 
19
20
  # Get the ADL launch command
20
21
  def launch
21
22
  command = []
22
- command << path
23
- command << extra_opts
24
- command << escape(appxml_path)
25
- command << escape(root_dir)
23
+ command << @path
24
+ command << @extra_opts
25
+ command << escape(@appxml_path)
26
+ command << escape(@root_dir)
26
27
  process(command)
27
28
  end
28
29
 
@@ -14,21 +14,20 @@ module Airake #:nodoc:
14
14
  @path = options[:adt_path] || "adt"
15
15
  @extra_opts = options[:adt_extra_opts]
16
16
  with_options(options)
17
+ assert_required([ :path, :base_dir, :air_path, :appxml_path, :swf_path ])
17
18
  end
18
19
 
19
20
  # Get the ADT package command
20
21
  def package
21
- raise ArgumentError, "Must specify :base_dir" unless base_dir
22
-
23
22
  command = []
24
- command << path
25
- command << extra_opts
23
+ command << @path
24
+ command << @extra_opts
26
25
  command << "-package"
27
- command << "-certificate #{certificate}" unless certificate.blank?
28
- command << escape(relative_path(air_path, base_dir))
29
- command << escape(relative_path(appxml_path, base_dir))
30
- command << escape(relative_path(swf_path, base_dir))
31
- command << assets
26
+ command << "-certificate #{certificate}" unless @certificate.blank?
27
+ command << escape(relative_path(@air_path, @base_dir))
28
+ command << escape(relative_path(@appxml_path, @base_dir))
29
+ command << escape(relative_path(@swf_path, @base_dir))
30
+ command << @assets unless @assets.nil?
32
31
  process(command)
33
32
  end
34
33
 
@@ -7,47 +7,55 @@ module Airake #:nodoc:
7
7
  # http://livedocs.adobe.com/labs/air/1/devappsflex/help.html?content=CommandLineTools_2.html#1032546
8
8
  class Amxmlc < Base
9
9
 
10
- attr_reader :path, :extra_opts, :swf_path, :mxml_path, :lib_dir, :src_dir, :test_dir, :debug_option
10
+ attr_reader :path, :extra_opts, :swf_path, :mxml_path, :lib_dir, :src_dirs, :debug
11
11
 
12
- # options:: :amxmlc_path, :amxmlc_extra_opts, :swf_path, :mxml_path, :lib_dir, :src_dir, :test_dir, :debug_option
12
+ # options:: :amxmlc_path, :amxmlc_extra_opts, :swf_path, :mxml_path, :lib_dir, :src_dirs, :debug
13
13
  def initialize(options = {})
14
14
  @path = options[:amxmlc_path] || "mxmlc +configname=air"
15
15
  @extra_opts = options[:amxmlc_extra_opts]
16
- with_options(options)
16
+ with_options(options)
17
+ assert_required([ :path, :swf_path, :mxml_path ])
18
+ @source_paths = source_paths
19
+ raise ArgumentError, "There aren't any valid source directories to compile" if @source_paths.empty?
20
+ @library_path = library_path
17
21
  end
18
22
 
19
23
  # Get the amxmlc compile command
20
24
  def compile
21
25
  command = []
22
- command << path
23
- command << source_path_option
24
- command << library_path_option
26
+ command << @path
27
+ command << "-source-path #{@source_paths.join(" ")}"
28
+ command << "-library-path+=#{@library_path}"
25
29
  command << "-output"
26
- command << escape(swf_path)
27
- command << debug_option
28
- command << extra_opts
30
+ command << escape(@swf_path)
31
+ command << "-debug=#{@debug}" unless @debug.nil?
32
+ command << @extra_opts
29
33
  #command << "-disable-incremental-optimizations=true"
30
34
  command << "--"
31
- command << escape(mxml_path)
35
+ command << escape(@mxml_path)
32
36
  process(command)
33
37
  end
34
38
 
35
39
  protected
36
40
 
37
- def source_path_option
41
+ def source_paths
42
+ source_paths = []
38
43
  # List of directories in lib/ for source_path +=
39
- lib_source_paths = Dir["#{lib_dir}/*"].collect { |f| escape(f) if File.directory?(f) }.compact
40
- lib_source_paths << escape(test_dir) if test_dir and File.directory?(test_dir)
41
- lib_source_paths << escape(src_dir) if src_dir and File.directory?(src_dir)
42
-
43
- source_paths ||= lib_source_paths
44
- source_paths.empty? ? "" : "-source-path #{source_paths.join(" ")}"
44
+ if @lib_dir and File.directory?(@lib_dir)
45
+ Dir["#{@lib_dir}/*"].collect { |f| escape(f) if File.directory?(f) }.compact
46
+ end
47
+
48
+ @src_dirs.each do |src_dir|
49
+ if File.directory?(src_dir)
50
+ source_paths << escape(src_dir)
51
+ else
52
+ raise "Source directory: #{src_dir} is not a directory or does not exist"
53
+ end
54
+ end
45
55
  end
46
56
 
47
- def library_path_option
48
- library_paths = []
49
- library_paths << escape(lib_dir) if lib_dir and File.directory?(lib_dir)
50
- library_paths.empty? ? "" : "-library-path+=#{library_paths.join(" ")}"
57
+ def library_path
58
+ escape(@lib_dir) if @lib_dir and File.directory?(@lib_dir)
51
59
  end
52
60
 
53
61
  end
@@ -24,7 +24,8 @@ module Airake #:nodoc:
24
24
 
25
25
  def with_options(options, defaults = {})
26
26
  options.each do |key, value|
27
- instance_variable_set("@#{key}", value)
27
+ raise "Invalid option: '#{key}' for command: #{self.class}" unless respond_to?(key.to_sym)
28
+ instance_variable_set("@#{key}", value)
28
29
  end
29
30
 
30
31
  defaults.each do |key, value|
@@ -33,6 +34,12 @@ module Airake #:nodoc:
33
34
  end
34
35
  end
35
36
 
37
+ def assert_required(vars)
38
+ vars.each do |var|
39
+ raise ArgumentError, "Must specify option: #{var}" if instance_variable_get("@#{var}").nil?
40
+ end
41
+ end
42
+
36
43
  end
37
44
 
38
45
  end
@@ -5,9 +5,8 @@ module Airake #:nodoc
5
5
 
6
6
  attr_reader :base_dir, :bin_dir, :src_dir, :lib_dir, :test_dir
7
7
  attr_reader :mxml_path, :appxml_path, :air_path, :swf_path
8
- attr_reader :debug
9
- attr_reader :options
10
- attr_reader :assets
8
+ attr_reader :debug, :assets, :certificate
9
+ attr_reader :build_env
11
10
 
12
11
  # Options to override defaults
13
12
  Options = [ :certificate, :assets, :amxmlc_path, :adt_path, :adt_path, :bin_dir, :src_dir, :lib_dir, :test_dir,
@@ -18,7 +17,7 @@ module Airake #:nodoc
18
17
  # base_dir:: Base (project) directory
19
18
  # mxml_path: Path to the project.mxml (relative)
20
19
  # options:: Override default paths, commands, extra opts, etc; See Options class var
21
- def initialize(base_dir, mxml_path, options = {})
20
+ def initialize(base_dir, mxml_path, options = {}, build_env = :normal)
22
21
  raise ArgumentError, "Invalid MXML path: #{mxml_path}" if mxml_path.blank?
23
22
 
24
23
  mxml_dir = File.expand_path(File.dirname(mxml_path))
@@ -26,7 +25,7 @@ module Airake #:nodoc
26
25
 
27
26
  @base_dir = base_dir
28
27
  @mxml_path = File.join(mxml_dir, "#{project_name}.mxml")
29
- @options = options
28
+ @build_env = build_env
30
29
 
31
30
  @bin_dir = options[:bin_dir] || File.join(base_dir, "bin")
32
31
  @src_dir = options[:src_dir] || File.join(base_dir, "src")
@@ -40,51 +39,72 @@ module Airake #:nodoc
40
39
  @swf_path = options[:swf_path] || File.join(@bin_dir, "#{project_name}.swf")
41
40
 
42
41
  # Debug options
43
- @debug = options[:debug].is_a?(TrueClass) || options[:debug] == "true"
42
+ @debug = options[:debug].is_a?(TrueClass) || options[:debug] == "true"
43
+
44
+ @assets = options[:assets]
45
+ @certificate = options[:certificate]
44
46
  end
45
47
 
46
48
  # Flex compiler command for this project
47
49
  def amxmlc
48
- options = @options.merge({ :swf_path => swf_path, :mxml_path => mxml_path, :lib_dir => lib_dir,
49
- :src_dir => src_dir, :test_dir => test_dir, :debug_option => debug_option })
50
+ src_dirs = case build_env
51
+ when :normal then [ @src_dir ]
52
+ when :test then [ @src_dir, @test_dir ]
53
+ else raise "Invalid build_env setting: #{build_env}"
54
+ end
55
+
56
+ options = { :swf_path => @swf_path, :mxml_path => @mxml_path, :lib_dir => @lib_dir,
57
+ :src_dirs => src_dirs, :debug => @debug }
58
+
50
59
  Airake::Commands::Amxmlc.new(options)
51
60
  end
52
61
 
53
62
  # ADL command for this project
54
63
  def adl
55
- options = @options.merge({ :appxml_path => appxml_path, :root_dir => base_dir })
64
+ options = { :appxml_path => @appxml_path, :root_dir => @base_dir }
56
65
  Airake::Commands::Adl.new(options)
57
66
  end
58
67
 
59
68
  # ADT command for this project
60
69
  def adt
61
- options = @options.merge({ :air_path => air_path, :appxml_path => appxml_path, :swf_path => swf_path, :base_dir => base_dir })
70
+ options = { :air_path => @air_path, :appxml_path => @appxml_path, :swf_path => @swf_path,
71
+ :base_dir => @base_dir, :assets => @assets, :certificate => @certificate }
62
72
  Airake::Commands::Adt.new(options)
63
73
  end
74
+
75
+ # List of files to remove on clean
76
+ def to_clean
77
+ case build_env
78
+ when :normal then [ swf_path, air_path ]
79
+ when :test then [ swf_path ]
80
+ end
81
+ end
64
82
 
65
83
  # Create project using parameters from rake ENV
84
+ #
85
+ # This shouldn't really be here, but a Rakefile is a bad place to be :O
66
86
  #
67
87
  # You can set any of the options via ENV; just upcase it. <tt>:foo_bar => ENV["FOO_BAR"]</tt>
68
88
  #
69
89
  # Booleans must be "true" for true
70
- def self.new_from_rake(env, is_test = false)
90
+ def self.new_from_rake(env, build_env = :normal)
71
91
  base_dir = env["BASE_DIR"]
72
- mxml = is_test ? env["MXML_TEST"] : env["MXML"]
92
+ mxml = case build_env
93
+ when :test then env["MXML_TEST"]
94
+ when :normal then env["MXML"]
95
+ else raise "Invalid build env: #{build_env}"
96
+ end
73
97
 
74
98
  # For any option check to see if its in the ENV
75
99
  options = {}
76
100
  Options.each do |option_key|
77
- env_key = option_key.to_s.upcase
101
+ env_key = option_key.to_s.upcase
78
102
  options[option_key] = env[env_key] if env.has_key?(env_key)
79
103
  end
80
104
  #puts "Using options: #{options.inspect}" unless options.empty?
81
- self.new(base_dir, mxml, options)
105
+ self.new(base_dir, mxml, options, build_env)
82
106
  end
83
107
 
84
- def debug_option
85
- "-debug=#{@debug}" if @debug
86
- end
87
-
88
108
  end
89
109
 
90
110
  end
@@ -7,23 +7,25 @@ module Airake #:nodoc:
7
7
  attr_reader :output, :cmd, :took, :process
8
8
 
9
9
  def initialize(cmd)
10
- @cmd = RUBY_PLATFORM =~ /win32/ ? "cmd.exe /c #{cmd}" : cmd
10
+ @cmd = RUBY_PLATFORM =~ /win32/ ? "cmd.exe /c #{cmd}" : "#{cmd} 2>&1"
11
11
  end
12
12
 
13
13
  def run(verbose = true)
14
- puts "Running: #{cmd}" if verbose
14
+ puts "Running: #{@cmd}" if verbose
15
15
 
16
16
  t1 = Time.now
17
- IO.popen(@cmd) do |f|
18
- @output = f.read
19
- @process = Process.waitpid2(f.pid)[1]
17
+ IO.popen(@cmd) do |f|
18
+ while s = f.read(1)
19
+ printf s
20
+ STDOUT.flush
21
+ end
20
22
  end
23
+ @process = $?
21
24
  @took = Time.now - t1
22
25
 
23
26
  if verbose
24
- puts output
25
27
  success? or fail
26
- puts "Took %.2fs" % [ took ]
28
+ #puts "Took %.2fs" % [ @took ]
27
29
  end
28
30
  end
29
31
 
@@ -15,7 +15,7 @@ namespace :air do
15
15
  desc "Test"
16
16
  task :test => :clean do
17
17
  ENV["DEBUG"] = "true" unless ENV.has_key?("DEBUG")
18
- test_project = Airake::Project.new_from_rake(ENV, true)
18
+ test_project = Airake::Project.new_from_rake(ENV, :test)
19
19
  Airake::Runner.run(test_project.amxmlc, :compile)
20
20
  Airake::Runner.run(test_project.adl, :launch)
21
21
  end
@@ -135,11 +135,11 @@ namespace :air do
135
135
  desc "Clean"
136
136
  task :clean do
137
137
  project = Airake::Project.new_from_rake(ENV)
138
- paths = [ project.swf_path, project.air_path ]
138
+ paths = project.to_clean
139
139
 
140
140
  # Test
141
- test_project = Airake::Project.new_from_rake(ENV, true)
142
- paths += [ test_project.swf_path ]
141
+ test_project = Airake::Project.new_from_rake(ENV, :test)
142
+ paths += project.to_clean
143
143
 
144
144
  paths.each do |path|
145
145
  FileUtils.rm(path, :verbose => true) if File.exist?(path)
@@ -2,7 +2,7 @@ module Airake #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 8
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: airake
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.8
7
- date: 2007-11-07 00:00:00 -05:00
6
+ version: 0.2.9
7
+ date: 2007-11-09 00:00:00 -05:00
8
8
  summary: Tasks and generators for Adobe AIR apps
9
9
  require_paths:
10
10
  - lib