Class: Bundler::LockfileParser
- Inherits:
-
Object
- Object
- Bundler::LockfileParser
- Defined in:
- lib/bundler/lockfile_parser.rb
Defined Under Namespace
Classes: Position
Constant Summary collapse
- BUNDLED =
"BUNDLED WITH"
- DEPENDENCIES =
"DEPENDENCIES"
- CHECKSUMS =
"CHECKSUMS"
- PLATFORMS =
"PLATFORMS"
- RUBY =
"RUBY VERSION"
- GIT =
"GIT"
- GEM =
"GEM"
- PATH =
"PATH"
- PLUGIN =
"PLUGIN SOURCE"
- SPECS =
" specs:"
- OPTIONS =
/^ ([a-z]+): (.*)$/i
- SOURCE =
[GIT, GEM, PATH, PLUGIN].freeze
- SECTIONS_BY_VERSION_INTRODUCED =
{ Gem::Version.create("1.0") => [DEPENDENCIES, PLATFORMS, GIT, GEM, PATH].freeze, Gem::Version.create("1.10") => [BUNDLED].freeze, Gem::Version.create("1.12") => [RUBY].freeze, Gem::Version.create("1.13") => [PLUGIN].freeze, Gem::Version.create("2.5.0") => [CHECKSUMS].freeze, }.freeze
- KNOWN_SECTIONS =
SECTIONS_BY_VERSION_INTRODUCED.values.flatten!.freeze
- ENVIRONMENT_VERSION_SECTIONS =
[BUNDLED, RUBY].freeze
Instance Attribute Summary collapse
-
#bundler_version ⇒ Object
readonly
Returns the value of attribute bundler_version.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#most_specific_locked_platform ⇒ Object
readonly
Returns the value of attribute most_specific_locked_platform.
-
#platforms ⇒ Object
readonly
Returns the value of attribute platforms.
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
Class Method Summary collapse
- .bundled_with ⇒ Object
- .sections_in_lockfile(lockfile_contents) ⇒ Object
- .sections_to_ignore(base_version = nil) ⇒ Object
- .unknown_sections_in_lockfile(lockfile_contents) ⇒ Object
Instance Method Summary collapse
-
#initialize(lockfile, strict: false) ⇒ LockfileParser
constructor
A new instance of LockfileParser.
- #may_include_redundant_platform_specific_gems? ⇒ Boolean
Constructor Details
#initialize(lockfile, strict: false) ⇒ LockfileParser
Returns a new instance of LockfileParser.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/bundler/lockfile_parser.rb', line 97 def initialize(lockfile, strict: false) @platforms = [] @sources = [] @dependencies = {} @parse_method = nil @specs = {} @lockfile_path = begin SharedHelpers.relative_lockfile_path rescue GemfileNotFound "Gemfile.lock" end @pos = Position.new(1, 1) @strict = strict if lockfile.match?(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/) raise LockfileError, "Your #{@lockfile_path} contains merge conflicts.\n" \ "Run `git checkout HEAD -- #{@lockfile_path}` first to get a clean lock." end lockfile.split(/((?:\r?\n)+)/) do |line| # split alternates between the line and the following whitespace next @pos.advance!(line) if line.match?(/^\s*$/) if SOURCE.include?(line) @parse_method = :parse_source parse_source(line) elsif line == DEPENDENCIES @parse_method = :parse_dependency elsif line == CHECKSUMS # This is a temporary solution to make this feature disabled by default # for all gemfiles that don't already explicitly include the feature. @checksums = true @parse_method = :parse_checksum elsif line == PLATFORMS @parse_method = :parse_platform elsif line == RUBY @parse_method = :parse_ruby elsif line == BUNDLED @parse_method = :parse_bundled_with elsif /^[^\s]/.match?(line) @parse_method = nil elsif @parse_method send(@parse_method, line) end @pos.advance!(line) end if !Bundler.frozen_bundle? && @platforms.include?(Gem::Platform::X64_MINGW_LEGACY) if @platforms.include?(Gem::Platform::X64_MINGW) @platforms.delete(Gem::Platform::X64_MINGW_LEGACY) SharedHelpers.major_deprecation(2, "Found x64-mingw32 in lockfile, which is deprecated. Removing it. Support for x64-mingw32 will be removed in Bundler 4.0.", removed_message: "Found x64-mingw32 in lockfile, which is no longer supported as of Bundler 4.0.") else @platforms[@platforms.index(Gem::Platform::X64_MINGW_LEGACY)] = Gem::Platform::X64_MINGW SharedHelpers.major_deprecation(2, "Found x64-mingw32 in lockfile, which is deprecated. Using x64-mingw-ucrt, the replacement for x64-mingw32 in modern rubies, instead. Support for x64-mingw32 will be removed in Bundler 4.0.", removed_message: "Found x64-mingw32 in lockfile, which is no longer supported as of Bundler 4.0.") end end @most_specific_locked_platform = @platforms.min_by do |bundle_platform| Gem::Platform.platform_specificity_match(bundle_platform, Bundler.local_platform) end @specs = @specs.values.sort_by!(&:full_name).each do |spec| spec.most_specific_locked_platform = @most_specific_locked_platform end rescue ArgumentError => e Bundler.ui.debug(e) raise LockfileError, "Your lockfile is unreadable. Run `rm #{@lockfile_path}` " \ "and then `bundle install` to generate a new lockfile. The error occurred while " \ "evaluating #{@lockfile_path}:#{@pos}" end |
Instance Attribute Details
#bundler_version ⇒ Object (readonly)
Returns the value of attribute bundler_version.
29 30 31 |
# File 'lib/bundler/lockfile_parser.rb', line 29 def bundler_version @bundler_version end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
29 30 31 |
# File 'lib/bundler/lockfile_parser.rb', line 29 def dependencies @dependencies end |
#most_specific_locked_platform ⇒ Object (readonly)
Returns the value of attribute most_specific_locked_platform.
29 30 31 |
# File 'lib/bundler/lockfile_parser.rb', line 29 def most_specific_locked_platform @most_specific_locked_platform end |
#platforms ⇒ Object (readonly)
Returns the value of attribute platforms.
29 30 31 |
# File 'lib/bundler/lockfile_parser.rb', line 29 def platforms @platforms end |
#ruby_version ⇒ Object (readonly)
Returns the value of attribute ruby_version.
29 30 31 |
# File 'lib/bundler/lockfile_parser.rb', line 29 def ruby_version @ruby_version end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
29 30 31 |
# File 'lib/bundler/lockfile_parser.rb', line 29 def sources @sources end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
29 30 31 |
# File 'lib/bundler/lockfile_parser.rb', line 29 def specs @specs end |
Class Method Details
.bundled_with ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/bundler/lockfile_parser.rb', line 87 def self.bundled_with lockfile = Bundler.default_lockfile return unless lockfile.file? lockfile_contents = Bundler.read_file(lockfile) return unless lockfile_contents.include?(BUNDLED) lockfile_contents.split(BUNDLED).last.strip end |
.sections_in_lockfile(lockfile_contents) ⇒ Object
66 67 68 69 70 |
# File 'lib/bundler/lockfile_parser.rb', line 66 def self.sections_in_lockfile(lockfile_contents) sections = lockfile_contents.scan(/^\w[\w ]*$/) sections.uniq! sections end |
.sections_to_ignore(base_version = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bundler/lockfile_parser.rb', line 76 def self.sections_to_ignore(base_version = nil) base_version &&= base_version.release base_version ||= Gem::Version.create("1.0") attributes = [] SECTIONS_BY_VERSION_INTRODUCED.each do |version, introduced| next if version <= base_version attributes += introduced end attributes end |
.unknown_sections_in_lockfile(lockfile_contents) ⇒ Object
72 73 74 |
# File 'lib/bundler/lockfile_parser.rb', line 72 def self.unknown_sections_in_lockfile(lockfile_contents) sections_in_lockfile(lockfile_contents) - KNOWN_SECTIONS end |
Instance Method Details
#may_include_redundant_platform_specific_gems? ⇒ Boolean
171 172 173 |
# File 'lib/bundler/lockfile_parser.rb', line 171 def may_include_redundant_platform_specific_gems? bundler_version.nil? || bundler_version < Gem::Version.new("1.16.2") end |