Skip to content

Commit

Permalink
Add the ability to rename annotations added by the Scala compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
shawjef3 committed Feb 15, 2022
1 parent 24c371c commit 2fc3c2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import com.github.jengelman.gradle.plugins.shadow.relocation.RelocatePathContext
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction.RelativeArchivePath
import org.objectweb.asm.commons.Remapper
import scala.Function1
import scala.Option
import scala.jdk.FunctionWrappers

import java.util.regex.Matcher
import java.util.regex.Pattern
Expand All @@ -40,10 +43,18 @@ class RelocatorRemapper extends Remapper {

List<Relocator> relocators
ShadowStats stats
Function1<String, Option<String>> scalaRenamer

RelocatorRemapper(List<Relocator> relocators, ShadowStats stats) {
this.relocators = relocators
this.stats = stats
this.scalaRenamer =
new FunctionWrappers.FromJavaFunction(
(String string) -> {
Optional<Relocator> maybe = relocators.stream().filter(x -> x.canRelocateClass(string)).findAny()
Option.apply(maybe.map(it.relocateClass(new RelocateClassContext(string, stats))).orElse(null))
}
)
}

boolean hasRelocators() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.jengelman.gradle.plugins.shadow.tasks

import com.eed3si9n.jarjarabrams.scalasig.ScalaSigClassVisitor
import com.github.jengelman.gradle.plugins.shadow.ShadowStats
import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
import com.github.jengelman.gradle.plugins.shadow.internal.GradleVersionUtil
Expand Down Expand Up @@ -348,7 +349,7 @@ class ShadowCopyAction implements CopyAction {
// that use the constant pool to determine the dependencies of a class.
ClassWriter cw = new ClassWriter(0)

ClassVisitor cv = new ClassRemapper(cw, remapper)
ClassVisitor cv = new ScalaSigClassVisitor(new ClassRemapper(cw, remapper), remapper.scalaRenamer)

try {
cr.accept(cv, ClassReader.EXPAND_FRAMES)
Expand Down

0 comments on commit 2fc3c2c

Please sign in to comment.