diff options
Diffstat (limited to 'lib/bundler/plugin/api')
| -rw-r--r-- | lib/bundler/plugin/api/source.rb | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/lib/bundler/plugin/api/source.rb b/lib/bundler/plugin/api/source.rb index 586477efb5..798326673a 100644 --- a/lib/bundler/plugin/api/source.rb +++ b/lib/bundler/plugin/api/source.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "uri" - module Bundler module Plugin class API @@ -37,11 +35,11 @@ module Bundler # # @!attribute [rw] dependency_names # @return [Array<String>] Names of dependencies that the source should - # try to resolve. It is not necessary to use this list intenally. This + # try to resolve. It is not necessary to use this list internally. This # is present to be compatible with `Definition` and is used by # rubygems source. module Source - attr_reader :uri, :options, :name + attr_reader :uri, :options, :name, :checksum_store attr_accessor :dependency_names def initialize(opts) @@ -50,6 +48,7 @@ module Bundler @uri = opts["uri"] @type = opts["type"] @name = opts["name"] || "#{@type} at #{@uri}" + @checksum_store = Checksum::Store.new end # This is used by the default `spec` method to constructs the @@ -68,13 +67,21 @@ module Bundler # to check out same version of gem later. # # There options are passed when the source plugin is created from the - # lock file. + # lockfile. # # @return [Hash] def options_to_lock {} end + # Download the gem specified by the spec at appropriate path. + # + # A source plugin can implement this method to split the download and the + # installation of a gem. + # + # @return [Boolean] Whether the download of the gem succeeded. + def download(spec, opts); end + # Install the gem specified by the spec at appropriate path. # `install_path` provides a sufficient default, if the source can only # satisfy one gem, but is not binding. @@ -97,7 +104,7 @@ module Bundler # # Note: Do not override if you don't know what you are doing. def post_install(spec, disable_exts = false) - opts = { :env_shebang => false, :disable_extensions => disable_exts } + opts = { env_shebang: false, disable_extensions: disable_exts } installer = Bundler::Source::Path::Installer.new(spec, opts) installer.post_install end @@ -108,7 +115,7 @@ module Bundler def install_path @install_path ||= begin - base_name = File.basename(URI.parse(uri).normalize.path) + base_name = File.basename(Gem::URI.parse(uri).normalize.path) gem_install_dir.join("#{base_name}-#{uri_hash[0..11]}") end @@ -132,7 +139,7 @@ module Bundler Bundler::Index.build do |index| files.each do |file| next unless spec = Bundler.load_gemspec(file) - Bundler.rubygems.set_installed_by_version(spec) + spec.installed_by_version = Gem::VERSION spec.source = self Bundler.rubygems.validate(spec) @@ -142,6 +149,13 @@ module Bundler end end + # Set internal representation to fetch the gems/specs locally. + # + # When this is called, the source should try to fetch the specs and + # install from the local system. + def local! + end + # Set internal representation to fetch the gems/specs from remote. # # When this is called, the source should try to fetch the specs and @@ -170,7 +184,7 @@ module Bundler # # This is used by `app_cache_path` def app_cache_dirname - base_name = File.basename(URI.parse(uri).normalize.path) + base_name = File.basename(Gem::URI.parse(uri).normalize.path) "#{base_name}-#{uri_hash}" end @@ -190,13 +204,14 @@ module Bundler FileUtils.rm_rf(new_cache_path) FileUtils.cp_r(install_path, new_cache_path) + FileUtils.rm_rf(app_cache_path.join(".git")) FileUtils.touch(app_cache_path.join(".bundlecache")) end # This shall check if two source object represent the same source. # # The comparison shall take place only on the attribute that can be - # inferred from the options passed from Gemfile and not on attibutes + # inferred from the options passed from Gemfile and not on attributes # that are used to pin down the gem to specific version (e.g. Git # sources should compare on branch and tag but not on commit hash) # @@ -239,7 +254,21 @@ module Bundler specs.unmet_dependency_names end + # Used by definition. + # + # Note: Do not override if you don't know what you are doing. + def spec_names + specs.spec_names + end + + # Used by definition. + # # Note: Do not override if you don't know what you are doing. + def add_dependency_names(names) + @dependencies |= Array(names) + end + + # NOTE: Do not override if you don't know what you are doing. def can_lock?(spec) spec.source == self end @@ -262,10 +291,11 @@ module Bundler end def to_s - "plugin source for #{options[:type]} with uri #{uri}" + "plugin source for #{@type} with uri #{@uri}" end + alias_method :identifier, :to_s - # Note: Do not override if you don't know what you are doing. + # NOTE: Do not override if you don't know what you are doing. def include?(other) other == self end @@ -274,7 +304,7 @@ module Bundler SharedHelpers.digest(:SHA1).hexdigest(uri) end - # Note: Do not override if you don't know what you are doing. + # NOTE: Do not override if you don't know what you are doing. def gem_install_dir Bundler.install_path end @@ -289,12 +319,6 @@ module Bundler end # @private - # Returns true - def bundler_plugin_api_source? - true - end - - # @private # This API on source might not be stable, and for now we expect plugins # to download all specs in `#specs`, so we implement the method for # compatibility purposes and leave it undocumented (and don't support) |
