aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAsutosh Palai <asupalai@gmail.com>2016-06-22 20:32:40 +0530
committerAsutosh Palai <asupalai@gmail.com>2016-07-03 09:41:58 +0530
commit8ebb03557ad50d76d45bd9d849d114c22067a437 (patch)
tree86f856cada240fa7b6bf12555c072fc33ad449ce /lib
parent5fc02346aa552f09ed2bec75fedae58af77d18dd (diff)
downloadbundler-8ebb03557ad50d76d45bd9d849d114c22067a437.tar.gz
Added caching
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/plugin.rb11
-rw-r--r--lib/bundler/plugin/api.rb2
-rw-r--r--lib/bundler/plugin/api/source.rb61
3 files changed, 68 insertions, 6 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 85ae33af..de811505 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -49,10 +49,13 @@ module Bundler
return if definition.dependencies.empty?
- plugins = definition.dependencies.map(&:name)
+ plugins = definition.dependencies.map(&:name).reject {|p| index.installed? p }
install_paths = Installer.new.install_definition(definition)
save_plugins plugins, install_paths, builder.inferred_plugins
+ rescue => e
+ Bundler.ui.error "Failed to install plugin: #{e.message}\n #{e.backtrace[0]}"
+ raise
end
# The index object used to store the details about the plugin
@@ -133,8 +136,8 @@ module Bundler
plugins.each do |name|
path = Pathname.new paths[name]
validate_plugin! path
- register_plugin name, path, optional_plugins.include?(name)
- Bundler.ui.info "Installed plugin #{name}"
+ installed = register_plugin name, path, optional_plugins.include?(name)
+ Bundler.ui.info "Installed plugin #{name}" if installed
end
end
@@ -171,8 +174,10 @@ module Bundler
if optional_plugin && @sources.keys.any? {|s| source? s }
Bundler.rm_rf(path)
+ false
else
index.register_plugin name, path.to_s, @commands.keys, @sources.keys
+ true
end
ensure
@commands = commands
diff --git a/lib/bundler/plugin/api.rb b/lib/bundler/plugin/api.rb
index 88f06edf..71728c14 100644
--- a/lib/bundler/plugin/api.rb
+++ b/lib/bundler/plugin/api.rb
@@ -47,7 +47,7 @@ module Bundler
# The cache dir to be used by the plugins for storage
#
# @return [Pathname] path of the cache dir
- def cache
+ def cache_dir
Plugin.cache.join("plugins")
end
diff --git a/lib/bundler/plugin/api/source.rb b/lib/bundler/plugin/api/source.rb
index e8ec8bf5..97a22f39 100644
--- a/lib/bundler/plugin/api/source.rb
+++ b/lib/bundler/plugin/api/source.rb
@@ -121,11 +121,17 @@ module Bundler
end
# Set internal representation to fetch the gems/specs from remote.
+ #
+ # When this is called, the source should try to fetch the specs and
+ # install from remote path.
def remote!
end
- # Set internal representation to fetch the gems/specs from cache.
- def cache!
+ # Set internal representation to fetch the gems/specs from app cache.
+ #
+ # When this is called, the source should try to fetch the specs and
+ # install from the path provided by `app_cache_path`.
+ def cached!
end
# This is called to update the spec and installation.
@@ -135,6 +141,36 @@ module Bundler
def unlock!
end
+ # Name of directory where plugin the is expected to cache the gems when
+ # #cache is called.
+ #
+ # Also this name is matched against the directories in cache for pruning
+ #
+ # This is used by `app_cache_path`
+ def app_cache_dirname
+ base_name = File.basename(URI.parse(uri).normalize.path)
+ "#{base_name}-#{uri_hash}"
+ end
+
+ # This method is called while caching to save copy of the gems that the
+ # source can resolve to path provided by `app_cache_app`so that they can
+ # be reinstalled from the cache without querying the remote (i.e. an
+ # alternative to remote)
+ #
+ # This is stored with the app and source plugins should try to provide
+ # specs and install only from this cache when `cached!` is called.
+ #
+ # This cache is different from the internal caching that can be done
+ # at sub paths of `cache_path` (from API). This can be though as caching
+ # by bundler.
+ def cache(spec, custom_path = nil)
+ new_cache_path = app_cache_path(custom_path)
+
+ FileUtils.rm_rf(new_cache_path)
+ FileUtils.cp_r(install_path, new_cache_path)
+ 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
@@ -166,14 +202,33 @@ module Bundler
File.directory?(install_path)
end
+ # The full path where the plugin should cache the gem so that it can be
+ # installed latter.
+ #
+ # Note: Do not override if you don't know what you are doing.
+ def app_cache_path(custom_path = nil)
+ @app_cache_path ||= Bundler.app_cache(custom_path).join(app_cache_dirname)
+ end
+
+ # Used by definition.
+ #
+ # Note: Do not override if you don't know what you are doing.
def unmet_deps
specs.unmet_dependency_names
end
+ # Note: Do not override if you don't know what you are doing.
def can_lock?(spec)
spec.source == self
end
+ # Generates the content to be entered into the lockfile.
+ # Saves type and remote and also calls to `options_to_lock`.
+ #
+ # Plugin should use `options_to_lock` to save information in lockfile
+ # and not override this.
+ #
+ # Note: Do not override if you don't know what you are doing.
def to_lock
out = String.new("#{LockfileParser::PLUGIN}\n")
out << " remote: #{@uri}\n"
@@ -188,6 +243,7 @@ module Bundler
"plugin source for #{options[:type]} with uri #{uri}"
end
+ # Note: Do not override if you don't know what you are doing.
def include?(other)
other == self
end
@@ -196,6 +252,7 @@ module Bundler
Digest::SHA1.hexdigest(uri)
end
+ # Note: Do not override if you don't know what you are doing.
def gem_install_dir
Bundler.install_path
end