Title: [516] trunk/rails-integration/plugins/war-snapshot: Partial application of changes from Jon Tirsen's new_war_rb.patch:
Revision
516
Author
tantalon
Date
2007-04-28 00:02:21 -0400 (Sat, 28 Apr 2007)

Log Message

Partial application of changes from Jon Tirsen's new_war_rb.patch:
+ Use RAILS_ROOT
+ Only use require when the tasks are executed (stops them failing to show on minor errors)
+ Move Jetty port and opts into config
+ Make configuration singleton
+ Display jetty command line

Modified Paths

Diff

Modified: trunk/rails-integration/plugins/war-snapshot/lib/create_war.rb (515 => 516)


--- trunk/rails-integration/plugins/war-snapshot/lib/create_war.rb	2007-04-27 10:13:10 UTC (rev 515)
+++ trunk/rails-integration/plugins/war-snapshot/lib/create_war.rb	2007-04-28 04:02:21 UTC (rev 516)
@@ -15,8 +15,8 @@
 
     attr_accessor :config
 
-    def initialize
-      @config = Configuration.new
+    def initialize(config = Configuration.instance)
+      @config = config
       @java_lib_packer = JavaLibPacker.new(@config)
       @ruby_lib_packer = RubyLibPacker.new(@config)
       @webapp_packer = WebappPacker.new(@config)

Modified: trunk/rails-integration/plugins/war-snapshot/lib/packer.rb (515 => 516)


--- trunk/rails-integration/plugins/war-snapshot/lib/packer.rb	2007-04-27 10:13:10 UTC (rev 515)
+++ trunk/rails-integration/plugins/war-snapshot/lib/packer.rb	2007-04-28 04:02:21 UTC (rev 516)
@@ -5,7 +5,7 @@
 	
 	  attr_accessor :config
 	
-	  def initialize(config)
+	  def initialize(config = Configuration.instance)
 	    @config = config
 	  end
 	  

Modified: trunk/rails-integration/plugins/war-snapshot/lib/run.rb (515 => 516)


--- trunk/rails-integration/plugins/war-snapshot/lib/run.rb	2007-04-27 10:13:10 UTC (rev 515)
+++ trunk/rails-integration/plugins/war-snapshot/lib/run.rb	2007-04-28 04:02:21 UTC (rev 516)
@@ -6,19 +6,15 @@
     
     attr_accessor :config
     attr_accessor :jetty_main
-    attr_accessor :jetty_port
     attr_accessor :jetty_tmp
     attr_accessor :jetty_config
     attr_accessor :classpath
-    attr_accessor :java_opts
     
-    def initialize
-      @config = Configuration.new
+    def initialize(config = Configuration.instance)
+      @config = config
       @jetty_main = 'org.mortbay.start.Main'
-      @jetty_port = 8080
       @jetty_tmp = File.join('tmp', 'jetty')
       @jetty_config = File.join(jetty_tmp, 'jetty.xml')
-      @java_opts = ''
     end
     
     def run_standalone
@@ -30,15 +26,14 @@
       add_jetty_libraries
       add_jetty_config
       classpath_string = classpath.join(config.os_path_separator)
-      java_opts = self.java_opts
+      java_opts = config.jetty_java_opts.dup
       java_opts << ' -Xmx128m' unless java_opts =~ /-Xmx/
-      system("java #{java_opts} -cp \"#{classpath_string}\" #{jetty_main} #{jetty_config}")
+      java_opts << " -Djetty.port=#{config.jetty_port}" unless java_opts =~ /jetty.port/
+      cmd = "java #{java_opts} -cp \"#{classpath_string}\" #{jetty_main} #{jetty_config}"
+      puts cmd
+      system(cmd)
     end
     
-    def java_opts
-      ENV['JAVA_OPTS'] || @java_opts
-    end
-    
     def add_jetty_libraries
       # Get the Jetty libraries
       @classpath = []

Modified: trunk/rails-integration/plugins/war-snapshot/lib/war_config.rb (515 => 516)


--- trunk/rails-integration/plugins/war-snapshot/lib/war_config.rb	2007-04-27 10:13:10 UTC (rev 515)
+++ trunk/rails-integration/plugins/war-snapshot/lib/war_config.rb	2007-04-28 04:02:21 UTC (rev 516)
@@ -5,6 +5,7 @@
 #
 module War
   class Configuration
+    include Singleton
 
     # the name of the project
     attr_accessor :name
@@ -48,11 +49,12 @@
     # the real separator for the operating system
     attr_accessor :os_separator
     attr_accessor :os_path_separator
+    
+    attr_accessor :jetty_port
+    attr_accessor :jetty_java_opts
 
     def initialize
-
       # default internal locations
-      @rails_basedir = File.dirname(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))))
       @staging = File.join('tmp', 'war')
       @excludes = []
       @local_java_lib = File.join('lib', 'java')
@@ -72,7 +74,7 @@
       @maven_remote_repository = 'http://www.ibiblio.org/maven2'
 
       # configured war name, defaults to the same as the ruby webapp
-      @name = File.basename(@rails_basedir)
+      @name = File.basename(RAILS_ROOT)
       @war_file = "[EMAIL PROTECTED]"
 
       @java_libraries = {}
@@ -99,6 +101,10 @@
       add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-plus', '6.1.1'))
       add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-naming', '6.1.1'))
       
+      # default jetty settings
+      @jetty_port = 8080
+      @jetty_java_opts = ENV['JAVA_OPTS'] || ''
+      
       # separators
       if RUBY_PLATFORM =~ /(mswin)|(cygwin)/i # watch out for darwin
         @os_separator = '\\'
@@ -113,7 +119,6 @@
 
       # load user configuration
       load_user_configuration
-
     end # initialize
     
     def exclude_files(pattern)
@@ -133,16 +138,11 @@
       version ? "= #{version}" : nil
     end
 
-    #def is_conf(name)
-    #   return true if @config_db and @config_db[name]
-    #end
-
     def load_user_configuration
-      user_config = File.join(@rails_basedir, 'config', 'war.rb')
+      user_config = File.join(RAILS_ROOT, 'config', 'war.rb')
       if File.exists?(user_config)
         begin
-          puts "Reading user configuration"
-          @config_db = War::Configuration::DSL.evaluate(user_config, self).result
+          War::Configuration::DSL.evaluate(user_config, self)
         rescue => e
           puts e.backtrace.join("\n")
           puts "Error reading user configuration (#{e.message}), using defaults"
@@ -175,6 +175,10 @@
       @gem_libraries[name] = match_version
     end
 
+    def remove_gem(name)
+      @gem_libraries.delete(name)
+    end
+
     def local_locations(artifact, version, type='jar')
       paths = []
       if local_java_lib

Modified: trunk/rails-integration/plugins/war-snapshot/tasks/war.rake (515 => 516)


--- trunk/rails-integration/plugins/war-snapshot/tasks/war.rake	2007-04-27 10:13:10 UTC (rev 515)
+++ trunk/rails-integration/plugins/war-snapshot/tasks/war.rake	2007-04-28 04:02:21 UTC (rev 516)
@@ -2,14 +2,6 @@
 # Rake tasks for building a war file
 #
 
-# add the lib to the load path
-plugin_dir = File.dirname(File.dirname(File.expand_path(__FILE__)))
-$LOAD_PATH <<  File.join(plugin_dir, 'lib')
-
-# load the library
-require 'create_war'
-require 'run'
-
 # aliases for the tasks
 task 'create_war' => ['war:standalone:create']
 task 'create_war:standalone' => ['war:standalone:create']
@@ -19,36 +11,38 @@
 task 'war:shared' => ['war:shared:create']
 task 'tmp:war:clean' => ['tmp:war:clear']
 
-# create a standalone package
+task 'war:init' => [:environment] do
+  # load the library
+  require 'create_war'
+  require 'run'
+end
+
 desc 'Create a self-contained Java war'
-task 'war:standalone:create' do
+task 'war:standalone:create' => ['war:init'] do
   creator = War::Creator.new
   creator.standalone = true
   creator.create_war_file
 end
 
-# assemble the files for a standalone package
-task 'war:standalone:assemble' do
+desc "Assemble the files for a standalone package"
+task 'war:standalone:assemble' => ['war:init'] do
   creator = War::Creator.new
   creator.standalone = true
   creator.assemble
 end
 
-# create a shared package
 desc 'Create a war for use on a Java server where JRuby is available'
-task 'war:shared:create' do
+task 'war:shared:create' => ['war:init'] do
   creator = War::Creator.new
   creator.standalone = false
   creator.create_war_file
 end
 
-# clean up
 desc "Clears all files used in the creation of a war"
-task 'tmp:war:clear' do
+task 'tmp:war:clear' => ['war:init'] do
   War::Creator.new.clean_war
 end
 
-# run the war file with jetty
 desc "Run the webapp in Jetty"
 task 'war:standalone:run' => ['war:standalone:assemble'] do
   War::Runner.new.run_standalone
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to