Skip to content

Conversation

@cbuschka
Copy link

@cbuschka cbuschka commented Aug 25, 2017

Added extra checks if a property has been generated by maven-git-commit-id-plugin before filtering. This fixes issue 310.

@cbuschka cbuschka force-pushed the issue_310_cbuschka_project_props_removed branch from 80d6691 to 4045457 Compare August 25, 2017 09:24
@cbuschka cbuschka force-pushed the issue_310_cbuschka_project_props_removed branch from 4045457 to 993f265 Compare August 25, 2017 09:25
@TheSnoozer
Copy link
Collaborator

TheSnoozer commented Aug 25, 2017

Hi thank you for reporting the issue and creating a pull request!
This is indeed kinda ugly....I'm just thinking if there would be other things effected when using the outlined scenario...for example in the latest version of the plugin we have an option to replace properties...however using the outlined scenario the replacement of properties would work differently and thus the question raises why we even use different property sets inside initProperties() see
https://github.com/ktoso/maven-git-commit-id-plugin/blame/master/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java#L538.

The PR looks ok, but I'll definitely need to look into that further to check if other items of the plugin would be affected by this as well. Also would be nice to have a testcase for this since it is something more critical ;-)

@cbuschka
Copy link
Author

Yes you are right I will create a unit test for.

@cbuschka
Copy link
Author

cbuschka commented Aug 25, 2017

Ok, I moved the filtering into a collaborator (PropertiesFilterer) and added a unit test. This solves the issue and adds test coverage.

Additionally we could do a refactoring related to working on the project properties. We could change initProperties() to always return a new Properties instance, generate the properties, do the replacement, filtering etc. and "publish" the result into the project properties as it is already done in https://github.com/ktoso/maven-git-commit-id-plugin/blame/master/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java#L383 . What do you think about that change?

@TheSnoozer
Copy link
Collaborator

Thanks for the test cases!
Yes, fully agree! The properties = initProperties(); should rather be always properties = new Properties().

It seems that the project.getProperties().putAll(properties); here https://github.com/ktoso/maven-git-commit-id-plugin/blob/master/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java#L383 is independent from the generateGitPropertiesFile switch.
Currently the initProperties get the mavenProject-properties when generateGitPropertiesFile=false
and if generateGitPropertiesFile=true the properties are being attached with the project.getProperties().putAll(properties); outlined above.

Please add the refactoring and I'll pull in the changes....
Thanks again for reporting and creating a PR :-)

@cbuschka
Copy link
Author

Moved replacement code into PropertiesReplacer with own test and added the refactoring described above. The refactoring changes behaviour! What is the intend behind the properties replacement? Should it be performed on project wide properties?

@TheSnoozer
Copy link
Collaborator

TheSnoozer commented Aug 26, 2017

Actually its a really good question on what properties the replacement should perform. The initial intent comes from here #138. In a nutshell a branch has a name like "feature/feature_name" and someone wanted to use the branch-name in the finalName of the artifact. However the character "/" is not valid as filename and thus this would not work.

Based on what I wrote inside the docs (1e8b523) the replacement can be used to replace certain characters or strings using regular expressions within the generated git properties. I even added the following note Please note that the replacement will *only be applied to properties that are being generated by the plugin....

I would say at the time being it is sufficient to have the replacement only work on the properties generated by the plugin (that is pretty much what the readme says about the functionality).

Just for reference:
We either can adjust the way it works (it requested with a string reason) or the user can use
https://code.google.com/archive/p/maven-replacer-plugin/ which is pretty much the same but for all properties.

TLDR

All changes look good to me!
Thanks for the code cleanup and the changes!
I will pull in the changes since the replacement should currently only work on properties generated by the plugin (was not released yet, so no one can claim it ever worked differently :-P)

@TheSnoozer TheSnoozer merged commit c2d2061 into git-commit-id:master Aug 26, 2017
@TheSnoozer TheSnoozer added the bug label Aug 26, 2017
@cbuschka
Copy link
Author

Thanks for merging! I am glad I could contribute and give something back in return.

@cbuschka cbuschka deleted the issue_310_cbuschka_project_props_removed branch August 26, 2017 15:05
@ktoso
Copy link
Collaborator

ktoso commented Aug 28, 2017

Thanks @cbuschka !

This is now released as 2.2.3, have fun! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants