lib/appengine-tools/bundler.rb in appengine-tools-0.0.14 vs lib/appengine-tools/bundler.rb in appengine-tools-0.0.15.pre
- old
+ new
@@ -16,12 +16,10 @@
# limitations under the License.
require 'appengine-rack'
require 'appengine-tools/boot'
require 'appengine-tools/gem_bundler'
-require 'appengine-tools/web-xml'
-require 'appengine-tools/xml-formatter'
require 'fileutils'
require 'yaml'
module AppEngine
module Admin
@@ -63,42 +61,35 @@
def config_ru
path('config.ru')
end
- def web_xml
- path('WEB-INF', 'web.xml')
+ def app_yaml
+ path('app.yaml')
end
- def aeweb_xml
- path('WEB-INF', 'appengine-web.xml')
- end
-
- def build_status
- path('WEB-INF', 'appengine-generated', 'build_status.yaml')
- end
-
def bundled_jars
path('WEB-INF', 'appengine-generated', 'bundled_jars.yaml')
end
def public_root
- path(AppEngine::Rack.app.public_root) if AppEngine::Rack.app.public_root
+ @public_root ||= begin
+ if File.exist?(app_yaml)
+ app = YAML.load(IO.read(app_yaml))
+ return path(app['public_root']) if app['public_root']
+ end
+ path('public')
+ end
end
def favicon_ico
File.join(public_root ? public_root : @root, 'favicon.ico')
end
def robots_txt
File.join(public_root ? public_root : @root, 'robots.txt')
end
-
- def rack_app
- AppEngine::Rack.app
- end
-
end
class AppBundler
EXISTING_APIS = /^appengine-api.*jar$/
@@ -106,35 +97,35 @@
@app = Application.new(root_path)
end
def bundle(args=[])
bundle_deps(args)
- convert_config_ru
+ generate_config_ru
+ generate_app_yaml
+ create_public
end
def bundle_deps(args=[])
confirm_appdir
create_webinf
bundle_gems(args)
end
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)
+ unless File.exists?(app.app_yaml)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 "You need to create #{app.app_yaml}."
puts ""
puts "Run 'appcfg.rb generate_app #{app.path}'"
puts "to generate a skeleton application."
exit 1
end
@@ -145,35 +136,37 @@
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)
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
+ def generate_config_ru
unless File.exists?(app.config_ru)
puts "=> Generating rackup"
+ stock_rackup = "run lambda {Rack::Response.new('Hello').finish}\n"
+ File.open(app.config_ru, 'w') {|f| f.write(stock_rackup) }
+ end
+ end
+
+ def generate_app_yaml
+ unless File.exists?(app.app_yaml)
+ puts "=> Generating app.yaml"
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 }
+ stock_yaml = <<EOF
+application: #{app_id}
+version: 1
+runtime: jruby
EOF
- File.open(app.config_ru, 'w') {|f| f.write(stock_rackup) }
+ File.open(app.app_yaml, 'w') {|f| f.write(stock_yaml)}
end
- generate_xml
- create_public
end
private
def find_jars(regex)
@@ -210,60 +203,9 @@
def remove_jars(jars)
paths = jars.map do |jar|
"#{app.webinf_lib}/#{jar}"
end
FileUtils.rm_f(paths)
- end
-
- def valid_build
- return false unless File.exists? app.build_status
- 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.aeweb_xml).mtime.eql? yaml[:aeweb_xml]
- true
- end
-
- def generate_xml
- return if valid_build
- if defined? JRUBY_VERSION
- puts "=> Generating configuration files"
- Dir.glob("#{app.webinf_lib}/*.jar").each do |path|
- $: << path
- end
- app_root = app.root
- builder = WebXmlBuilder.new do
- # First read the user's rackup file
- Dir.chdir(app_root) do
- 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
- end
- open(app.web_xml, 'w') do |webxml|
- xml = AppEngine::Rack::XmlFormatter.format(builder.to_xml)
- webxml.write(xml)
- end
- open(app.aeweb_xml, 'w') do |aeweb|
- xml = AppEngine::Rack::XmlFormatter.format(app.rack_app.to_xml)
- aeweb.write(xml)
- end
- yaml = {
- :config_ru => File.stat(app.config_ru).mtime,
- :aeweb_xml => File.stat(app.aeweb_xml).mtime,
- :web_xml => File.stat(app.web_xml).mtime }
- open(app.build_status, 'w') { |f| YAML.dump(yaml, f) }
- else
- AppEngine::Development.boot_jruby(app.root,
- :args => ['bundle', app.root],
- :exec => false)
- end
end
end
def self.bundle_app(*args)
AppBundler.new(args.pop).bundle(args)