#!/usr/bin/ruby1.8 -w # # Copyright:: Copyright 2009 Google Inc. # Original Author:: John Woodell (mailto:woodie@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 'rubygems' require 'fileutils' require 'zip/zip' require 'zip/zipfilesystem' require 'rubygems/command_manager' require 'appengine-tools/bundler' module AppEngine module Admin class GemBundler def initialize(root) @root = root @app = Application.new(root) end def bundle(args) verify_gemfile gem_bundle(args) end private def app @app end def gems_out_of_date if File.exists?(app.gems_jar) and File.stat(app.gems_jar).mtime > File.stat(app.gemfile).mtime return false end return true end def gem_bundle(args) return unless args.include?('--update') || gems_out_of_date Gem.platforms = [Gem::Platform::RUBY, Gem::Platform.new('universal-java')] Gem.configuration = Gem::ConfigFile.new(args.unshift('bundle')) puts "=> Bundling gems" begin Dir.chdir(@root) do Gem::CommandManager.instance.run(Gem.configuration.args) end rescue Gem::SystemExitException => e exit e.exit_code unless e.exit_code == 0 end bundler_dir = "#{app.gems_dir}/bundler_gems" # TODO: this temporary hack should be fixed properly gem_patch = < true # blow away the old jar puts "=> Installing gems" gem_files = Dir["#{bundler_dir}/gems/**/**"] + Dir["#{bundler_dir}/environment.rb"] Zip::ZipFile.open(app.gems_jar, 'w') do |jar| gem_files.reject {|f| f == app.gems_jar}.each do |file| jar.add(file.sub("#{app.gems_dir}/",''), file) end end end def verify_gemfile return if File.exists?(app.gemfile) puts "=> Generating gemfile" # TODO: Maybe we should include the latest # versions from updatecheck here? stock_gemfile = <