Skip to content
Merged
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: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ The Java client and its dependencies are bundled as a single shaded JAR under `l
`lib/ext/rabbitmq-client-netty-shaded.jar` is a shaded uber-JAR, produced by `mvn package`
via the Maven Shade plugin (see `pom.xml`). It bundles the RabbitMQ Java client with all
Netty modules. Netty classes are relocated from `io.netty.*` to
`com.rabbitmq.marchhare.shaded.netty.*`, so another JRuby gem's own Netty version
`com.rabbitmq.marchhare.shaded.io.netty.*`, so another JRuby gem's own Netty version
(Logstash plugins, for example) cannot conflict with March Hare's.
Keep `io.netty` in the relocated package name: Netty's native library loader only
supports adding a prefix to the original package.

The SLF4J JARs (`slf4j-api.jar` and `slf4j-simple.jar`) are not shaded and stay separate,
so the RabbitMQ client's logging goes through whatever SLF4J backend the application uses.
Expand Down
Binary file modified lib/ext/rabbitmq-client-netty-shaded.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/march_hare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Single shaded JAR bundling the RabbitMQ Java client together with all Netty
# dependencies. Netty classes are relocated from io.netty.* to
# com.rabbitmq.marchhare.shaded.netty.* so they cannot conflict with other gems
# com.rabbitmq.marchhare.shaded.io.netty.* so they cannot conflict with other gems
# (e.g. Logstash plugins) that bundle a different Netty version on the same JVM.
require 'ext/rabbitmq-client-netty-shaded'

Expand Down
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@
Relocate every io.netty class to a private package so that other gems
bundling a different Netty version do not clash with ours.
The RabbitMQ client's internal references are rewritten automatically.
Keep the original io.netty package intact: Netty's native library
loader supports prepending a namespace, but not replacing the
original package.
-->
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>com.rabbitmq.marchhare.shaded.netty</shadedPattern>
<shadedPattern>com.rabbitmq.marchhare.shaded.io.netty</shadedPattern>
</relocation>
</relocations>

Expand Down
19 changes: 19 additions & 0 deletions spec/java_dependencies_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
RSpec.describe "Shaded Netty dependencies" do
it "preserves the package suffix required by Netty's native library loader" do
jar = java.util.jar.JarFile.new(File.expand_path("../lib/ext/rabbitmq-client-netty-shaded.jar", __dir__))
begin
loader_entry = jar.entries.to_a.map(&:name).find do |name|
name.end_with?("/netty/util/internal/NativeLibraryLoader.class")
end
ensure
jar.close
end

expect(loader_entry).not_to be_nil
loader = JavaUtilities.get_proxy_class(loader_entry.delete_suffix(".class").tr("/", "."))
# Exercise the prefix check without requiring a platform-specific native library
prefix_method = loader.java_class.declared_method("calculateMangledPackagePrefix")
prefix_method.accessible = true
expect(prefix_method.invoke_static).to eq("com_rabbitmq_marchhare_shaded_")
end
end
Loading