#! /usr/bin/ruby # Copyright:: Copyright 2009 Google Inc. # Original Author:: Ryan Brown (mailto:ribrdb@google.com) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # 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 super(connection, app) end def getIndexYaml indexes = merge_indexes if indexes return indexes.to_yaml end nil end def getCronYaml cron = File.join(app.path, 'cron.yaml') if File.exists?(cron) return cron.to_yaml end nil end def merge_indexes if @app.indexes_xml indexes = YAML.load(@app.indexes_xml.to_yaml)['indexes'] end indexes ||= [] index_yaml = File.join(@app.path, 'index.yaml') if File.exist?(index_yaml) manual_indexes = YAML.load_file(index_yaml)['indexes'] || [] manual_indexes.each do |index| indexes << index unless indexes.include?(index) end end if indexes.size > 0 {'indexes' => indexes} else nil end end end end class JRubyAppCfg NO_XML_COMMANDS = [ 'version' ] RUBY_COMMANDS = ['bundle', 'gem', 'help', 'run'] COMMAND_SUMMARY = < 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 end def gem_help help = < 0 && line.lstrip == line count += 1 print COMMAND_SUMMARY if count == 3 end puts line end end def parse_args(args) if RUBY_COMMANDS.include?(args[0]) return [args[0], args[1, args.length]] elsif args.empty? || !(%w(-h --help) & args).empty? return ['help', []] elsif args[-3] == 'request_logs' command = args[-3] path = args[-2] else command = args[-2] path = args[-1] end return [command, [path]] end end end end end