-
Notifications
You must be signed in to change notification settings - Fork 92
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
[MSHADE-391] Do not write modified class files for no-op relocations #95
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work
thank you very much.
I wonder if you could try to add a test case in order to prevent regressions in the future
src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
Outdated
Show resolved
Hide resolved
Such a test would be heuristic, relying on whether ASM happens to restructure certain class files during transformation or not. It would also be an integration test with some real world dependencies and classes using them. Indirectly, we would be testing ASM rather than Shade, but the test is certainly doable. It would be more expensive to create than the actual change, though. |
Please also find the TODO in the diff and provide some feedback as to whether or not I should simplify the mapping method to an unparametrised one used by both callers. If so, I would rather inline it and chain the calls. |
src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
Outdated
Show resolved
Hide resolved
Sorry for the force-push, but I think my change was not worth a separate commit, which would still be visible after merging this (unless the person merging it squashes commits). |
I just added an integration test. Please review and execute. |
BTW, can anyone tell me why running a single IT by
does not work as expected? My test passes, but the setup job fails:
If I explicitly add
the build passes. That is not so nice, because it requires "sacred knowledge". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the test.
The patch looks great to me
+1
I am sorry I cannot help with the single run issue. For some plugjns I modify the pom.xml file in order to select only one single IT. I have never really worked on this plugin |
Also, rename method 'DefaultShader.shadeSingleJar' to 'shadeJarEntry' in order to reflect what it actually does: It does *not* shade a JAR but a JAR entry, i.e. not a "single JAR" but rather a single file.
Test src/it/projects/MSHADE-391_noRelocationKeepOriginalClasses shades two dependencies, relocating one of them. For the non-relocated one, it compares pre-calculated MD5 checksums to the actual ones in the uber JAR, making sure that they are identical. The test will fail in Maven Shade 3.2.4 or older, but pass with the changes made in MSHADE-391.
FYI, I rebased on master after #88 was merged. Otherwise no changes. |
… visitor to host the state in the visitor
Hi @kriegaex , as said last week I had a look to this and have multiple comments to do:
So overall, after some more advanced testing on small and "medium/big" (~50M) fatjars with relocations, I think it is good to just store the remapped flag in the remapper and have one instance per class jar entry. It avoids some verbosity we can try to avoid until we do a complete and adapted implementation (which would be way more than this PR tries to do IMHO). Wdyt? |
@rmannibucau: I showed you mine. If you show me yours, I can say more about it. Is it a PR on top of my PR or a reimplementation of it? I would not be sad to throw away mine, because the sole purpose of it is to fix the problem. If it just remains to be the trigger for you to fix it in a more elegant way, it still served its purpose. So how are we going to do this? Update: OK, I just noticed the link in your message and can see that your commit piggy-backs on mine. Going to take a look now. |
There was some suboptimal naming: We had class names - Relocator, - SimpleRelocator, - Relocators, - DefaultRelocators. That was a bit too much of '*Relocator(s)', and the plural was not nice either. We are actually dealing with one mapper (interface), the default implementation of which happens to own a list of relocators. We now have - Relocator, - SimpleRelocator, - PackageMapper, - DefaultPackageMapper. I also changed PackageMapper.map to have two boolean parameters now, even though the first one is always true in current use cases. But I wanted the method signature to more clearly describe what the boolean parameters do. Before there was just 'boolean clazz', which does not communicate anything to the caller. Now we have the method signature String map(String entityName, boolean mapPaths, boolean mapPackages) which is better in this respect. Also, 'entityName' is a clearer than just 'name'. Despite the interface being private, I also added Javadoc to this method, because it is a crucial one for understanding how class relocation and entity name mapping work. Test case DefaultShaderTest.testNoopWhenNotRelocated was refactored to be a bit more readable and also to explicitly test that the byte code for a relocated class has actually changed and not only its path within the uber JAR has been adjusted. I also renamed the helper method 'areEquals' to 'areEqual'.
@rmannibucau, I pushed both your commit and my refactoring of it to this PR, please review again. I hope you are OK with what I changed. The commit comment is quite extensive, if you want to read that first before looking at the diff. I am happy to collaborate with you in this way, that is so much better than a reviewer micro-managing the contributor to do exactly as he says. Taking turns and refining this together is great! I hope we can learn from each other. Do you think that this one is mergeable now? |
@eolivelli |
@Tibor17 no, go for it |
@kriegaex Pls squash these commits to one. We will include this PR in a release. Thx |
@Tibor17, I see no reason to squash the commits, because they are doing separate things. I see you use separate commits in one PR too, e.g. lately in Surefire, and I think small commits are a good practice. If ever you need to revert something, chances are that you can revert a single commit instead of a part of a big one. Bisecting bugs is easier, too. Furthermore, in this case there are two separate committers. Squashing everything into one commit would mean to disrespect other people's contribution and copyright. So I am not confident squasing @rmannibucau's commit into mine. The 4 commits do the following:
This code evolution and protocol of my collaboration with Romain should remain visible and traceable, IMO. If you insist, I can squash 1+2, but I would rather not. Not a big commit history is a problem, big commits are. |
Not sure it helps but personally I don't care at all if commits are squashed or not, it is up to the code writter to do it (I see it as a doc writer task). Also not having my name in "blame" is fine if you judge it is saner to squash commits. |
@kriegaex |
@Tibor17, that is not sound reasoning IMO. I completely disagree. Whether it is in a PR or not, later I might need to bisect when there is a problem. Smaller commits mean, it is easier to find bugs. The older a commit gets, the more important it becomes. So commits are more than just part of an iterative development process.
Seriously? That is your argument? Because there is one Jira issue, there must be a single commit? Sorry, I do not mean to disrespect you, but that is complete nonsense.
The opposite is true.
Again, I disagree. It helps understand where problems come from and also the opposite, i.e. why some things we would not understand without the history are not problems. Besides, you also want me to squash commits with non-intersecting lines of code. You know what? If you want to be the dictator micro-managing people, just squash the commits by yourself. I know you think you are always right and you have the power to merge, I don't. But that does not mean I need to always do what you demand. Merge as is or squash by yourself, if it is so important for you, or close the issue. I really don't care, the way you treat contributors like children both here and in Surefire. Edit: You are a competent developer, and I respect that. I cannot agree with your world view of how good software development should be done, though. I also cannot deal with the way you treat people. Sorry. |
@kriegaex |
Thanks for the merge, @Tibor17. Maybe next time you want to retain at least part of the squashed commit comments. |
Also, rename method
DefaultShader.shadeSingleJar
toshadeJarEntry
in order to reflect what it actually does: It does not shade a JAR but a JAR entry, i.e. not a "single JAR" but rather a single file.for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MSHADE-XXX] - Fixes bug in ApproximateQuantiles
,where you replace
MSHADE-XXX
with the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verify
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
mvn -Prun-its clean verify
).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.