lib/bundler.rb in bundler-0.9.26 vs lib/bundler.rb in bundler-1.0.0.beta.1
- old
+ new
@@ -3,29 +3,31 @@
require 'yaml'
require 'bundler/rubygems_ext'
require 'bundler/version'
module Bundler
+ ORIGINAL_ENV = ENV.to_hash
+
autoload :Definition, 'bundler/definition'
autoload :Dependency, 'bundler/dependency'
autoload :Dsl, 'bundler/dsl'
autoload :Environment, 'bundler/environment'
+ autoload :Graph, 'bundler/graph'
autoload :Index, 'bundler/index'
autoload :Installer, 'bundler/installer'
+ autoload :LazySpecification, 'bundler/lazy_specification'
+ autoload :LockfileParser, 'bundler/lockfile_parser'
autoload :RemoteSpecification, 'bundler/remote_specification'
autoload :Resolver, 'bundler/resolver'
autoload :Runtime, 'bundler/runtime'
autoload :Settings, 'bundler/settings'
autoload :SharedHelpers, 'bundler/shared_helpers'
autoload :SpecSet, 'bundler/spec_set'
autoload :Source, 'bundler/source'
autoload :Specification, 'bundler/shared_helpers'
autoload :UI, 'bundler/ui'
- GEM_LOADED = true
- ORIGINAL_ENV = ENV.to_hash
-
class BundlerError < StandardError
def self.status_code(code = nil)
return @code unless code
@code = code
end
@@ -35,20 +37,34 @@
end
end
class GemfileNotFound < BundlerError; status_code(10) ; end
class GemNotFound < BundlerError; status_code(7) ; end
- class VersionConflict < BundlerError; status_code(6) ; end
class GemfileError < BundlerError; status_code(4) ; end
class GemfileChanged < GemfileError; status_code(4) ; end
class PathError < BundlerError; status_code(13) ; end
class GitError < BundlerError; status_code(11) ; end
class GemspecError < BundlerError; status_code(14) ; end
class DeprecatedMethod < BundlerError; status_code(12) ; end
class DeprecatedOption < BundlerError; status_code(12) ; end
+ class GemspecError < BundlerError; status_code(14) ; end
class InvalidOption < BundlerError; status_code(15) ; end
+ class VersionConflict < BundlerError
+ attr_reader :conflicts
+
+ def initialize(conflicts, msg = nil)
+ super(msg)
+ @conflicts = conflicts
+ end
+
+ status_code(6)
+ end
+
+ # Internal errors, should be rescued
+ class InvalidSpecSet < StandardError; end
+
class << self
attr_writer :ui, :bundle_path
def configure
@configured ||= begin
@@ -61,16 +77,24 @@
@ui ||= UI.new
end
def bundle_path
@bundle_path ||= begin
- path = settings[:path] || "#{Gem.user_home}/.bundle/#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}"
+ path = settings[:path] || Gem.dir
Pathname.new(path).expand_path(root)
end
end
- def gem_setup(*groups)
+ def bin_path
+ @bin_path ||= begin
+ path = settings[:bin] || "#{Gem.user_home}/.bundle/bin"
+ FileUtils.mkdir_p(path)
+ Pathname.new(path).expand_path
+ end
+ end
+
+ def setup(*groups)
return @setup if @setup
if groups.empty?
# Load all groups, but only once
@setup = load.setup
@@ -81,39 +105,30 @@
@completed_groups = groups | (@completed_groups || [])
# Load any groups that are not yet loaded
unloaded.any? ? load.setup(*unloaded) : load
end
end
- alias setup gem_setup unless defined?(Bundler::ENV_LOADED)
- def gem_require(*groups)
+ def require(*groups)
setup(*groups).require(*groups)
end
- alias require gem_require unless defined?(Bundler::ENV_LOADED)
def load
- @load ||= begin
- if !update_env_file?
- Kernel.require env_file
- Bundler
- else
- runtime
- end
- end
+ @load ||= Runtime.new(root, definition)
end
- def runtime
- @runtime ||= Runtime.new(root, definition)
+ def environment
+ Bundler::Environment.new(root, definition)
end
- def definition
- configure
- lockfile = root.join("Gemfile.lock")
- if lockfile.exist?
- Definition.from_lock(lockfile)
- else
- Definition.from_gemfile(default_gemfile)
+ def definition(unlock = nil)
+ @definition = nil if unlock
+ @definition ||= begin
+ configure
+ upgrade_lockfile
+ lockfile = root.join("Gemfile.lock")
+ Definition.build(default_gemfile, lockfile, unlock)
end
end
def home
bundle_path.join("bundler")
@@ -130,21 +145,25 @@
def cache
bundle_path.join("cache/bundler")
end
def root
- default_gemfile.dirname
+ default_gemfile.dirname.expand_path
end
- def settings
- @settings ||= Settings.new(root)
+ def app_cache
+ root.join("vendor/cache")
end
- def env_file
- SharedHelpers.env_file
+ def tmp
+ "#{Gem.user_home}/.bundler/tmp"
end
+ def settings
+ @settings ||= Settings.new(root)
+ end
+
def with_clean_env
bundled_env = ENV.to_hash
ENV.replace(ORIGINAL_ENV)
yield
ensure
@@ -153,10 +172,26 @@
def default_gemfile
SharedHelpers.default_gemfile
end
+ WINDOWS = Config::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
+ NULL = WINDOWS ? "NUL" : "/dev/null"
+
+ def requires_sudo?
+ case
+ when File.writable?(bundle_path) ||
+ `which sudo 2>#{NULL}`.empty? ||
+ File.owned?(bundle_path)
+ false
+ else
+ true
+ end
+ rescue Errno::ENOENT
+ false
+ end
+
private
def configure_gem_home_and_path
if settings[:disable_shared_gems]
ENV['GEM_PATH'] = ''
@@ -168,19 +203,30 @@
end
Gem.clear_paths
end
- def update_env_file?
- if env_file.exist?
- outdated = (env_file.read(100) !~ /Bundler #{Bundler::VERSION}/)
- writable = env_file.writable?
- if outdated && !writable
- STDERR.puts "Cannot write to outdated .bundle/environment.rb to update it"
- end
- outdated && writable
- else
- true
+ def upgrade_lockfile
+ lockfile = root.join("Gemfile.lock")
+ if lockfile.exist? && lockfile.read(3) == "---"
+ Bundler.ui.warn "Detected Gemfile.lock generated by 0.9, deleting..."
+ lockfile.rmtree
+ # lock = YAML.load_file(lockfile)
+ #
+ # source_uris = lock["sources"].map{|s| s["Rubygems"]["uri"] }
+ # sources = [Bundler::Source::Rubygems.new({"remotes" => source_uris})]
+ #
+ # deps = lock["dependencies"].map do |name, opts|
+ # version = opts.delete("version")
+ # Bundler::Dependency.new(name, version, opts)
+ # end
+ #
+ # definition = Bundler::Definition.new(nil, deps, sources, {})
+ #
+ # File.open(lockfile, 'w') do |f|
+ # f.write definition.to_lock
+ # end
end
end
+
end
end