#! /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 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 IO.read(cron) end nil end def getQueueYaml queue = File.join(app.path, 'queue.yaml') if File.exists?(queue) return IO.read(queue) 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 = %w{version} RUBY_COMMANDS = %w{gem bundle help run} COMMAND_SUMMARY = < 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(*args) if File.directory?(args[-1] || '') AppEngine::Admin.bundle_app(*args) else bundle_help end end def bundle_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