[macruby-changes] [420] MacRuby/trunk/lib/hotcocoa/application_builder.rb

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 11 10:37:44 PDT 2008


Revision: 420
          http://trac.macosforge.org/projects/ruby/changeset/420
Author:   rich at infoether.com
Date:     2008-08-11 10:37:44 -0700 (Mon, 11 Aug 2008)
Log Message:
-----------
add copying of load file to sources, change require to load, enable :force to remove and rebuild app

Modified Paths:
--------------
    MacRuby/trunk/lib/hotcocoa/application_builder.rb

Modified: MacRuby/trunk/lib/hotcocoa/application_builder.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/application_builder.rb	2008-08-11 17:36:29 UTC (rev 419)
+++ MacRuby/trunk/lib/hotcocoa/application_builder.rb	2008-08-11 17:37:44 UTC (rev 420)
@@ -1,3 +1,5 @@
+require 'fileutils'
+
 module HotCocoa
   
   class ApplicationBuilder
@@ -4,7 +6,7 @@
     
     ApplicationBundlePackage = "APPL????"
     
-    attr_accessor :name, :require_file, :sources
+    attr_accessor :name, :load_file, :sources, :force
     
     def self.build(build_options)
       if build_options[:file]
@@ -13,8 +15,10 @@
       end
       ab = new
       ab.name = build_options[:name]
-      ab.require_file = build_options[:require]
-      build_options[:sources].each do |source|
+      ab.load_file = build_options[:load]
+      ab.force = (build_options.include?(:force) ? build_options[:force] : false)
+      sources = build_options[:sources] || []
+      sources.each do |source|
         ab << source
       end
       ab.build
@@ -25,17 +29,32 @@
     end
       
     def build
+      check_for_bundle_root
       build_bundle_structure
       write_bundle_files
       copy_sources
     end
     
+    def force?
+      @force
+    end
+    
     def <<(source_file)
       sources << source_file
     end
     
     private
     
+      def check_for_bundle_root
+        if File.exist?(bundle_root)
+          if force?
+            puts `rm -rf #{bundle_root}`
+          else
+            puts "Error, #{bundle_root} already exists, use :force => true to remove"
+          end
+        end
+      end
+    
       def build_bundle_structure
         Dir.mkdir(bundle_root)
         Dir.mkdir(contents_root)
@@ -51,8 +70,10 @@
       end
       
       def copy_sources
-        require 'fileutils'
-        FileUtils.cp_r sources, resources_root
+        FileUtils.cp_r load_file, resources_root unless sources.include?(load_file)
+        sources.each do |source|
+          FileUtils.cp_r source, resources_root
+        end
       end
       
       def write_pkg_info_file
@@ -108,7 +129,7 @@
         File.open(main_ruby_source_file, "wb") do |f|
           f.puts %{
             $:.unshift NSBundle.mainBundle.resourcePath.fileSystemRepresentation
-            require '#{require_file}'
+            load '#{load_file}'
           }
         end
       end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080811/13760d4a/attachment.html 


More information about the macruby-changes mailing list