summaryrefslogtreecommitdiff
path: root/lib/bundler/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/plugin')
-rw-r--r--lib/bundler/plugin/api/source.rb8
-rw-r--r--lib/bundler/plugin/events.rb68
-rw-r--r--lib/bundler/plugin/index.rb52
-rw-r--r--lib/bundler/plugin/installer.rb13
-rw-r--r--lib/bundler/plugin/source_list.rb2
5 files changed, 114 insertions, 29 deletions
diff --git a/lib/bundler/plugin/api/source.rb b/lib/bundler/plugin/api/source.rb
index 6c888d0373..798326673a 100644
--- a/lib/bundler/plugin/api/source.rb
+++ b/lib/bundler/plugin/api/source.rb
@@ -74,6 +74,14 @@ module Bundler
{}
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.
diff --git a/lib/bundler/plugin/events.rb b/lib/bundler/plugin/events.rb
index 29c05098ae..3fbf60307e 100644
--- a/lib/bundler/plugin/events.rb
+++ b/lib/bundler/plugin/events.rb
@@ -31,6 +31,54 @@ module Bundler
end
# @!parse
+ # A hook called before the Gemfile is evaluated
+ # Includes the Gemfile path and the Lockfile path
+ # GEM_BEFORE_EVAL = "before-eval"
+ define :GEM_BEFORE_EVAL, "before-eval"
+
+ # @!parse
+ # A hook called after the Gemfile is evaluated
+ # Includes a Bundler::Definition
+ # GEM_AFTER_EVAL = "after-eval"
+ define :GEM_AFTER_EVAL, "after-eval"
+
+ # @!parse
+ # A hook called before any gems install
+ # Includes an Array of Bundler::Dependency objects
+ # GEM_BEFORE_INSTALL_ALL = "before-install-all"
+ define :GEM_BEFORE_INSTALL_ALL, "before-install-all"
+
+ # @!parse
+ # A hook called before each individual gem is downloaded from a remote source.
+ # Includes a spec-like object responding to the Gem::Specification API
+ # (for example, a Bundler spec proxy such as Bundler::EndpointSpecification
+ # or Bundler::RemoteSpecification). Does not fire when the gem is already
+ # present at the initial download-cache check.
+ # GEM_BEFORE_FETCH = "before-fetch"
+ define :GEM_BEFORE_FETCH, "before-fetch"
+
+ # @!parse
+ # A hook called after each individual gem is downloaded from a remote source.
+ # Includes a spec-like object responding to the Gem::Specification API
+ # (for example, a Bundler spec proxy such as Bundler::EndpointSpecification
+ # or Bundler::RemoteSpecification). Does not fire when the gem is already
+ # present at the initial download-cache check.
+ # GEM_AFTER_FETCH = "after-fetch"
+ define :GEM_AFTER_FETCH, "after-fetch"
+
+ # @!parse
+ # A hook called before a git source is fetched or checked out.
+ # Includes a Bundler::Source::Git reference.
+ # GIT_BEFORE_FETCH = "before-git-fetch"
+ define :GIT_BEFORE_FETCH, "before-git-fetch"
+
+ # @!parse
+ # A hook called after a git source is fetched or checked out.
+ # Includes a Bundler::Source::Git reference.
+ # GIT_AFTER_FETCH = "after-git-fetch"
+ define :GIT_AFTER_FETCH, "after-git-fetch"
+
+ # @!parse
# A hook called before each individual gem is installed
# Includes a Bundler::ParallelInstaller::SpecInstallation.
# No state, error, post_install_message will be present as nothing has installed yet
@@ -46,18 +94,18 @@ module Bundler
define :GEM_AFTER_INSTALL, "after-install"
# @!parse
- # A hook called before any gems install
- # Includes an Array of Bundler::Dependency objects
- # GEM_BEFORE_INSTALL_ALL = "before-install-all"
- define :GEM_BEFORE_INSTALL_ALL, "before-install-all"
-
- # @!parse
# A hook called after any gems install
# Includes an Array of Bundler::Dependency objects
# GEM_AFTER_INSTALL_ALL = "after-install-all"
define :GEM_AFTER_INSTALL_ALL, "after-install-all"
# @!parse
+ # A hook called before any gems require
+ # Includes an Array of Bundler::Dependency objects.
+ # GEM_BEFORE_REQUIRE_ALL = "before-require-all"
+ define :GEM_BEFORE_REQUIRE_ALL, "before-require-all"
+
+ # @!parse
# A hook called before each individual gem is required
# Includes a Bundler::Dependency.
# GEM_BEFORE_REQUIRE = "before-require"
@@ -70,16 +118,10 @@ module Bundler
define :GEM_AFTER_REQUIRE, "after-require"
# @!parse
- # A hook called before any gems require
- # Includes an Array of Bundler::Dependency objects.
- # GEM_BEFORE_REQUIRE_ALL = "before-require-all"
- define :GEM_BEFORE_REQUIRE_ALL, "before-require-all"
-
- # @!parse
# A hook called after all gems required
# Includes an Array of Bundler::Dependency objects.
# GEM_AFTER_REQUIRE_ALL = "after-require-all"
- define :GEM_AFTER_REQUIRE_ALL, "after-require-all"
+ define :GEM_AFTER_REQUIRE_ALL, "after-require-all"
end
end
end
diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb
index 0682d37772..1dfb061304 100644
--- a/lib/bundler/plugin/index.rb
+++ b/lib/bundler/plugin/index.rb
@@ -119,6 +119,12 @@ module Bundler
@plugin_paths[name]
end
+ def up_to_date?(spec)
+ path = installed?(spec.name)
+
+ path == spec.full_gem_path
+ end
+
def installed_plugins
@plugin_paths.keys
end
@@ -157,6 +163,8 @@ module Bundler
# @param [Pathname] index file path
# @param [Boolean] is the index file global index
def load_index(index_file, global = false)
+ base = base_for_index(global)
+
SharedHelpers.filesystem_access(index_file, :read) do |index_f|
valid_file = index_f&.exist? && !index_f.size.zero?
break unless valid_file
@@ -168,8 +176,8 @@ module Bundler
@commands.merge!(index["commands"])
@hooks.merge!(index["hooks"])
- @load_paths.merge!(index["load_paths"])
- @plugin_paths.merge!(index["plugin_paths"])
+ @load_paths.merge!(transform_index_paths(index["load_paths"]) {|p| absolutize_path(p, base) })
+ @plugin_paths.merge!(transform_index_paths(index["plugin_paths"]) {|p| absolutize_path(p, base) })
@sources.merge!(index["sources"]) unless global
end
end
@@ -178,11 +186,13 @@ module Bundler
# instance variables in YAML format. (The instance variables are supposed
# to be only String key value pairs)
def save_index
+ base = base_for_index(false)
+
index = {
"commands" => @commands,
"hooks" => @hooks,
- "load_paths" => @load_paths,
- "plugin_paths" => @plugin_paths,
+ "load_paths" => transform_index_paths(@load_paths) {|p| relativize_path(p, base) },
+ "plugin_paths" => transform_index_paths(@plugin_paths) {|p| relativize_path(p, base) },
"sources" => @sources,
}
@@ -192,6 +202,40 @@ module Bundler
File.open(index_f, "w") {|f| f.puts YAMLSerializer.dump(index) }
end
end
+
+ def base_for_index(global)
+ global ? Plugin.global_root : Plugin.root
+ end
+
+ def transform_index_paths(paths)
+ return {} unless paths
+
+ paths.transform_values do |value|
+ if value.is_a?(Array)
+ value.map {|path| yield path }
+ else
+ yield value
+ end
+ end
+ end
+
+ def relativize_path(path, base)
+ pathname = Pathname.new(path)
+ return path unless pathname.absolute?
+
+ base_path = Pathname.new(base)
+ if pathname == base_path || pathname.to_s.start_with?(base_path.to_s + File::SEPARATOR)
+ pathname.relative_path_from(base_path).to_s
+ else
+ path
+ end
+ end
+
+ def absolutize_path(path, base)
+ pathname = Pathname.new(path)
+ pathname = Pathname.new(base).join(pathname) unless pathname.absolute?
+ pathname.to_s
+ end
end
end
end
diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb
index ac3c3ea7f3..9be8b36843 100644
--- a/lib/bundler/plugin/installer.rb
+++ b/lib/bundler/plugin/installer.rb
@@ -43,16 +43,6 @@ module Bundler
private
def check_sources_consistency!(options)
- if options.key?(:git) && options.key?(:local_git)
- raise InvalidOption, "Remote and local plugin git sources can't be both specified"
- end
-
- # back-compat; local_git is an alias for git
- if options.key?(:local_git)
- Bundler::SharedHelpers.major_deprecation(2, "--local_git is deprecated, use --git")
- options[:git] = options.delete(:local_git)
- end
-
if (options.keys & [:source, :git, :path]).length > 1
raise InvalidOption, "Only one of --source, --git, or --path may be specified"
end
@@ -120,7 +110,8 @@ module Bundler
paths = {}
specs.each do |spec|
- spec.source.install spec
+ spec.source.download(spec)
+ spec.source.install(spec)
paths[spec.name] = spec
end
diff --git a/lib/bundler/plugin/source_list.rb b/lib/bundler/plugin/source_list.rb
index 746996de55..d929ade29e 100644
--- a/lib/bundler/plugin/source_list.rb
+++ b/lib/bundler/plugin/source_list.rb
@@ -23,7 +23,7 @@ module Bundler
private
- def rubygems_aggregate_class
+ def source_class
Plugin::Installer::Rubygems
end
end