lib/appengine-tools/appcfg.rb in appengine-tools-0.0.4 vs lib/appengine-tools/appcfg.rb in appengine-tools-0.0.5

- old
+ new

@@ -25,13 +25,10 @@ if defined? Java AppCfg = AppEngine::SDK.load_appcfg import Java.ComGoogleAppengineToolsAdmin.AppAdminFactory import Java.ComGoogleAppengineToolsAdmin.AppVersionUpload import Java.ComGoogleAppengineToolsUtil.Logging - import java.io.FileOutputStream - import java.util.jar.JarOutputStream - import java.util.zip.ZipEntry class JRubyAppVersionUpload < AppVersionUpload def initialize(connection, app) @connection = connection @app = app @@ -74,149 +71,87 @@ end end end class JRubyAppCfg - NO_XML_COMMANDS = [ 'version' ] - RUBY_COMMANDS = ['bundle', 'gem', 'help', 'run'] + NO_XML_COMMANDS = %w{version} + RUBY_COMMANDS = %w{gem bundle help run} COMMAND_SUMMARY = <<EOF run: run jruby in your application environment. - gem: run rubygems for your application. bundle: package your application for deployment. -The 'gem' and 'run' commands assume the app directory is the current directory. + The 'run' command assumes the app directory is the current directory. EOF class << self def main(args) command, parsed_args = parse_args(args) if RUBY_COMMANDS.include? command send(command, *parsed_args) return end - if command && ! NO_XML_COMMANDS.include?(command) + if command && !NO_XML_COMMANDS.include?(command) path = parsed_args[0] AppEngine::Admin.bundle_app(path) AppEngine::Development.boot_jruby updater = AppEngine::Admin::UpdateCheck.new(path) updater.nag else AppEngine::Development.boot_jruby end - puts "running AppCfg" + puts "=> Running AppCfg" run_appcfg(args) end def run_appcfg(args) factory = AppAdminFactory.new factory.setAppVersionUploadClass(JRubyAppVersionUpload) Logging.initializeLogging AppCfg.new(factory, args.to_java(java.lang.String)) end - def bundle(path) - AppEngine::Admin.bundle_app(path) + def bundle(*args) + if File.directory?(args[-1] || '') + AppEngine::Admin.bundle_app(*args) + else + bundle_help + end end def bundle_help help = <<EOF -#{$0} bundle app_dir +#{$0} bundle [gem bundle options] app_dir -Generates files necessary to run an application as a Java Servlet. -This is run automatically when necessary, so you should not -need to run it manually. +Bundles the gems listed in Gemfile and generates files necessary +to run an application as a servlet. This runs automatically for you, +but you need to run it manually to update gems if you don't specify +a version number. Pass --update to refresh bundled gems. EOF end - + def gem(*args) - AppEngine::Admin.bundle_deps('.') - AppEngine::Development.boot_jruby - puts "=> Running RubyGems" - require 'rubygems' - require 'rubygems/command_manager' - Gem.configuration = Gem::ConfigFile.new(args) - Gem.use_paths('.gems') - Gem::Command.add_specific_extra_args( - 'install', %w(--no-rdoc --no-ri)) - saved_gems = all_gem_specs - begin - Gem::CommandManager.instance.run(Gem.configuration.args) - rescue Gem::SystemExitException => e - exit e.exit_code unless e.exit_code == 0 - end - unless ((all_gem_specs == saved_gems) && - File.exist?('WEB-INF/lib/gems.jar')) - Dir.mkdir 'WEB-INF' unless File.exists? 'WEB-INF' - Dir.mkdir 'WEB-INF/lib' unless File.exists? 'WEB-INF/lib' - Dir.chdir '.gems' - puts '=> Packaging gems' - write_jar('../WEB-INF/lib/gems.jar') do |jar| - add_to_jar('gems', jar) - add_to_jar('specifications', jar) - end - puts 'If you upgraded any gems, please run `appcfg.rb gem cleanup`' - puts 'to remove the old versions.' - end + gem_help end def gem_help help = <<EOF -#{$0} gem [rubygems arguments] +Sorry, the 'appcfg.rb gem' option is deprecated. +Simply update the 'Gemfile' and run 'appcfg.rb bundle .' instead. -Configures rubygems for this application and bundles the gems into a .jar file. -Must be run from the application directory. - EOF + puts help end - def all_gem_specs - Gem.source_index.map do |_, spec| - spec - end - end - - def write_jar(filename) - filename = File.expand_path(filename) - jar = JarOutputStream.new(FileOutputStream.new(filename)) - begin - yield jar - ensure - jar.close - end - end - - def add_to_jar(path, jar) - directory = File.directory?(path) - if directory - path << '/' - end - entry = ZipEntry.new(path) - jar.put_next_entry(entry) - unless directory - data = IO.read(path) - jar.write(data.to_java_bytes, 0, data.size) - end - jar.close_entry - if directory - Dir.entries(path).each do |filename| - unless ['.', '..'].include?(filename) - add_to_jar(path + filename, jar) - end - end - end - end - def run(*args) AppEngine::Admin.bundle_deps('.') AppEngine::Development.boot_app('.', args) end def run_help help = <<EOF #{$0} run [ruby args] - Starts the jruby interpreter within your application's environment. Use `#{$0} run -S command` to run a command such as rake or irb. Must be run from the application directory, after running bundle. EOF @@ -263,6 +198,6 @@ return [command, [path]] end end end end -end \ No newline at end of file +end