lib/appengine-tools/bundler.rb in appengine-tools-0.0.7 vs lib/appengine-tools/bundler.rb in appengine-tools-0.0.8.pre
- old
+ new
@@ -95,14 +95,12 @@
end
class AppBundler
EXISTING_JRUBY = /^(jruby-abridged|appengine-jruby)-.*jar$/
- EXISTING_RACK = /jruby-rack.*jar$/
+ EXISTING_RACK = /^jruby-rack.*jar$/
EXISTING_APIS = /^appengine-api.*jar$/
- JRUBY_RACK = 'jruby-rack-0.9.5.jar'
- JRUBY_RACK_URL = "http://kenai.com/downloads/jruby-rack/#{JRUBY_RACK}"
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}
@@ -114,10 +112,11 @@
bundle_deps(args)
convert_config_ru
end
def bundle_deps(args=[])
+ confirm_appdir
create_webinf
bundle_gems(args)
copy_jruby
copy_rack
copy_sdk
@@ -131,10 +130,23 @@
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."
+ puts "You need a #{app.gemfile} or #{app.config_ru} file."
+ puts ""
+ puts "Run 'appcfg.rb generate #{app.path}'"
+ puts "to generate a skeleton application."
+ exit 1
+ end
+ end
+
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
@@ -147,47 +159,37 @@
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
- if !File.exists?(app.config_ru)
- if File.exists?(app.web_xml)
- unless File.exists?(app.aeweb_xml)
- puts "Error: you either need a #{app.config_ru} or "
- puts " #{app.aeweb_xml}."
- exit 1
- end
- else
- # TODO auto generate a config.ru
- puts "Error: you need to create #{app.config_ru}."
- exit 1
- end
- else
- generate_xml
- create_public
+ 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}",
+ :precompilation_enabled => true,
+ :version => "1")
+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_rack
- update_jars('jruby-rack', EXISTING_RACK, [JRUBY_RACK]) do
- require 'open-uri'
- begin
- open(JRUBY_RACK_URL) do |src|
- open(File.join(app.webinf_lib, JRUBY_RACK), 'wb') do |dest|
- dest.write(src.read)
- end
- end
- rescue SocketError
- puts "Unable to download jruby-rack."
- puts "Please check your internet connection."
- end
- end
+ require 'jruby-rack-jar'
+ update_jars('JRuby-Rack', EXISTING_RACK,
+ [AppEngine::JRubyJars.jrubyrack_jar])
end
def copy_sdk
require 'appengine-sdk'
glob = "appengine-api-{1.0-sdk,labs}-*.jar"
@@ -255,13 +257,13 @@
$: << path
end
app_root = app.root
builder = WebXmlBuilder.new do
# First read the user's rackup file
- # TODO generate a skeleton if it's missing
Dir.chdir(app_root) do
- require '.gems/bundler_gems/environment'
+ require File.join(".gems", "bundler_gems",
+ 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)
@@ -284,10 +286,10 @@
: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)