# frozen_string_literal: truemoduleBundler# Handles the installation of plugin in appropriate directories.## This class is supposed to be wrapper over the existing gem installation infra# but currently it itself handles everything as the Source's subclasses (e.g. Source::RubyGems)# are heavily dependent on the Gemfile.modulePluginclassInstallerautoload:Rubygems,File.expand_path("installer/rubygems",__dir__)autoload:Git,File.expand_path("installer/git",__dir__)autoload:Path,File.expand_path("installer/path",__dir__)definstall(names,options)check_sources_consistency!(options)version=options[:version]||[">= 0"]ifoptions[:git]install_git(names,version,options)elsifoptions[:path]install_path(names,version,options[:path])elsesources=options[:source]||Gem.sourcesinstall_rubygems(names,version,sources)endend# Installs the plugin from Definition object created by limited parsing of# Gemfile searching for plugins to be installed## @param [Definition] definition object# @return [Hash] map of names to their specs they are installed withdefinstall_definition(definition)defdefinition.lock(*);enddefinition.resolve_remotely!specs=definition.specsinstall_from_specsspecsendprivatedefcheck_sources_consistency!(options)ifoptions.key?(:git)&&options.key?(:local_git)raiseInvalidOption,"Remote and local plugin git sources can't be both specified"end# back-compat; local_git is an alias for gitifoptions.key?(:local_git)Bundler::SharedHelpers.major_deprecation(2,"--local_git is deprecated, use --git")options[:git]=options.delete(:local_git)endif(options.keys&[:source,:git,:path]).length>1raiseInvalidOption,"Only one of --source, --git, or --path may be specified"endif(options.key?(:branch)||options.key?(:ref))&&!options.key?(:git)raiseInvalidOption,"--#{options.key?(:branch)?"branch":"ref"} can only be used with git sources"endifoptions.key?(:branch)&&options.key?(:ref)raiseInvalidOption,"--branch and --ref can't be both specified"endenddefinstall_git(names,version,options)source_list=SourceList.newsource=source_list.add_git_source({"uri"=>options[:git],"branch"=>options[:branch],"ref"=>options[:ref]})install_all_sources(names,version,source_list,source)enddefinstall_path(names,version,path)source_list=SourceList.newsource=source_list.add_path_source({"path"=>path,"root_path"=>SharedHelpers.pwd})install_all_sources(names,version,source_list,source)end# Installs the plugin from rubygems source and returns the path where the# plugin was installed## @param [String] name of the plugin gem to search in the source# @param [Array] version of the gem to install# @param [String, Array<String>] source(s) to resolve the gem## @return [Hash] map of names to the specs of plugins installeddefinstall_rubygems(names,version,sources)source_list=SourceList.newArray(sources).each{|remote|source_list.add_global_rubygems_remote(remote)}install_all_sources(names,version,source_list)enddefinstall_all_sources(names,version,source_list,source=nil)deps=names.map{|name|Dependency.new(name,version,{"source"=>source})}Bundler.configure_gem_home_and_path(Plugin.root)Bundler.settings.temporary(deployment: false,frozen: false)dodefinition=Definition.new(nil,deps,source_list,true)install_definition(definition)endend# Installs the plugins and deps from the provided specs and returns map of# gems to their paths## @param specs to install## @return [Hash] map of names to the specsdefinstall_from_specs(specs)paths={}specs.eachdo|spec|spec.source.installspecpaths[spec.name]=specendpathsendendendend