Title: [570] trunk/rails-integration/plugins/goldspike-snapshot/lib: Assemble web application in place rather than using tmp/war.
Revision
570
Author
tantalon
Date
2007-05-10 18:28:32 -0400 (Thu, 10 May 2007)

Log Message

Assemble web application in place rather than using tmp/war.
The result of this is that the excludes list is not as fine grained (e.g. we cannot include the log directory without the files inside it).

Changed File.install to File.copy due to popular demand :)

Modified Paths

Diff

Modified: trunk/rails-integration/plugins/goldspike-snapshot/lib/create_war.rb (569 => 570)


--- trunk/rails-integration/plugins/goldspike-snapshot/lib/create_war.rb	2007-05-10 18:39:18 UTC (rev 569)
+++ trunk/rails-integration/plugins/goldspike-snapshot/lib/create_war.rb	2007-05-10 22:28:32 UTC (rev 570)
@@ -38,7 +38,6 @@
 
     def clean_war
       FileUtils.remove_file(@config.war_file) if File.exists?(@config.war_file)
-      FileUtils.remove_dir(@config.staging) if File.exists?(@config.staging)
     end
 
     def create_war_file
@@ -49,7 +48,6 @@
     def assemble
       puts 'Assembling web application'
       add_java_libraries
-      add_webapp
       if config.standalone
         add_ruby_libraries
       end
@@ -63,10 +61,6 @@
       @webapp_packer.create_war
     end
 
-    def add_webapp
-      @webapp_packer.add_webapp
-    end
-
     def add_java_libraries
       @java_lib_packer.add_java_libraries
     end

Modified: trunk/rails-integration/plugins/goldspike-snapshot/lib/packer.rb (569 => 570)


--- trunk/rails-integration/plugins/goldspike-snapshot/lib/packer.rb	2007-05-10 18:39:18 UTC (rev 569)
+++ trunk/rails-integration/plugins/goldspike-snapshot/lib/packer.rb	2007-05-10 22:28:32 UTC (rev 570)
@@ -2,55 +2,59 @@
 module War
   
   class Packer
-	
-	  attr_accessor :config
-	
-	  def initialize(config = Configuration.instance)
-	    @config = config
-	  end
-	  
+  
+    attr_accessor :config
+  
+    def initialize(config = Configuration.instance)
+      @config = config
+    end
+    
     def install(source, dest, mode=0644)
-      File.install(source, dest, mode)
+      # File.install is disabled because of a performance problem under JRuby,
+      # without it the task may fail if the original gem files were not writable by the owner
+      #File.install(source, dest, mode)
+      File.copy(source, dest)
     end
-	  
-	  def copy_tree(files, target, strip_prefix='')
-	    files.each do |f|
-	      relative = f[strip_prefix.length, f.length]
-	      target_file = File.join(target, relative)
-	      if File.directory?(f)
-	        File.makedirs(target_file)
-	      elsif File.file?(f)
-	        # puts "  Copying #{f} to #{relative}"
-	        File.makedirs(File.dirname(target_file))
-	        install(f, target_file)
-	      end
-	    end    
-	  end
-	  
-	  def compile_tree(dir, config)
-	    return unless config.compile_ruby
-	    # find the libraries
-	    classpath_files = Rake::FileList.new(File.join(config.staging, 'WEB-INF', 'lib', '*.jar'))
-	    classpath_files_array = classpath_files.to_a
-	    classpath_files_array.collect! {|f| File.expand_path(f) }
-	    classpath = classpath_files_array.join(config.os_path_separator)
-	    # compile the files
-	    os_dir = dir.gsub(File::SEPARATOR, config.os_separator)
-	    unless system("cd #{os_dir} && java -cp #{classpath} org.jruby.webapp.ASTSerializerMain #{'--replace' unless config.keep_source}")
-	      raise "Error: failed to preparse files in #{dir}, returned with error code #{$?}"    
-	    end
-	  end
-	  
-	  def jar(target_file, source_dir, compress=true)
-	    os_target_file = target_file.gsub(File::SEPARATOR, config.os_separator)
-	    os_source_dir = source_dir.gsub(File::SEPARATOR, config.os_separator)
-	    flags = '-cf'
-	    flags += '0' unless compress
-	    unless system("jar #{flags} #{os_target_file} -C #{os_source_dir} .")
-	      raise "Error: failed to create archive, error code #{$?}"
-	    end
-	  end
-	  
+    
+    def copy_tree(files, target, strip_prefix='')
+      files.each do |f|
+        relative = f[strip_prefix.length, f.length]
+        target_file = File.join(target, relative)
+        if File.directory?(f)
+          File.makedirs(target_file)
+        elsif File.file?(f)
+          # puts "  Copying #{f} to #{relative}"
+          File.makedirs(File.dirname(target_file))
+          install(f, target_file)
+        end
+      end    
+    end
+    
+    def compile_tree(dir, config)
+      return unless config.compile_ruby
+      # find the libraries
+      classpath_files = Rake::FileList.new(File.join(config.staging, 'WEB-INF', 'lib', '*.jar'))
+      classpath_files_array = classpath_files.to_a
+      classpath_files_array.collect! {|f| File.expand_path(f) }
+      classpath = classpath_files_array.join(config.os_path_separator)
+      # compile the files
+      os_dir = dir.gsub(File::SEPARATOR, config.os_separator)
+      unless system("cd #{os_dir} && java -cp #{classpath} org.jruby.webapp.ASTSerializerMain")
+        raise "Error: failed to preparse files in #{dir}, returned with error code #{$?}"    
+      end
+    end
+    
+    def jar(target_file, source_dir, files, compress=true)
+      os_target_file = target_file.gsub(File::SEPARATOR, config.os_separator)
+      os_source_dir = source_dir.gsub(File::SEPARATOR, config.os_separator)
+      flags = '-cf'
+      flags += '0' unless compress
+      files_list = files.join(' ')
+      unless system("jar #{flags} #{os_target_file} -C #{os_source_dir} #{files_list}")
+        raise "Error: failed to create archive, error code #{$?}"
+      end
+    end
+    
   end
   
   class JavaLibPacker < Packer
@@ -96,17 +100,9 @@
       raise "The #{name} gem is not installed" if matched.empty?
       gem = matched.last
 
-      gem_target = File.join(target_gem_home, 'gems', gem.full_gem_path.split('/').last)
+      gem_target = File.join(target_gem_home, 'gems', gem.full_gem_path.split('/').last)
 
       unless File.exists?(gem_target)
-        #####################
-        ## package up the gem
-        #puts "  Adding Ruby gem #{gem.name} version #{gem.version}"
-        ## copy the cache file
-        #gem_source = File.join(Gem.path, 'cache', "#{gem.name}-#{gem.version}.gem")
-        #install(gem_source, target_gem_home, 0644)
-        #####################
-
         # package up the gem
         puts "  Adding Ruby gem #{gem.name} version #{gem.version}"
         # copy the specification
@@ -117,8 +113,8 @@
         copy_tree(gem_files, gem_target, gem.full_gem_path)
         # compile the .rb files to .rb.ast.ser
         compile_tree(File.join(gem_target, 'lib'), config)
-
       end
+      
       # handle dependencies
       if config.add_gem_dependencies
         for gem_child in gem.dependencies
@@ -137,7 +133,18 @@
     end
     
     def create_war
-      jar(config.war_file, config.staging)
+      # we can't include a directory, but exclude it's files
+      webapp_files = Rake::FileList.new
+      webapp_files.include('*')
+      webapp_files.exclude('*.war')
+      webapp_files.exclude(/tmp$/)
+      webapp_files.include(File.join('tmp', '*'))
+      webapp_files.exclude(File.join('tmp', 'jetty'))
+      config.excludes.each do |exclude|
+        webapp_files.exclude(exclude)
+      end
+
+      jar(config.war_file, config.staging, webapp_files)
     end
     
     def add_webapp

Modified: trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb (569 => 570)


--- trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb	2007-05-10 18:39:18 UTC (rev 569)
+++ trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb	2007-05-10 22:28:32 UTC (rev 570)
@@ -55,7 +55,7 @@
 
     def initialize
       # default internal locations
-      @staging = File.join('tmp', 'war')
+      @staging = RAILS_ROOT
       @excludes = []
       @local_java_lib = File.join('lib', 'java')
 
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to