lib/appengine-tools/appcfg.rb in appengine-tools-0.0.2 vs lib/appengine-tools/appcfg.rb in appengine-tools-0.0.3

- old
+ new

@@ -15,19 +15,23 @@ # limitations under the License. require 'appengine-sdk' require 'appengine-tools/boot' require 'appengine-tools/bundler' +require 'appengine-tools/update_check' require 'yaml' module AppEngine module Admin 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 @@ -86,16 +90,20 @@ if RUBY_COMMANDS.include? command send(command, *parsed_args) return end if command && ! NO_XML_COMMANDS.include?(command) - AppEngine::Admin.bundle_app(parsed_args[0]) + 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 - if !RUBY_COMMANDS.include?(command) - puts "running AppCfg" - run_appcfg(args) - end + puts "running AppCfg" + run_appcfg(args) end def run_appcfg(args) factory = AppAdminFactory.new factory.setAppVersionUploadClass(JRubyAppVersionUpload) @@ -117,31 +125,37 @@ 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 Dir.glob('.gems/specifications/*.gemspec').empty? + 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' - command = %w(jar cf ../WEB-INF/lib/gems.jar gems specifications) - if !system(*command) - puts 'Error running jar command.' - exit $? + 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 end def gem_help help = <<EOF @@ -152,10 +166,48 @@ Must be run from the application directory. EOF 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 \ No newline at end of file