-
Notifications
You must be signed in to change notification settings - Fork 69
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
Reformat the templates for Kotlin model code #310
Conversation
MariusVolkhart
commented
Jan 7, 2024
- Change import statements to not have an indent. No functional change.
- Remove unused imports. These were likely copied over from the Java template, but are not needed in Kotlin.
- Dynamic methods, which generate a map, now use Kotlin's buildMap() instead of mapOf(). mapOf() produces extra garbage, as it creates a Pair for each entry, whereas buildMap() modifies the underlying map directly.
- Static methods are now defined as an expression. No functional change.
- In static methods, the template class name is no longer fully qualified, as it's provided as an import. No functional change.
- Remove semicolons - idiomatic Kotlin doesn't use them. No functional change.
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.
Looks good.
@MariusVolkhart can you have a look at the failing tests? I believe they need to be adjusted to fit the improved code style? |
I don't know what to make of these test failures. The lines they point to are comments, and the error message they give isn't helping me - |
That's really weird, it compiles locally here as well. @marcospereira could this be an issue with the CI caching introduced recently? |
It is possible since jte build publishes artifacts locally, and I guess those are being included in the cache. I will do some investigation tomorrow, but a way to validate if the caches are screwing the builds here is to delete all of them (using gh cli), and trigger a new build manually (for this pr). |
I'm unsure if cache was the culprit here, or if this was just a CI fluke. Still, I created #316 since it would be good hygiene. @casid, can you trigger another build, and if it fails, delete the caches, and trigger another one? It would at least give us some confirmation if the failure is related to caching artifacts. |
import gg.jte.TemplateOutput | ||
import gg.jte.html.HtmlInterceptor |
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.
I'm not 100% sure about this removal.
There is a call to kmethod
a few lines below:
@template.statictemplates.kmethod(config = config, template = template) |
And that template later declares this variable:
!{String outputClass = config.contentType() == ContentType.Html ? "HtmlTemplateOutput" : "TemplateOutput";} |
That is then used by StaticJteModel
in the next line:
override fun ${Util.methodName(template)}(${Util.kotlinTypedParams(template, false)}): JteModel = StaticJteModel<${outputClass}>( |
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.
Yup! I'd say it's needed. Thanks for catching that
@marcospereira I re-ran the ubuntu build yesterday and it still failed. https://github.com/casid/jte/actions/runs/7470236001/job/20359418271?pr=310 will try to figure out how to clear the cache. |
I made a comment about it in #316. If you have GH CLI installed, you only need to run |
Thanks! I just cleared the cache via gh cli and reran the tests this morning, but the problem remains (https://github.com/casid/jte/actions/runs/7470236001/job/20372467503?pr=310). So this is not a cache problem. |
tl;drThere is a mismatch between your branch and the PR changes. A possible fix is to amend your last commit, force push, and see if this fixes the issue: git commit --amend --no-edit
git push --force-with-lease 🤞🏼 What is going on?
We got tricked by this. CI is not running gh pr checkout 310
./mvnw clean install --file pom.xml
Well, it is not. 🙈 This is the main branch right now: jte/jte-models/src/test/java/gg/jte/models/generator/TestModelExtension.java Lines 1 to 29 in 7ad2e12
And your PR IS NOT adding an import for See? No imports there! 👆🏼 Now, here is the WTH part of this. When I navigate to your branch, the import is there: Permalink: I guess that you run into some weird sync issues between your branch and the PR state? Maybe something related to this: https://github.com/orgs/community/discussions/16351 |
Okay, I got what is happening now. This is where the import for But your branch is not up to date with that change. You need to rebase it on top of |
@casid, it may be a good idea to enable this configuration: It will be clear when the PR branch is outdated, and help to fix confusions like this. |
Thanks for the investigation @marcospereira!
This setting makes a lot of sense, I've enabled it and will give the button a try :-). |
31fc79d
to
4848042
Compare
Thanks! So, the build is still failing because, now that the branch is rebased on top of the main, it does not include the import, and it should be failing locally the same way CI fails (since the |
Hey @casid @MariusVolkhart, I would love to see a new release containing #319, and I think the changes here can be part of it since this PR is virtually done. @MariusVolkhart, if you don't have the time, I can create a separate pull request with your commits (keeping proper attribution, of course) and fix the small issue blocking progress here. Let me know if you are okay with that. |
@marcospereira Awesome! Thanks for the investigation! Like I said, CI don't lie 😛 And thanks for the bump on this. Looking at it now. |
- Change import statements to not have an indent. No functional change. - Remove unused imports. These were likely copied over from the Java template, but are not needed in Kotlin. - Dynamic methods, which generate a map, now use Kotlin's buildMap() instead of mapOf(). mapOf() produces extra garbage, as it creates a Pair for each entry, whereas buildMap() modifies the underlying map directly. - Static methods are now defined as an expression. No functional change. - In static methods, the template class name is no longer fully qualified, as it's provided as an import. No functional change. - Remove semicolons - idiomatic Kotlin doesn't use them. No functional change.
Add import for Collectors
Restore the TemplateOutput import
4848042
to
5a7144a
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #310 +/- ##
=========================================
Coverage 91.23% 91.23%
Complexity 1216 1216
=========================================
Files 76 76
Lines 3159 3159
Branches 492 492
=========================================
Hits 2882 2882
Misses 164 164
Partials 113 113 ☔ View full report in Codecov by Sentry. |
Adjust the tests for windows line endings
Thank you guys! :-) |
Thanks, @MariusVolkhart! @casid, it would be great to have a 3.1.7 release if you have the time. :-) |
@marcospereira I just published 3.1.7 to maven central. |
Thanks, @casid! I tried it and... there is a bug in the model extension. The change here: It should use I'm working on a quick fix and how to test for that. Also, the changes in #310 are actually adding a number of unused imports in the model-extension facades. 🤔 /cc @MariusVolkhart. |
Quickly documenting my findings. :-) There is no Gradle test that combines:
|
See #324. |
:( I’m sorry for that. Breaking things and adding more work for the maintainers. @marcospereira thanks for fixing it and adding new tests. |
@MariusVolkhart no worries! We have a saying in German, which goes like "those who do nothing, break nothing". I'm really proud that the detection and fix went so quickly and smooth. It's an incredible little community in this project. |
Love this. Making and problems go together. It is how you react that matters. Keep the PRs coming, @MariusVolkhart.
It is a small community, but the experience of contributing here is very welcoming. Thanks for always been so responsive, @casid. |