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

source_changes at macosforge.org source_changes at macosforge.org
Sat Aug 30 10:48:14 PDT 2008


Revision: 530
          http://trac.macosforge.org/projects/ruby/changeset/530
Author:   rich at infoether.com
Date:     2008-08-30 10:48:14 -0700 (Sat, 30 Aug 2008)
Log Message:
-----------
add ability to copy files in the resources directory

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-30 17:47:03 UTC (rev 529)
+++ MacRuby/trunk/lib/hotcocoa/application_builder.rb	2008-08-30 17:48:14 UTC (rev 530)
@@ -6,7 +6,7 @@
     
     ApplicationBundlePackage = "APPL????"
     
-    attr_accessor :name, :load_file, :sources, :overwrite, :icon, :version, :info_string, :secure
+    attr_accessor :name, :load_file, :sources, :overwrite, :icon, :version, :info_string, :secure, :resources
     
     def self.build(build_options)
       build_options.each do |key, value|
@@ -16,23 +16,28 @@
         require 'yaml'
         build_options = YAML.load(File.read(build_options[:file]))
       end
-      ab = new
-      ab.secure = (build_options[:secure] == true)
-      ab.name = build_options[:name]
-      ab.load_file = build_options[:load]
-      ab.icon = build_options[:icon] if build_options[:icon] && File.exist?(build_options[:icon])
-      ab.version = build_options[:version] || "1.0"
-      ab.info_string = build_options[:info_string]
-      ab.overwrite = (build_options.include?(:overwrite) ? build_options[:overwrite] : true)
+      builder = new
+      builder.secure = (build_options[:secure] == true)
+      builder.name = build_options[:name]
+      builder.load_file = build_options[:load]
+      builder.icon = build_options[:icon] if build_options[:icon] && File.exist?(build_options[:icon])
+      builder.version = build_options[:version] || "1.0"
+      builder.info_string = build_options[:info_string]
+      builder.overwrite = (build_options.include?(:overwrite) ? build_options[:overwrite] : true)
       sources = build_options[:sources] || []
       sources.each do |source|
-        ab << source
+        builder.add_source_path source
       end
-      ab.build
+      resources = build_options[:resources] || []
+      resources.each do |resource|
+        builder.add_resource_path resource
+      end
+      builder.build
     end
     
     def initialize
       @sources = []
+      @resources = []
     end
       
     def build
@@ -40,6 +45,7 @@
       build_bundle_structure
       write_bundle_files
       copy_sources
+      copy_resources
       copy_icon_file if icon
     end
     
@@ -47,11 +53,17 @@
       @overwrite
     end
     
-    def <<(source_file_pattern)
+    def add_source_path(source_file_pattern)
       Dir.glob(source_file_pattern).each do |source_file|
         sources << source_file
       end
     end
+
+    def add_resource_path(resource_file_pattern)
+      Dir.glob(resource_file_pattern).each do |resource_file|
+        resources << resource_file
+      end
+    end
     
     def secure?
       secure
@@ -103,8 +115,16 @@
         end
       end
       
+      def copy_resources
+        resources.each do |resource|
+          destination = File.join(resources_root, resource.split("/")[1..-1].join("/"))
+          FileUtils.mkdir_p(File.dirname(destination)) unless File.exist?(File.dirname(destination))
+          FileUtils.cp_r resource, destination
+        end
+      end
+      
       def copy_icon_file
-        FileUtils.cp(icon, icon_file)
+        FileUtils.cp(icon, icon_file) unless File.exist?(icon_file)
       end
       
       def write_pkg_info_file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080830/0f0ad476/attachment.html 


More information about the macruby-changes mailing list