Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for The bundle currently has logstash-xxx-yyy locked at N when doing offline plugin install #10016

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/pluginmanager/bundler/logstash_injector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def inject(gemfile_path, lockfile_path, dependencies)
gemfile.update(dependency.name, dependency.requirement)
end
end
builder.eval_gemfile("bundler file", gemfile.generate_without_groups(:build, :development))
definition = builder.to_definition(lockfile_path, true)

builder.eval_gemfile("bundler file", gemfile.generate())
definition = builder.to_definition(lockfile_path, {})
definition.lock(lockfile_path)
gemfile.save
rescue => e
Expand Down
30 changes: 29 additions & 1 deletion lib/pluginmanager/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def generate
"#{HEADER}#{gemset.to_s}"
end

def generate_without_groups(*groups)
result = HEADER.dup
gemset.without_groups(groups) do |gs|
result << gs.to_s
end
result
end

def find(name)
@gemset.find_gem(name)
end
Expand Down Expand Up @@ -96,6 +104,15 @@ def initialize
@gems = [] # list of Gem class
@gems_by_name = {} # hash of name => Gem
@gemspec = {} # gemspec is a options hash
@exclude_groups = []
end

def without_groups(groups)
old_exclude_groups = @exclude_groups
@exclude_groups = groups
yield self
ensure
@exclude_groups = old_exclude_groups
end

def to_s
Expand Down Expand Up @@ -169,13 +186,24 @@ def sources_to_s

def gems_to_s
return "" if @gems.empty?
@gems.map do |gem|
group_excluded_gems.map do |gem|
requirements = gem.requirements.empty? ? nil : gem.requirements.map{|r| r.inspect}.join(", ")
options = gem.options.empty? ? nil : gem.options.map{|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
"gem " + [gem.name.inspect, requirements, options].compact.join(", ")
end.join("\n")
end

def group_excluded_gems
return @gems if @exclude_groups.empty?
@gems.reject{|pg| group_excluded?(pg) }
end

def group_excluded?(parsed_gem)
# typical options: :group => :development
return false if parsed_gem.options.empty?
@exclude_groups.include?(parsed_gem.options[:group])
end

def gemspec_to_s
return "" if @gemspec.empty?
options = @gemspec.map{|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/plugin_manager/gemfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,34 @@
)
end
end

context "generation" do
it "generate" do
file = <<-END
gem "foo", "> 1.0", :b => "b"
gem "bar", "> 2.0", "< 3.0", :c => "c", :d => "d"
END

gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
as_string = gemfile.generate
expect(as_string).to include('gem "foo", "> 1.0", :b => "b"')
expect(as_string).to include('gem "bar", "> 2.0", "< 3.0", :c => "c", :d => "d"')
end

it "generate_without_groups" do
file = <<-END
gem "foo", "> 1.0", :b => "b"
gem "bar", "> 2.0", "< 3.0", :group => :fancy
gem "baz", "> 2.0", "< 3.0", :group => :pants
END

gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
as_string = gemfile.generate_without_groups(:fancy, :pants)
expect(as_string).to include('gem "foo", "> 1.0", :b => "b"')
expect(as_string).not_to include('gem "bar", "> 2.0", "< 3.0", :group => :fancy')
expect(as_string).not_to include('gem "baz", "> 2.0", "< 3.0", :group => :pants')
end
end
end

context LogStash::DSL do
Expand Down