lib/appengine-tools/bundler.rb in appengine-tools-0.0.11 vs lib/appengine-tools/bundler.rb in appengine-tools-0.0.12
- old
+ new
@@ -26,11 +26,11 @@
module AppEngine
module Admin
class Application
attr_reader :root
-
+
def initialize(root)
@root = root
end
def path(*pieces)
@@ -96,28 +96,24 @@
def rack_app
AppEngine::Rack.app
end
end
-
+
class AppBundler
EXISTING_JRUBY = /^(jruby-abridged|appengine-jruby)-.*jar$/
EXISTING_APIS = /^appengine-api.*jar$/
- RACKUP = %q{Dir.chdir('..') if Dir.pwd =~ /WEB-INF$/; } +
- %q{begin; require 'bundler_gems/environment'; } +
- %q{rescue LoadError; end;} +
- %q{eval IO.read('config.ru'), nil, 'config.ru', 1}
def initialize(root_path)
@app = Application.new(root_path)
end
-
+
def bundle(args=[])
bundle_deps(args)
convert_config_ru
end
-
+
def bundle_deps(args=[])
confirm_appdir
create_webinf
bundle_gems(args)
copy_jruby
@@ -127,15 +123,15 @@
def bundle_gems(args)
return if defined? JRUBY_VERSION
gem_bundler = AppEngine::Admin::GemBundler.new(app.root)
gem_bundler.bundle(args)
end
-
+
def app
@app
end
-
+
def confirm_appdir
unless File.exists?(app.config_ru) or
File.exists?(app.gemfile) or File.exists?(app.webinf)
puts ""
puts "Oops, this does not look like an application directory."
@@ -150,53 +146,53 @@
def create_webinf
Dir.mkdir(app.webinf) unless File.exists?(app.webinf)
Dir.mkdir(app.webinf_lib) unless File.exists?(app.webinf_lib)
Dir.mkdir(app.generation_dir) unless File.exists?(app.generation_dir)
end
-
+
def create_public
return unless defined? JRUBY_VERSION
if app.public_root and !File.exists?(app.public_root)
- Dir.mkdir(app.public_root)
+ Dir.mkdir(app.public_root)
end
FileUtils.touch(app.favicon_ico) unless File.exists?(app.favicon_ico)
FileUtils.touch(app.robots_txt) unless File.exists?(app.robots_txt)
end
-
+
def convert_config_ru
unless File.exists?(app.config_ru)
puts "=> Generating rackup"
app_id = File.basename(File.expand_path(app.path)).
downcase.gsub('_', '-').gsub(/[^-a-z0-9]/, '')
stock_rackup = <<EOF
require 'appengine-rack'
-AppEngine::Rack.configure_app(
- :application => "#{app_id}",
+AppEngine::Rack.configure_app(
+ :application => "#{app_id}",
:precompilation_enabled => true,
:version => "1")
-run lambda { Rack::Response.new("Hello").finish }
+run lambda { ::Rack::Response.new("Hello").finish }
EOF
File.open(app.config_ru, 'w') {|f| f.write(stock_rackup) }
end
generate_xml
create_public
end
-
+
def copy_jruby
require 'appengine-jruby-jars'
update_jars("JRuby", EXISTING_JRUBY, [AppEngine::JRubyJars.jruby_jar])
end
-
+
def copy_sdk
require 'appengine-sdk'
glob = "appengine-api-{1.0-sdk,labs}-*.jar"
jars = Dir.glob("#{AppEngine::SDK::SDK_ROOT}/lib/user/#{glob}")
update_jars('appengine-sdk', EXISTING_APIS, jars)
end
-
+
private
-
+
def find_jars(regex)
Dir.entries(app.webinf_lib).grep(regex) rescue []
end
def update_jars(name, regex, jars, opt_regex=nil, opt_jars=[])
@@ -238,11 +234,11 @@
return false unless File.exists? app.web_xml
return false unless File.exists? app.aeweb_xml
yaml = YAML.load_file app.build_status
return false unless yaml.is_a? Hash
return false unless File.stat(app.config_ru).mtime.eql? yaml[:config_ru]
- return false unless File.stat(app.web_xml).mtime.eql? yaml[:web_xml]
+ return false unless File.stat(app.web_xml).mtime.eql? yaml[:web_xml]
return false unless File.stat(app.aeweb_xml).mtime.eql? yaml[:aeweb_xml]
true
end
def generate_xml
@@ -260,11 +256,11 @@
TARGET_ENGINE, TARGET_VERSION, "environment")
eval IO.read('config.ru'), nil, 'config.ru', 1
end
# Now configure the basic jruby-rack settings.
- add_jruby_rack_defaults(RACKUP)
+ add_jruby_rack_defaults
end
open(app.web_xml, 'w') do |webxml|
xml = AppEngine::Rack::XmlFormatter.format(builder.to_xml)
webxml.write(xml)
end
@@ -282,14 +278,14 @@
:args => ['bundle', app.root],
:exec => false)
end
end
end
-
+
def self.bundle_app(*args)
AppBundler.new(args.pop).bundle(args)
end
-
+
def self.bundle_deps(*args)
AppBundler.new(args.pop).bundle(args)
end
end