lib/buildr/as3/apparat.rb in buildr-as3-0.1.16 vs lib/buildr/as3/apparat.rb in buildr-as3-0.1.17

- old
+ new

@@ -19,83 +19,134 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # module Buildr module AS3 - module Apparat - class ApparatToolkit - attr_reader :home, :asmifier, :concrete, :coverage, :dump, - :jitb, :reducer, :stripper, :tdsi, :asm_swc, - :ersatz_swc, :lzma_decoder_swc + module Apparat + class ApparatToolkit + attr_reader :home, :asmifier, :concrete, :coverage, :dump, + :jitb, :reducer, :stripper, :tdsi, :asm_swc, + :ersatz_swc, :lzma_decoder_swc, :scala_home - def initialize(apparat_version,apparat_url) + def initialize(version) + @version = version + @spec = "com.googlecode:apparat-bin:zip:#{@version}" + @apparat_zip = Buildr.artifact(@spec) + @apparat_dir = File.join(File.dirname(@apparat_zip.to_s), "apparat-bin-#{@version}", "apparat-#{@version}") + generate_paths @apparat_dir, @version + end - apparat_zip = Buildr::artifact("com.googlecode:apparat-bin:zip:#{apparat_version}").from(Buildr::download(apparat_url)) - apparat_zip.invoke unless File.exists? apparat_zip.to_s - apparat_dir = File.join(File.dirname(apparat_zip.to_s), "apparat-bin-#{apparat_version}") - unless File.exists? apparat_dir - puts "Unzipping Apparat, this may take a while." - Buildr::unzip(apparat_dir=>apparat_zip.to_s).target.invoke - end + def invoke - @home = apparat_dir - bat_ext = Buildr::Util.win_os? ? ".bat" : "" - @apparat = "#{@home}/apparat#{bat_ext}" - @asmifier = "#{@home}/asmifier#{bat_ext}" - @concrete = "#{@home}/concrete#{bat_ext}" - @coverage = "#{@home}/coverage#{bat_ext}" - @dump = "#{@home}/dump#{bat_ext}" - @jitb = "#{@home}/jitb#{bat_ext}" - @reducer = "#{@home}/reducer#{bat_ext}" - @stripper = "#{@home}/stripper#{bat_ext}" - @tdsi = "#{@home}/tdsi#{bat_ext}" - @asm_swc = "#{@home}/apparat-asm-#{apparat_version}.swc" - @ersatz_swc = "#{@home}/apparat-ersatz-#{apparat_version}.swc" - @lzma_decoder_swc = "#{@home}/apparat-lzma-decoder-#{apparat_version}.swc" + if @url + Buildr.artifact(@spec).from(Buildr.download(@url)).invoke unless File.exists? @apparat_zip.to_s + else + Buildr.artifact(@spec).invoke unless File.exists? @apparat_zip.to_s end - end - module Tasks - include Extension - first_time do - Project.local_task('apparat_tdsi') - Project.local_task('apparat_reducer') + unless File.exists? @apparat_dir + puts "Unzipping Apparat, this might take a while." + unzip_dir = File.dirname @apparat_dir + if Buildr::Util.win_os? + puts "Please make sure unzip is installed and in your PATH variable!" + unzip @apparat_zip, unzip_dir + else + begin + Buildr.unzip(unzip_dir.to_s=>@apparat_zip.to_s).target.invoke + rescue TypeError + puts "RubyZip extract failed, trying system unzip now." + unzip @apparat_zip, unzip_dir + end + end end + self + end - before_define do |project| - end + def from(url) + @url = url + self + end - after_define do |project| - end + def scala(scala_home) + @scala_home = scala_home + self + end - def apparat_tdsi(options = {}) - output = Buildr::AS3::Compiler::CompilerUtils::get_output(project,compile.target,compile.packaging,compile.options) - apparat_tk = compile.options[:apparat] - cmd_args = [] - cmd_args << apparat_tk.tdsi - cmd_args << "-i #{output}" - cmd_args << "-o #{output}" - reserved = [] - options.to_hash.reject { |key, value| reserved.include?(key) }. + + protected + + def unzip(zip, destination) + project_dir = Dir.getwd + Dir.chdir File.dirname(zip.to_s) + system("unzip #{File.basename(zip.to_s).to_s} -d #{File.basename(destination).to_s}") + Dir.chdir project_dir + end + + def generate_paths(home_dir, version) + @home = home_dir + bat_ext = Buildr::Util.win_os? ? "" : "" + @apparat = "#{@home}/apparat#{bat_ext}" + @asmifier = "#{@home}/asmifier#{bat_ext}" + @concrete = "#{@home}/concrete#{bat_ext}" + @coverage = "#{@home}/coverage#{bat_ext}" + @dump = "#{@home}/dump#{bat_ext}" + @jitb = "#{@home}/jitb#{bat_ext}" + @reducer = "#{@home}/reducer#{bat_ext}" + @stripper = "#{@home}/stripper#{bat_ext}" + @tdsi = "#{@home}/tdsi#{bat_ext}" + @asm_swc = "#{@home}/apparat-asm-#{version}.swc" + @ersatz_swc = "#{@home}/apparat-ersatz-#{version}.swc" + @lzma_decoder_swc = "#{@home}/apparat-lzma-decoder-#{version}.swc" + self + end + end + + + module Tasks + include Extension + + first_time do + Project.local_task('apparat_tdsi') + Project.local_task('apparat_reducer') + end + + before_define do |project| + end + + after_define do |project| + end + + def apparat_tdsi(options = {}) + output = Buildr::AS3::Compiler::CompilerUtils::get_output(project, compile.target, compile.packaging, compile.options) + apparat_tk = compile.options[:apparat].invoke + cmd_args = [] + cmd_args << "\"#{apparat_tk.tdsi}\"" + cmd_args << "-i #{output}" + cmd_args << "-o #{output}" + reserved = [] + options.to_hash.reject { |key, value| reserved.include?(key) }. each do |key, value| - cmd_args << "-#{key} #{value}" - end - system(cmd_args.join " ") + cmd_args << "-#{key} #{value}" end + ENV["PATH"] = "#{apparat_tk.scala_home}/bin#{File::PATH_SEPARATOR}#{ENV["PATH"]}" if apparat_tk.scala_home && !ENV["PATH"].include?("#{apparat_tk.scala_home}/bin") + puts "path:", ENV["PATH"] + puts "tdsi:",cmd_args.join(" "), system(cmd_args.join " ") + end - def apparat_reducer(quality) - output = Buildr::AS3::Compiler::CompilerUtils::get_output(project,compile.target,compile.packaging,compile.options) - apparat_tk = compile.options[:apparat] - cmd_args = [] - cmd_args << apparat_tk.reducer - cmd_args << "-i #{output}" - cmd_args << "-o #{output}" - cmd_args << "-q" - cmd_args << quality || 100 - system(cmd_args.join " ") - end + def apparat_reducer(quality) + output = Buildr::AS3::Compiler::CompilerUtils::get_output(project, compile.target, compile.packaging, compile.options) + apparat_tk = compile.options[:apparat].invoke + cmd_args = [] + cmd_args << "\"#{apparat_tk.reducer}\"" + cmd_args << "-i #{output}" + cmd_args << "-o #{output}" + cmd_args << "-q" + cmd_args << quality || 100 + ENV["PATH"] = "#{apparat_tk.scala_home}#{File::Separator}bin#{File::PATH_SEPARATOR}#{ENV["PATH"]}" if apparat_tk.scala_home && !ENV["PATH"].include?("#{apparat_tk.scala_home}/bin") + system(cmd_args.join " ") end end + end end class Project include Buildr::AS3::Apparat::Tasks end end