-
Notifications
You must be signed in to change notification settings - Fork 242
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
HSEARCH-4673 Use record specific methods to get constructor parameter names when applicable #3240
HSEARCH-4673 Use record specific methods to get constructor parameter names when applicable #3240
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.
Hey Marko! Thanks for that PR :)
Unfortunately... I think it would have been better to start with a test.
Looking at your code, I had a hunch and asked my self "hey, but since the compiler adds metadata for record components, maybe it also adds the param name to Parameter#getName()
, just for records, even when not using the -parameters
compiler flag? And indeed, it looks like it does: https://github.com/yrodiere/jdk-playground/blob/records-parameters/src/test/java/org/hibernate/jdk/playground/MyTest.java#L13-L14
So... The good news is that projection constructors for records compiled without using -parameters
probably already work in Hibernate Search. The bad news is that changes in this PR won't be needed... They were still useful though, since they made me ask the right question and find out the answer :)
What's needed, though, is some testing and adjustments to the warnings about -parameters
in the documentation.
Regarding testing, it's going to be a bit complex... We need to make sure that records involved in this test are compiled without the -parameters
flag, and all test code is compiled with this flag...
So, if you're still up for it, I'd suggest:
- Adding a source directory
java17-noparameters
tointegrationtest/mapper/pojo-base
- Adding a dedicated execution of the
maven-compiler-plugin
to that same module, making sure that-parameters
is NOT enabled - Copy-pasting
ProjectionConstructorRecordIT
tojava17-noparameters
(renaming it toProjectionConstructorRecordNoParametersCompilerFlagIT
?) - Adding a test to
ProjectionConstructorRecordNoParametersCompilerFlagIT
to check that-parameters
is indeed not enabled. Maybe just add a dummy class to the same source directory and check that its constructor parameters don't have a name (!param.isNamePresent()
)?
And if you work on this, don't forget to update the documentation, of course :)
Thanks again!
No worries 😃 I’ll make the changes. |
b14ed87
to
9325c71
Compare
sorry that it took me ages to go back to this PR 🙊 I have removed the I also thought if we want to keep the additional sources folder as we can configure the compiler plugin with includes/excludes. I also noticed that the build failed for the compiler-eclipse ... so I'll try to see what I can do about it. |
9325c71
to
8f58882
Compare
We need different configuration (compiler flags) for each source folder, so we need multiple executions... not sure what you're suggesting?
Looks like the main build is failing as well :) |
8f58882
to
21cfb4e
Compare
let's see if the build works now 🙈 I have a bit more time to actually explain what I meant 😃 hopefully, it'll make sense 😉
If I get it correctly... adding test sources happens before their compilation, which means once we reach the step of compiling the tests, all of them are pulled into one folder, and it doesn't really matter for the compiler plugin where they came from. These [INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ hibernate-search-documentation ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 372 source files to /mnt/jenkins-workdir/workspace/hibernate-search_PR-3240/documentation/target/test-classes
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (noparameters-testCompile) @ hibernate-search-documentation ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 372 source files to /mnt/jenkins-workdir/workspace/hibernate-search_PR-3240/documentation/target/test-classes that's what caused the failure of main build -_- but if there's a match, everything is ok and only a single test is compiled as expected: [INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ hibernate-search-integrationtest-mapper-pojo-base ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 214 source files to /home/marko/development/projects/opensource/hibernate-search/integrationtest/mapper/pojo-base/target/test-classes
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (noparameters-testCompile) @ hibernate-search-integrationtest-mapper-pojo-base ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/marko/development/projects/opensource/hibernate-search/integrationtest/mapper/pojo-base/target/test-classes To make it work, I've added a configurable |
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 noticed a few typos, and added a few questions.
documentation/src/main/asciidoc/reference/mapping-projection.asciidoc
Outdated
Show resolved
Hide resolved
documentation/src/main/asciidoc/reference/mapping-projection.asciidoc
Outdated
Show resolved
Hide resolved
...st/mapper/pojo/mapping/definition/ProjectionConstructorRecordNoParametersCompilerFlagIT.java
Outdated
Show resolved
Hide resolved
21cfb4e
to
c4e3c75
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.
One more typo I noticed by chance. I also answered regarding the source filtering in maven-compiler-plugin.
...st/mapper/pojo/mapping/definition/ProjectionConstructorRecordNoParametersCompilerFlagIT.java
Outdated
Show resolved
Hide resolved
c4e3c75
to
3848b6b
Compare
ok. rebased to include the latest changes 😃 I've added a new execution for checkstyle to enforce the I have also tried to remove the Let's see if the build will pass on CI 🤞🏻 |
👍
Right, that's probably the culprit. Changing that code you linked to configure the
|
- switch to `noparameters` package filtering instead of test class name - use checkstyle to enforce `noparameters` package presence
3848b6b
to
6f46e3a
Compare
- apply -parameters arg only to default-compile - do not override compiler parameters for noparameters-testCompile execution
6f46e3a
to
12f487f
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
https://hibernate.atlassian.net/browse/HSEARCH-4673
Hey Yoann! It's been a while 😑😃. I noticed this task on reflection, so I thought I'd look into it. From what I understand, it all starts inside
ProjectionConstructorProcessor#process()
, which led me to these SPI HCAnn classes...As these are SPI, I'm not sure where it would be better to put the utils for records and if it's ok to have two implementations for the constructor or if we should keep just one and hide the logic inside...