lib/bundler/definition.rb in bundler-1.9.10 vs lib/bundler/definition.rb in bundler-1.10.0.pre
- old
+ new
@@ -41,23 +41,25 @@
# @param dependencies [Array(Bundler::Dependency)] array of dependencies from Gemfile
# @param sources [Bundler::SourceList]
# @param unlock [Hash, Boolean, nil] Gems that have been requested
# to be updated or true if all gems should be updated
# @param ruby_version [Bundler::RubyVersion, nil] Requested Ruby Version
- def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil)
+ # @param optional_groups [Array(String)] A list of optional groups
+ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, optional_groups = [])
@unlocking = unlock == true || !unlock.empty?
- @dependencies, @sources, @unlock = dependencies, sources, unlock
+ @dependencies, @sources, @unlock, @optional_groups = dependencies, sources, unlock, optional_groups
@remote = false
@specs = nil
@lockfile_contents = ""
@ruby_version = ruby_version
if lockfile && File.exist?(lockfile)
@lockfile_contents = Bundler.read_file(lockfile)
locked = LockfileParser.new(@lockfile_contents)
@platforms = locked.platforms
+ @locked_bundler_version = locked.bundler_version
if unlock != true
@locked_deps = locked.dependencies
@locked_specs = SpecSet.new(locked.specs)
@locked_sources = locked.sources
@@ -159,11 +161,11 @@
missing
end
def requested_specs
@requested_specs ||= begin
- groups = self.groups - Bundler.settings.without
+ groups = requested_groups
groups.map! { |g| g.to_sym }
specs_for(groups)
end
end
@@ -253,10 +255,20 @@
"There was an error while trying to write to Gemfile.lock. It is likely that \n" \
"you need to allow write permissions for the file at path: \n" \
"#{File.expand_path(file)}"
end
+ # Returns the version of Bundler that is creating or has created
+ # Gemfile.lock. Used in #to_lock.
+ def lock_version
+ if @locked_bundler_version && @locked_bundler_version < Gem::Version.new(Bundler::VERSION)
+ new_version = Bundler::VERSION
+ end
+
+ new_version || @locked_bundler_version || Bundler::VERSION
+ end
+
def to_lock
out = ""
sources.lock_sources.each do |source|
# Add the source header
@@ -291,13 +303,13 @@
next if handled.include?(dep.name)
out << dep.to_lock
handled << dep.name
end
- if @lockfile_contents =~ /^BUNDLED WITH[\r]?\n(\s{2,}#{Gem::Version::VERSION_PATTERN})[\r]?\n\Z/
- out << "\nBUNDLED WITH\n" << $1 << "\n"
- end
+ # Record the version of Bundler that was used to create the lockfile
+ out << "\nBUNDLED WITH\n"
+ out << " #{lock_version}\n"
out
end
def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
@@ -592,11 +604,11 @@
end
deps
end
def requested_dependencies
- groups = self.groups - Bundler.settings.without
+ groups = requested_groups
groups.map! { |g| g.to_sym }
dependencies.reject { |d| !d.should_include? || (d.groups & groups).empty? }
end
def source_requirements
@@ -626,7 +638,10 @@
end
names.uniq!
names
end
+ def requested_groups
+ self.groups - Bundler.settings.without - @optional_groups + Bundler.settings.with
+ end
end
end