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 relocation for ComponentsXmlResourceTransformer #678

Merged
merged 1 commit into from
Aug 1, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package com.github.jengelman.gradle.plugins.shadow.transformers

import com.github.jengelman.gradle.plugins.shadow.ShadowStats
import com.github.jengelman.gradle.plugins.shadow.relocation.RelocateClassContext
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
import org.apache.tools.zip.ZipEntry
import org.apache.tools.zip.ZipOutputStream
Expand Down Expand Up @@ -77,13 +79,13 @@ class ComponentsXmlResourceTransformer implements Transformer {
Xpp3Dom component = children[i]

String role = getValue(component, "role")
role = getRelocatedClass(role, context.relocators)
role = getRelocatedClass(role, context)
setValue(component, "role", role)

String roleHint = getValue(component, "role-hint")

String impl = getValue(component, "implementation")
impl = getRelocatedClass(impl, context.relocators)
impl = getRelocatedClass(impl, context)
setValue(component, "implementation", impl)

String key = role + ':' + roleHint
Expand All @@ -103,7 +105,7 @@ class ComponentsXmlResourceTransformer implements Transformer {
Xpp3Dom requirement = requirements.getChild(r)

String requiredRole = getValue(requirement, "role")
requiredRole = getRelocatedClass(requiredRole, context.relocators)
requiredRole = getRelocatedClass(requiredRole, context)
setValue(requirement, "role", requiredRole)
}
}
Expand Down Expand Up @@ -154,11 +156,14 @@ class ComponentsXmlResourceTransformer implements Transformer {
return baos.toByteArray()
}

private String getRelocatedClass(String className, List<Relocator> relocators) {
private static String getRelocatedClass(String className, TransformerContext context) {
List<Relocator> relocators = context.relocators
ShadowStats stats = context.stats
if (className != null && className.length() > 0 && relocators != null) {
for (Relocator relocator : relocators) {
if (relocator.canRelocateClass(className)) {
return relocator.relocateClass(className)
RelocateClassContext relocateClassContext = new RelocateClassContext(className, stats)
return relocator.relocateClass(relocateClassContext)
}
}
}
Expand Down