Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
12 changes: 0 additions & 12 deletions rakelib/artifacts.rake
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,6 @@ namespace "artifact" do
@exclude_paths << 'vendor/**/gems/**/Gemfile.lock'
@exclude_paths << 'vendor/**/gems/**/Gemfile'

@exclude_paths << 'vendor/jruby/lib/ruby/gems/shared/gems/rake-*'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are no longer required as they are handled by the new plugin:clean-duplicate-gems task.

# exclude ruby-maven-libs 3.3.9 jars until JRuby ships with >= 3.8.9
@exclude_paths << 'vendor/bundle/jruby/**/gems/ruby-maven-libs-3.3.9/**/*'

# remove this after JRuby includes rexml 3.3.x
@exclude_paths << 'vendor/jruby/lib/ruby/gems/shared/gems/rexml-3.2.5/**/*'
@exclude_paths << 'vendor/jruby/lib/ruby/gems/shared/specifications/rexml-3.2.5.gemspec'

# remove this after JRuby includes net-imap-0.2.4+
@exclude_paths << 'vendor/jruby/lib/ruby/gems/shared/specifications/net-imap-0.2.3.gemspec'
@exclude_paths << 'vendor/jruby/lib/ruby/gems/shared/gems/net-imap-0.2.3/**/*'

@exclude_paths.freeze
end

Expand Down
53 changes: 53 additions & 0 deletions rakelib/plugin.rake
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,65 @@ namespace "plugin" do
task.reenable # Allow this task to be run again
end # task "install"


task "clean-duplicate-gems" do
shared_gems_path = File.join(LogStash::Environment::LOGSTASH_HOME,
'vendor/jruby/lib/ruby/gems/shared/gems')
default_gemspecs_path = File.join(LogStash::Environment::LOGSTASH_HOME,
'vendor/jruby/lib/ruby/gems/shared/specifications/default')
bundle_gems_path = File.join(LogStash::Environment::BUNDLE_DIR,
'jruby/*/gems')

# "bundled" gems in jruby
# https://github.com/jruby/jruby/blob/024123c29d73b672d50730117494f3e4336a0edb/lib/pom.rb#L108-L152
shared_gem_names = Dir.glob(File.join(shared_gems_path, '*')).map do |path|
match = File.basename(path).match(/^(.+?)-\d+/)
match ? match[1] : nil
end.compact

# "default" gems in jruby/ruby
# https://github.com/jruby/jruby/blob/024123c29d73b672d50730117494f3e4336a0edb/lib/pom.rb#L21-L106
default_gem_names = Dir.glob(File.join(default_gemspecs_path, '*.gemspec')).map do |path|
match = File.basename(path).match(/^(.+?)-\d+/)
match ? match[1] : nil
end.compact

# gems we explicitly manage with bundler (we always want these to take precedence)
bundle_gem_names = Dir.glob(File.join(bundle_gems_path, '*')).map do |path|
match = File.basename(path).match(/^(.+?)-\d+/)
match ? match[1] : nil
end.compact

shared_duplicates = shared_gem_names & bundle_gem_names
default_duplicates = default_gem_names & bundle_gem_names
all_duplicates = (shared_duplicates + default_duplicates).uniq

puts("[plugin:clean-duplicate-gems] Removing duplicate gems: #{all_duplicates.sort.join(', ')}")

# Remove shared/bundled gem duplicates
shared_duplicates.each do |gem_name|
FileUtils.rm_rf(Dir.glob("#{shared_gems_path}/#{gem_name}-*"))
FileUtils.rm_rf(Dir.glob("#{shared_gems_path}/../specifications/#{gem_name}-*.gemspec"))
end

# Remove default gem gemspecs only
default_duplicates.each do |gem_name|
# For stdlib default gems we only remove the gemspecs as removing the source code
# files results in code loading errors and ruby warnings
FileUtils.rm_rf(Dir.glob("#{default_gemspecs_path}/#{gem_name}-*.gemspec"))
end

task.reenable
end

task "install-default" => "bootstrap" do
puts("[plugin:install-default] Installing default plugins")

remove_lockfile # because we want to use the release lockfile
install_plugins("--no-verify", "--preserve", *LogStash::RakeLib::DEFAULT_PLUGINS)

# Clean duplicates after full gem resolution
Rake::Task["plugin:clean-duplicate-gems"].invoke
task.reenable # Allow this task to be run again
end

Expand Down
12 changes: 10 additions & 2 deletions rubyUtils.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ tasks.register("installCustomJRuby", Copy) {
dependsOn buildCustomJRuby
description = "Install custom built JRuby in the vendor directory"
inputs.file(customJRubyTar)
outputs.dir("${projectDir}/vendor/jruby")
// Don't re-extract if core JRuby is already installed. This works around
// gem deduplication when rake calls back in to gradle.
onlyIf {
!file("${projectDir}/vendor/jruby/bin/jruby").exists()
}
from tarTree(customJRubyTar == "" ? jrubyTarPath : customJRubyTar)
eachFile { f ->
f.path = f.path.replaceFirst("^jruby-${customJRubyVersion}", '')
Expand All @@ -294,7 +298,11 @@ tasks.register("downloadAndInstallJRuby", Copy) {
dependsOn=[verifyFile, installCustomJRuby]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COREREVIEW: why is there a dep on installCustomJRuby here?

description = "Install JRuby in the vendor directory"
inputs.file(jrubyTarPath)
outputs.dir("${projectDir}/vendor/jruby")
// Don't re-extract if core JRuby is already installed. This works around
// gem deduplication when rake calls back in to gradle.
onlyIf {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interplay between gradle/rake it is hard (IMO impossible) to define a sane dependency graph to ensure that gems are cleaned after jruby has been installed and bundler has been run. TO get around issues where gradle was being tricked in to thinking we need a fresh jruby install when gems have been cleaned up, only install jruby when the executable is not in the expected place. This is kind of a hack as i could see a workflow where this would cause an issue with an unexpectedly old or broken jruby but I cant think of a way around it without majorly refactoring how our gradle/rake tasks are organized.

!file("${projectDir}/vendor/jruby/bin/jruby").exists()
}
from tarTree(downloadJRuby.dest)
eachFile { f ->
f.path = f.path.replaceFirst("^jruby-${jRubyVersion}", '')
Expand Down