#! /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.ComGoogleAppengineToolsUtil.Logging $CLASSPATH << File.dirname(__FILE__) import Java.ComGoogleAppengineJruby.AppVersionUploadDelegate import Java.ComGoogleAppengineJruby.JRubyAppVersionUpload class UploadDelegate include AppVersionUploadDelegate def index_yaml(app) indexes = merge_indexes(app) if indexes return indexes.to_yaml end '' end def cron_yaml(app) cron = File.join(app.path, 'cron.yaml') if File.exists?(cron) return IO.read(cron) end '' end def queue_yaml(app) queue = File.join(app.path, 'queue.yaml') if File.exists?(queue) return IO.read(queue) end '' end def merge_indexes(app) 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 generate_app} COMMAND_SUMMARY = < Running AppCfg" run_appcfg(args) end def run_appcfg(args) JRubyAppVersionUpload.set_delegate(UploadDelegate.new) factory = AppAdminFactory.new factory.setAppVersionUploadClass(JRubyAppVersionUpload.java_class) Logging.initializeLogging AppCfg.new(factory, args.to_java(java.lang.String)) end def generate_app(*args) if args and args.size > 0 appdir = args.pop webinf = File.join(appdir, 'WEB-INF') FileUtils.mkdir_p(webinf) AppEngine::Admin.bundle_app(appdir) else generate_app_help end end def generate_app_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