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

Add a getter on ShadowCopyAction.ArchiveFileTreeElement to access the containing jar file name #913

Open
uhyonc opened this issue Mar 23, 2024 · 2 comments

Comments

@uhyonc
Copy link

uhyonc commented Mar 23, 2024

Shadow Version

8.1.1

Gradle Version

7.5.3

Expected Behavior

Transformers should allow access to the Jar file path containing the FileTreeElement.
This is for implementing the method:
boolean canTransformResource(FileTreeElement element)
For example, I would like to be able to do something like

class MyTransformer implements Transformer {
    boolean canTransformResource(FileTreeElement element) {
        if (element instanceof com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction.ArchiveFileTreeElement
            && element.classFile && element.jarFile.path.contains('grpc-core-1.19.0.jar')) {
            return false
        }
        return true 
    }
   ...
}

This is useful for allowing us custom mechanisms to override which classes to be used (e.g. when multiple dependencies have the same class files in it...).

Actual Behavior

ShadowCopyAction.ArchiveFileTreeElement is the actual implementation class passed as the element. However, this does not have any information on the containing jar file.

Gradle Build Script(s)

Content of Shadow JAR (jar tf <jar file> - post link to GIST if too long)

@uhyonc uhyonc closed this as completed Mar 23, 2024
@uhyonc uhyonc reopened this Mar 23, 2024
@uhyonc
Copy link
Author

uhyonc commented Mar 23, 2024

In fact, another issue is that ".class" files are not getting transformed... Actually I don't necessarily want it to be transformed, just a way to define the policy for which dependency gets priority when there are class file conflicts.

@uhyonc
Copy link
Author

uhyonc commented Mar 23, 2024

A similar request for Relocator as well... e.g. RelocatePathContext / RelocateClassContext should hold information about the dependency and/or the jar file it came from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant