lib/bundler/source.rb in bundler-0.9.0.pre4 vs lib/bundler/source.rb in bundler-0.9.0.pre5
- old
+ new
@@ -1,31 +1,36 @@
require "rubygems/remote_fetcher"
require "rubygems/format"
require "digest/sha1"
+require "open3"
module Bundler
module Source
class Rubygems
attr_reader :uri, :options
def initialize(options = {})
@options = options
- @uri = options[:uri]
+ @uri = options["uri"]
@uri = URI.parse(@uri) unless @uri.is_a?(URI)
raise ArgumentError, "The source must be an absolute URI" unless @uri.absolute?
end
+ def to_s
+ "rubygems repository at `#{uri}`"
+ end
+
def specs
@specs ||= fetch_specs
end
def install(spec)
destination = Gem.dir
- Bundler.ui.info " * Downloading..."
+ Bundler.ui.debug " * Downloading..."
gem_path = Gem::RemoteFetcher.fetcher.download(spec, uri, destination)
- Bundler.ui.info " * Installing..."
+ Bundler.ui.debug " * Installing..."
installer = Gem::Installer.new gem_path,
:install_dir => Gem.dir,
:ignore_dependencies => true
installer.install
@@ -33,18 +38,18 @@
private
def fetch_specs
index = Index.new
- Bundler.ui.info "Source: Fetching remote index for `#{uri}`... "
+ Bundler.ui.info "Fetching source index from `#{uri}`... "
(main_specs + prerelease_specs).each do |name, version, platform|
next unless Gem::Platform.match(platform)
spec = RemoteSpecification.new(name, version, platform, @uri)
spec.source = self
index << spec
end
- Bundler.ui.info "done."
+ Bundler.ui.info "Done."
index.freeze
end
def main_specs
Marshal.load(Gem::RemoteFetcher.fetcher.fetch_path("#{uri}/specs.4.8.gz"))
@@ -73,23 +78,27 @@
index
end
end
def to_s
- "System gem source"
+ "system gems"
end
def install(spec)
- Bundler.ui.info " * already installed... skipping"
+ Bundler.ui.debug " * already installed... skipping"
end
end
class GemCache
def initialize(options)
- @path = options[:path]
+ @path = options["path"]
end
+ def to_s
+ ".gem files at #{@path}"
+ end
+
def specs
@specs ||= begin
index = Index.new
Dir["#{@path}/*.gem"].each do |gemfile|
@@ -103,11 +112,11 @@
end
def install(spec)
destination = Gem.dir
- Bundler.ui.info " * Installing from pack..."
+ Bundler.ui.debug " * Installing from pack..."
installer = Gem::Installer.new "#{@path}/#{spec.full_name}.gem",
:install_dir => Gem.dir,
:ignore_dependencies => true
installer.install
@@ -117,15 +126,19 @@
class Path
attr_reader :path, :options
def initialize(options)
@options = options
- @glob = options[:glob] || "{,*/}*.gemspec"
- @path = options[:path]
+ @glob = options["glob"] || "{,*/}*.gemspec"
+ @path = options["path"]
@default_spec = nil
end
+ def to_s
+ "source code at #{@path}"
+ end
+
def default_spec(*args)
return @default_spec if args.empty?
name, version = *args
@default_spec = Specification.new do |s|
s.name = name
@@ -158,11 +171,11 @@
index.freeze
end
end
def install(spec)
- Bundler.ui.info " * Using path `#{path}`..."
+ Bundler.ui.debug " * Using path `#{path}`..."
end
alias specs local_specs
end
@@ -170,27 +183,28 @@
class Git < Path
attr_reader :uri, :ref
def initialize(options)
@options = options
- @glob = options[:glob] || "{,*/}*.gemspec"
- @uri = options[:uri]
- @ref = options[:ref] || options[:branch] || 'master'
+ @glob = options["glob"] || "{,*/}*.gemspec"
+ @uri = options["uri"]
+ @ref = options["ref"] || options["branch"] || 'master'
end
+ def to_s
+ ref = @options["ref"] ? @options["ref"][0..6] : @ref
+ "#{@uri} (at #{ref})"
+ end
+
def options
- @options.merge(:ref => revision)
+ @options.merge("ref" => revision)
end
def path
Bundler.install_path.join("#{base_name}-#{uri_hash}-#{ref}")
end
- def to_s
- @uri
- end
-
def specs
@specs ||= begin
index = Index.new
# Start by making sure the git cache is up to date
cache
@@ -218,32 +232,38 @@
index.freeze
end
end
def install(spec)
- Bundler.ui.info " * Using git `#{uri}`..."
+ Bundler.ui.debug " * Using git `#{uri}`..."
if @installed
- Bundler.ui.info " * Already checked out revision: #{ref}..."
+ Bundler.ui.debug " * Already checked out revision: #{ref}..."
else
- Bundler.ui.info " * Checking out revision: #{ref}..."
+ Bundler.ui.debug " * Checking out revision: #{ref}..."
FileUtils.mkdir_p(path)
Dir.chdir(path) do
unless File.exist?(".git")
- %x(git clone --recursive --no-checkout #{cache_path} #{path})
+ %x(git clone --no-checkout #{cache_path} #{path})
end
- %x(git fetch --quiet)
- %x(git reset --hard #{revision})
- %x(git submodule init)
- %x(git submodule update)
+ git "fetch --quiet"
+ git "reset --hard #{revision}"
end
@installed = true
end
end
private
+ def git(command)
+ out = %x{git #{command}}
+ if $? != 0
+ raise GitError, "An error has occurred in git. Cannot complete bundling."
+ end
+ out
+ end
+
def base_name
File.basename(uri, ".git")
end
def uri_hash
@@ -254,21 +274,21 @@
@cache_path ||= Bundler.cache.join("git", "#{base_name}-#{uri_hash}")
end
def cache
if cache_path.exist?
- Bundler.ui.info "Source: Updating `#{uri}`... "
- in_cache { `git fetch --quiet #{uri} master:master` }
+ Bundler.ui.info "Updating `#{uri}`... "
+ in_cache { git "fetch --quiet #{uri} master:master" }
else
- Bundler.ui.info "Source: Cloning `#{uri}`... "
+ Bundler.ui.info "Fetching `#{uri}`... "
FileUtils.mkdir_p(cache_path.dirname)
- `git clone #{uri} #{cache_path} --bare --no-hardlinks`
+ git "clone #{uri} #{cache_path} --bare --no-hardlinks"
end
Bundler.ui.info "Done."
end
def revision
- @revision ||= in_cache { `git rev-parse #{ref}`.strip }
+ @revision ||= in_cache { git("rev-parse #{ref}").strip }
end
def in_cache(&blk)
Dir.chdir(cache_path, &blk)
end
\ No newline at end of file