Permalink
Browse files

include a runnable task (executable wihout the web server)

this allows to make a war for running packagted binaries such as `rake db:migrate` while not embedding a web server
  • Loading branch information...
1 parent 507dd11 commit d990414a55ded3877cd8999fed703254bb1b3ede @kares kares committed Dec 28, 2012
Showing with 42 additions and 9 deletions.
  1. +2 −1 lib/warbler.rb
  2. +4 −1 lib/warbler/application.rb
  3. +3 −0 lib/warbler/config.rb
  4. +5 −2 lib/warbler/traits/jar.rb
  5. +13 −4 lib/warbler/traits/war.rb
  6. +15 −1 spec/warbler/jar_spec.rb
View
@@ -9,7 +9,8 @@
# your Ruby applications into .jar or .war files.
module Warbler
WARBLER_HOME = File.expand_path(File.dirname(__FILE__) + '/..') unless defined?(WARBLER_HOME)
-
+ WARBLER_JAR = "#{WARBLER_HOME}/lib/warbler_jar.jar" unless defined?(WARBLER_JAR)
+
class << self
# An instance of Warbler::Application used by the +warble+ command.
attr_accessor :application
@@ -37,9 +37,12 @@ def load_rakefile
desc "Feature: package gem repository inside a jar"
task :gemjar => "#{wt.name}:gemjar"
- desc "Feature: make an executable archive"
+ desc "Feature: make an executable archive (runnable + an embedded web server)"
task :executable => "#{wt.name}:executable"
+ desc "Feature: make a runnable archive (e.g. java -jar rails.war -S rake db:migrate)"
+ task :runnable => "#{wt.name}:runnable"
+
desc "Feature: precompile all Ruby files"
task :compiled => "#{wt.name}:compiled"
@@ -200,6 +200,9 @@ def define_tasks
task "executable" do
self.features << "executable"
end
+ task "runnable" do
+ self.features << "runnable"
+ end
end
# Deprecated
@@ -33,8 +33,11 @@ def after_configure
end
def update_archive(jar)
- jar.files['META-INF/MANIFEST.MF'] = StringIO.new(Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: JarMain\n") unless config.manifest_file
- jar.files['JarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", "JarMain.class")
+ unless config.manifest_file
+ manifest = Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: JarMain\n"
+ jar.files['META-INF/MANIFEST.MF'] = StringIO.new(manifest)
+ end
+ jar.files['JarMain.class'] = jar.entry_in_jar(WARBLER_JAR, "JarMain.class")
end
def default_pathmaps
@@ -77,6 +77,7 @@ def update_archive(jar)
add_public_files(jar)
add_webxml(jar)
move_jars_to_webinf_lib(jar)
+ add_runnables(jar) if config.features.include?("runnable")
add_executables(jar) if config.features.include?("executable")
add_gemjar(jar) if config.features.include?("gemjar")
end
@@ -99,13 +100,21 @@ def add_webxml(jar)
end
end
+ def add_runnables(jar, main_class = 'WarMain')
+ main_class = main_class.sub('.class', '') # handles WarMain.class
+ unless config.manifest_file
+ manifest = Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: #{main_class}\n"
+ jar.files['META-INF/MANIFEST.MF'] = StringIO.new(manifest)
+ end
+ [ 'JarMain', 'WarMain', main_class ].uniq.each do |klass|
+ jar.files["#{klass}.class"] = jar.entry_in_jar(WARBLER_JAR, "#{klass}.class")
+ end
+ end
+
def add_executables(jar)
webserver = WEB_SERVERS[config.webserver.to_s]
webserver.add(jar)
- jar.files['META-INF/MANIFEST.MF'] = StringIO.new(Warbler::Jar::DEFAULT_MANIFEST.chomp + "Main-Class: WarMain\n")
- # TODO this will currently only work with "default" WarMain.class but not the jetty one :
- jar.files['JarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", "JarMain.class")
- jar.files['WarMain.class'] = jar.entry_in_jar("#{WARBLER_HOME}/lib/warbler_jar.jar", webserver.main_class)
+ add_runnables jar, webserver.main_class || 'WarMain'
end
def add_gemjar(jar)
@@ -475,16 +475,30 @@ class << t; public :instance_variable_get; end
context "with the executable feature" do
use_test_webserver
- it "adds a WarMain class" do
+ it "adds WarMain (and JarMain) class" do
use_config do |config|
config.webserver = "test"
config.features << "executable"
end
jar.apply(config)
file_list(%r{^WarMain\.class$}).should_not be_empty
+ file_list(%r{^JarMain\.class$}).should_not be_empty
end
end
+ context "with the runnable feature" do
+
+ it "adds WarMain (and JarMain) class" do
+ use_config do |config|
+ config.features << "runnable"
+ end
+ jar.apply(config)
+ file_list(%r{^WarMain\.class$}).should_not be_empty
+ file_list(%r{^JarMain\.class$}).should_not be_empty
+ end
+
+ end
+
context "in a Rails application" do
before :each do
@rails = nil

0 comments on commit d990414

Please sign in to comment.