From 031a0b1404af3e053430bcf5134b779517b5906a Mon Sep 17 00:00:00 2001 From: Alessandro Patti Date: Fri, 16 Dec 2022 16:24:20 +0100 Subject: [PATCH] Do not remap inner class names --- .../main/java/com/eed3si9n/jarjar/PackageRemapper.java | 10 ++++++++++ .../java/com/eed3si9n/jarjar/PackageRemapperTest.java | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/jarjar/src/main/java/com/eed3si9n/jarjar/PackageRemapper.java b/jarjar/src/main/java/com/eed3si9n/jarjar/PackageRemapper.java index eaaccaef..3af7081b 100644 --- a/jarjar/src/main/java/com/eed3si9n/jarjar/PackageRemapper.java +++ b/jarjar/src/main/java/com/eed3si9n/jarjar/PackageRemapper.java @@ -117,6 +117,16 @@ public Object mapValue(Object value) { } } + @Override + public String mapInnerClassName( + final String name, final String ownerName, final String innerName) { + // The default method would try to be smart and find the inner class name + // by looking at the $ sign. As the documentation calls out, this works in java + // but not necessarily in other languages, including scala, where $ has multiple applications. + // Since we actually don't care about remapping class names, only packages, we can ignore this + return innerName; + } + private String replaceHelper(String value) { for (Wildcard wildcard : wildcards) { String test = wildcard.replace(value); diff --git a/jarjar/src/test/java/com/eed3si9n/jarjar/PackageRemapperTest.java b/jarjar/src/test/java/com/eed3si9n/jarjar/PackageRemapperTest.java index d2cfb0be..65e6612d 100644 --- a/jarjar/src/test/java/com/eed3si9n/jarjar/PackageRemapperTest.java +++ b/jarjar/src/test/java/com/eed3si9n/jarjar/PackageRemapperTest.java @@ -61,6 +61,13 @@ public void testMapValue() { assertEquals("foo/example.package-info", remapper.mapValue("org/example.package-info")); } + @Test + public void testUnchangedInnerClassNames() { + String outer = "scala.collection.immutable.IntMap"; + String inner = "Nil$"; + assertEquals(inner, remapper.mapInnerClassName(outer + "$" + inner, outer, inner)); + } + private void assertUnchangedValue(String value) { assertEquals(value, remapper.mapValue(value)); }