-
-
Notifications
You must be signed in to change notification settings - Fork 305
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
Includeresource duplicate strategy to append to existing file when unrolling jar #6326
Includeresource duplicate strategy to append to existing file when unrolling jar #6326
Conversation
20a2822
to
7c6bb03
Compare
@pkriens one thing I am thinking about and would like to discuss is, wether or not we shoud add a way to enforce a
a line break is not required, since the first file ends with one. One option would be another strategy in addition to APPEND.
|
You are becoming the Elon Musk of bnd :-) Nice productivity. Some comments.
|
Your approach sounds good and more flexible.
I recognize a pattern here. I am always one level too deep 🤣
What about the existing method with the This was the main reason why I have put it here. But since it is public, we have to keep it anyway.
Are you talking plugin as in ? Ok I will try to digest your ideas and see what I can do. |
No, sometimes multiple levels 😎 When I was younger you had "structured design", DeMarco, Michael Jackson, Yourdan, etc. They were talking about coupling and cohesion. Did not get the cohesion until a few years ago but I think it is paramount. I try to write software based on reusable components. So each component must do one thing and one thing only otherwise reuse becomes hard. So I now strife to create classes and methods that do one thing. Very useful in there is not not do control (if/then/switch/case) and actual work in the same method. Anyway, in bnd it is relatively straightforward. Whenever there is choice, it should be in a processor. Things like JAR, Resource, Parameters, etc. are reusable and should just do their work and not take decisions. |
Few questions @pkriens :
I ask because I have things setup so far (not pushed), but not sure how simple or complex the "plugin"-mechanism should be. |
226d669
to
5df7631
Compare
@pkriens I pushed the first prototype of this approach. Example: dup_merge AND dup_warning combined:
Warnings are displayed (TODO for me: the message is not correct. the word "overwritten" should not appear when same file is also affected by dup_merge in effect: line break added in META-INF/services files but other files outside META-INF/services will be just appended (without line break). This part is what I would like to discuss: I have created two MergeFiles plugins and iterate over them via
But that does not feel right, because the order of the plugins is important.
|
Meeting notesFrom meeting with @pkriens today. These are just loose notes so I don't forget. I will cleanup later. Duplicate-Strategy:
Example: duplicate:="MERGE,metainfservices" duplicate:="MERGE" - means all merge plugins will be called plugin = tags | enum |
@pkriens I think I implemented what we have talked about today. I updated the PR description above One thing though I noticed during the bnd build locally is this output of the new warning we added when duplicate files overwrite eachother and no duplicate strategy is defined. I am not sure this output below is intended. Nor do I know exactly where it is coming from. a) we haven't thought about all side effects of adding a warning (and may remove it again)
|
Meeting Notes: enum ::= WARN, ERROR, MERGE, SKIP, OVERWRITE MERGE, SKIP, OVERWRITE -> exclusive onduplicate:='MERGE'
onduplicate:='MERGE,metainfservices'
onduplicate:='SKIP,metainfservices'
onduplicate:='metainfservices' (basically no enum, just a tag)
onduplicate:='INVALIDENUM,metainfservices'
onduplicate:='metainfservices,MERGE,SKIP' |
I took a look at the code. It is not bad but I think it can be done more readable. The logic when what happens is complex and it is not clear in the code. I came up with the following class (well record) that could help. It is a bit pedantic so you can probably convince me to go with your code but this is the way I would handle the core logic. (The MergeResources is copied for convenience.)
|
You can call the method doDuplicate with the directive content. This gives you back a function you can call when there is a duplicate. Advantage is that the errors are reported early and no unnecessary work is done. |
Thanks a lot @pkriens I started adding your implementation. I think I need to clarify again: What should e.g. happen with a duplicate for:
Should it Basically it could be summarized: I think you implemented a) and I kept that now and modified the testcases accordingly. Also your version did not have the default handling (backwards compatibility, meaning no :onduplicate directive) with the additional warning if resources are not identical. I added that. If the implementation as it is right now is ok and the testcases make sense, then I would say this is ready. |
1153f90
to
22f0052
Compare
- add onduplicate: directive for -includeresource which allows to OVERWRITE, MERGE, SKIP, WARN, ERROR when duplicate files are unrolled to a target jar Signed-off-by: Christoph Rueger <[email protected]>
Signed-off-by: Christoph Rueger <[email protected]>
eabdeec
to
a63330e
Compare
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.
LGTM except for the public record.
Signed-off-by: Christoph Rueger <[email protected]>
Closes #6325
Adds a duplicate strategy to
-includeresource
(similar to:flatten
or:rename
)onduplicate:=MERGE
onduplicate:='MERGE,sometag'
onduplicate:='MERGE,metainfservices'
onduplicate:=SKIP
onduplicate:=WARN
onduplicate:=ERROR
e.g.
The
MERGE
strategy:MergeFile
interface)MetaInfServiceMerger.java
which can handle theMETA-INF/services
path and append duplicate service files with a line-breakMERGE
has no effect.Another example using WARN
@pkriens This is the latest based on the discussion today (2024/10/29)