moduleBundlerclassInvalidRepository<StandardError;endclassBundleattr_reader:gemfile,:environmentdefself.load(gemfile=nil)gemfile=Pathname.new(gemfile||default_gemfile).expand_pathunlessgemfile.file?raiseManifestFileNotFound,"Manifest file not found: #{gemfile.to_s.inspect}"endnew(gemfile)enddefself.default_gemfilecurrent=Pathname.new(Dir.pwd)untilcurrent.root?filename=current.join("Gemfile")returnfilenameiffilename.exist?current=current.parentendraiseDefaultManifestNotFoundend# TODO: passing in the filename is not gooddefinitialize(gemfile)@gemfile=gemfile@environment=Environment.new(self)Dsl.evaluate(gemfile,self,@environment)# path = env.gem_pathFileUtils.mkdir_p(gem_path)@cache_path=gem_path.join('cache')@cache=GemDirectorySource.new(self,:location=>@cache_path)@specs_path=gem_path.join('specifications')@gems_path=gem_path.join('gems')enddefrootgemfile.parentenddefpath@path||=root.join("vendor/gems")enddefpath=(path)@path=(path.relative??root.join(path):path).expand_pathenddefgem_pathpath.join("#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}")enddefbindir@bindir||=root.join("bin")enddefbindir=(path)@bindir=(path.relative??root.join(path):path).expand_pathenddefinstall(options={})dependencies=@environment.dependenciessources=@environment.sources# ========== from envifonly_envs=options[:only]dependencies.reject!{|d|!only_envs.any?{|env|d.in?(env)}}end# ==========# TODO: clean this upsources.eachdo|s|s.local=options[:cached]end# Check to see whether the existing cache meets all the requirementsbeginvalid=nil# valid = Resolver.resolve(dependencies, [source_index], source_requirements)rescueBundler::GemNotFoundendsources=only_local(sources)ifoptions[:cached]# Check the remote sources if the existing cache does not meet the requirements# or the user passed --updateifoptions[:update]||!validBundler.logger.info"Calculating dependencies..."bundle=Resolver.resolve(dependencies,[@cache]+sources)download(bundle,options)do_install(bundle,options)valid=bundleendgenerate_bins(valid,options)cleanup(valid,options)configure(valid,options)Bundler.logger.info"Done."enddefcache(*gemfiles)FileUtils.mkdir_p(@cache_path)gemfiles.eachdo|gemfile|Bundler.logger.info"Caching: #{File.basename(gemfile)}"FileUtils.cp(gemfile,@cache_path)endenddeflist_outdated(options={})outdated_gems=source_index.outdated.sortifoutdated_gems.empty?Bundler.logger.info"All gems are up to date."elseBundler.logger.info"Outdated gems:"outdated_gems.eachdo|name|Bundler.logger.info" * #{name}"endendenddefprune(options={})dependencies,sources=@environment.gem_dependencies,@environment.sourcessources.eachdo|s|s.local=trueendsources=only_local(sources)bundle=Resolver.resolve(dependencies,[@cache]+sources)@cache.gems.eachdo|name,specs|specs.eachdo|spec|unlessbundle.any?{|s|s.name==spec.name&&s.version==spec.version}Bundler.logger.info"Pruning #{spec.name} (#{spec.version}) from the cache"FileUtils.rm@cache_path.join("#{spec.full_name}.gem")endendendenddeflist(options={})Bundler.logger.info"Currently bundled gems:"gems.eachdo|spec|Bundler.logger.info" * #{spec.name} (#{spec.version})"endenddefgemssource_index.gems.valuesenddefsource_indexindex=Gem::SourceIndex.from_gems_in(@specs_path)index.each{|n,spec|spec.loaded_from=@specs_path.join("#{spec.full_name}.gemspec")}indexenddefdownload_path_for(type)@repos[type].download_path_forenddefsetup_environmentunless@environment.system_gemsENV["GEM_HOME"]=gem_pathENV["GEM_PATH"]=gem_pathendENV["PATH"]="#{bindir}:#{ENV["PATH"]}"ENV["RUBYOPT"]="-r#{gem_path}/environment #{ENV["RUBYOPT"]}"endprivatedefonly_local(sources)sources.select{|s|s.can_be_local?}enddefdownload(bundle,options)bundle.sort_by{|s|s.full_name.downcase}.eachdo|spec|nextifspec.no_bundle?spec.source.download(spec)endenddefdo_install(bundle,options)bundle.eachdo|spec|nextifspec.no_bundle?spec.loaded_from=@specs_path.join("#{spec.full_name}.gemspec")# Do nothing if the gem is already expandednextif@gems_path.join(spec.full_name).directory?casespec.sourcewhenGemSource,GemDirectorySource,SystemGemSourceexpand_gemfile(spec,options)elseexpand_vendored_gem(spec,options)endendenddefgenerate_bins(bundle,options)bundle.eachdo|spec|nextifspec.no_bundle?# HAX -- Generate the binbin_dir=bindirpath=gem_pathgems_path=@gems_pathinstaller=Gem::Installer.allocateinstaller.instance_evaldo@spec=spec@bin_dir=bin_dir@gem_dir=gems_path.join(spec.full_name)@gem_home=path@wrappers=true@format_executable=false@env_shebang=falseendinstaller.generate_binendenddefexpand_gemfile(spec,options)Bundler.logger.info"Installing #{spec.name} (#{spec.version})"gemfile=@cache_path.join("#{spec.full_name}.gem").to_sifbuild_args=options[:build_options]&&options[:build_options][spec.name]Gem::Command.build_args=build_args.map{|k,v|"--with-#{k}=#{v}"}endinstaller=Gem::Installer.new(gemfile,options.merge(:install_dir=>gem_path,:ignore_dependencies=>true,:env_shebang=>true,:wrappers=>true,:bin_dir=>bindir))installer.installrescueGem::InstallErrorcleanup_spec(spec)raiseensureGem::Command.build_args=[]enddefexpand_vendored_gem(spec,options)add_spec(spec)FileUtils.mkdir_p(@gems_path)File.symlink(spec.location,@gems_path.join(spec.full_name))enddefadd_spec(spec)destination=@specs_pathdestination.mkdirunlessdestination.exist?File.open(destination.join("#{spec.full_name}.gemspec"),'w')do|f|f.putsspec.to_rubyendenddefcleanup(valid,options)to_delete=gemsto_delete.delete_ifdo|spec|valid.any?{|other|spec.name==other.name&&spec.version==other.version}endvalid_executables=valid.map{|s|s.executables}.flatten.compactto_delete.eachdo|spec|Bundler.logger.info"Deleting gem: #{spec.name} (#{spec.version})"cleanup_spec(spec)# Cleanup the bin directoryspec.executables.eachdo|bin|nextifvalid_executables.include?(bin)Bundler.logger.info"Deleting bin file: #{bin}"FileUtils.rm_rf(bindir.join(bin))endendenddefcleanup_spec(spec)FileUtils.rm_rf(@specs_path.join("#{spec.full_name}.gemspec"))FileUtils.rm_rf(@gems_path.join(spec.full_name))enddefexpand(options)each_repodo|repo|repo.expand(options)endenddefconfigure(specs,options)FileUtils.mkdir_p(gem_path)File.open(gem_path.join("environment.rb"),"w")do|file|file.puts@environment.environment_rb(specs,options)endgenerate_environment_pickerenddefgenerate_environment_pickerFileUtils.cp("#{File.dirname(__FILE__)}/templates/environment_picker.erb",path.join("environment.rb"))enddefrequire_code(file,dep)constraint=casewhendep.onlythen%{ if #{dep.only.inspect}.include?(env)}whendep.exceptthen%{ unless #{dep.except.inspect}.include?(env)}end"require #{file.inspect}#{constraint}"endendend