require'rbconfig'require'fileutils'require'pathname'require'yaml'require'bundler/rubygems_ext'require'bundler/version'moduleBundlerORIGINAL_ENV=ENV.to_hashautoload:Definition,'bundler/definition'autoload:Dependency,'bundler/dependency'autoload:Dsl,'bundler/dsl'autoload:Environment,'bundler/environment'autoload:GemHelper,'bundler/gem_helper'autoload:Graph,'bundler/graph'autoload:Index,'bundler/index'autoload:Installer,'bundler/installer'autoload:LazySpecification,'bundler/lazy_specification'autoload:LockfileParser,'bundler/lockfile_parser'autoload:RemoteSpecification,'bundler/remote_specification'autoload:Resolver,'bundler/resolver'autoload:Runtime,'bundler/runtime'autoload:Settings,'bundler/settings'autoload:SharedHelpers,'bundler/shared_helpers'autoload:SpecSet,'bundler/spec_set'autoload:Source,'bundler/source'autoload:Specification,'bundler/shared_helpers'autoload:UI,'bundler/ui'classBundlerError<StandardErrordefself.status_code(code=nil)define_method(:status_code){code}endendclassGemfileNotFound<BundlerError;status_code(10);endclassGemNotFound<BundlerError;status_code(7);endclassGemfileError<BundlerError;status_code(4);endclassPathError<BundlerError;status_code(13);endclassGitError<BundlerError;status_code(11);endclassDeprecatedError<BundlerError;status_code(12);endclassGemspecError<BundlerError;status_code(14);endclassDslError<BundlerError;status_code(15);endclassProductionError<BundlerError;status_code(16);endclassInvalidOption<DslError;endWINDOWS=RbConfig::CONFIG["host_os"]=~%r!(msdos|mswin|djgpp|mingw)!NULL=WINDOWS?"NUL":"/dev/null"classVersionConflict<BundlerErrorattr_reader:conflictsdefinitialize(conflicts,msg=nil)super(msg)@conflicts=conflictsendstatus_code(6)end# Internal errors, should be rescuedclassInvalidSpecSet<StandardError;endclass<<selfattr_writer:ui,:bundle_pathdefconfigure@configured||=beginconfigure_gem_home_and_pathtrueendenddefui@ui||=UI.newenddefbundle_path# STDERR.puts settings.path@bundle_path||=Pathname.new(settings.path).expand_path(root)enddefbin_path@bin_path||=beginpath=settings[:bin]||"bin"path=Pathname.new(path).expand_path(root)FileUtils.mkdir_p(path)Pathname.new(path).expand_pathendenddefsetup(*groups)return@setupifdefined?(@setup)&&@setupifgroups.empty?# Load all groups, but only once@setup=load.setupelse# Figure out which groups haven't been loaded yetunloaded=groups-(@completed_groups||[])# Record groups that are now loaded@completed_groups=groups|(@completed_groups||[])# Load any groups that are not yet loadedunloaded.any??load.setup(*unloaded):loadendenddefrequire(*groups)setup(*groups).require(*groups)enddefload@load||=Runtime.new(root,definition)enddefenvironmentBundler::Environment.new(root,definition)enddefdefinition(unlock=nil)@definition=nilifunlock@definition||=beginconfigureupgrade_lockfileDefinition.build(default_gemfile,default_lockfile,unlock)endenddefruby_scope"#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}"enddefuser_bundle_pathPathname.new(Gem.user_home).join(".bundler")enddefhomebundle_path.join("bundler")enddefinstall_pathhome.join("gems")enddefspecs_pathbundle_path.join("specifications")enddefcachebundle_path.join("cache/bundler")enddefrootdefault_gemfile.dirname.expand_pathenddefapp_config_pathENV['BUNDLE_APP_CONFIG']?Pathname.new(ENV['BUNDLE_APP_CONFIG']).expand_path(root):root.join('.bundle')enddefapp_cacheroot.join("vendor/cache")enddeftmpuser_bundle_path.join("tmp",Process.pid.to_s)enddefsettings@settings||=Settings.new(app_config_path)enddefwith_clean_envbundled_env=ENV.to_hashENV.replace(ORIGINAL_ENV)yieldensureENV.replace(bundled_env.to_hash)enddefdefault_gemfileSharedHelpers.default_gemfileenddefdefault_lockfileSharedHelpers.default_lockfileenddefrequires_sudo?path=bundle_pathpath=path.parentuntilpath.exist?sudo_present=!`which sudo 2>#{NULL}`.empty?settings.allow_sudo?&&!File.writable?(path)&&sudo_presentenddefmkdir_p(path)ifrequires_sudo?sudo"mkdir -p '#{path}'"unlessFile.exist?(path)elseFileUtils.mkdir_p(path)endenddefsudo(str)`sudo -p 'Enter your password to install the bundled RubyGems to your system: ' #{str}`enddefread_file(file)File.open(file,"rb"){|file|file.read}enddefload_gemspec(file)path=Pathname.new(file)# Eval the gemspec from its parent directoryDir.chdir(path.dirname)dobeginGem::Specification.from_yaml(path.basename)# Raises ArgumentError if the file is not valid YAMLrescueArgumentError,SyntaxError,Gem::EndOfYAMLException,Gem::Exceptionbegineval(File.read(path.basename),TOPLEVEL_BINDING,path.expand_path.to_s)rescueLoadError=>eoriginal_line=e.backtrace.find{|line|line.include?(path.to_s)}msg="There was a LoadError while evaluating #{path.basename}:\n#{e.message}"msg<<" from\n#{original_line}"iforiginal_linemsg<<"\n"ifRUBY_VERSION>="1.9.0"msg<<"\nDoes it try to require a relative path? That doesn't work in Ruby 1.9."endraiseGemspecError,msgendendendendprivatedefconfigure_gem_home_and_pathifsettings[:disable_shared_gems]ENV['GEM_PATH']=''ENV['GEM_HOME']=File.expand_path(bundle_path,root)elsifGem.dir!=bundle_path.to_spaths=[Gem.dir,Gem.path].flatten.compact.uniq.reject{|p|p.empty?}ENV["GEM_PATH"]=paths.join(File::PATH_SEPARATOR)ENV["GEM_HOME"]=bundle_path.to_sendGem.clear_pathsenddefupgrade_lockfilelockfile=default_lockfileiflockfile.exist?&&lockfile.read(3)=="---"Bundler.ui.warn"Detected Gemfile.lock generated by 0.9, deleting..."lockfile.rmtree# lock = YAML.load_file(lockfile)## source_uris = lock["sources"].map{|s| s["Rubygems"]["uri"] }# sources = [Bundler::Source::Rubygems.new({"remotes" => source_uris})]## deps = lock["dependencies"].map do |name, opts|# version = opts.delete("version")# Bundler::Dependency.new(name, version, opts)# end## definition = Bundler::Definition.new(nil, deps, sources, {})## File.open(lockfile, 'w') do |f|# f.write definition.to_lock# endendendendend