Skip to content
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

HHH-18644 - New and improved hibernate-maven-plugin #9129

Open
wants to merge 57 commits into
base: main
Choose a base branch
from

Conversation

koentsje
Copy link
Member

@koentsje koentsje commented Oct 21, 2024

This PR adds a new and improved Hibernate ORM Maven plugin


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-18644

  - Add 'target' and '.vscode' folders to .gitignore
  - Rename 'org.hibernate.orm.MyMojo' to 'org.hibernate.orm.EnhanceMojo'
  - Format 'pom.xml' and extract the version properties

Signed-off-by: Koen Aers <[email protected]>
  - Move class 'EnhanceMojo' to package 'org.hibernate.orm.tooling.maven.enhance'

Signed-off-by: Koen Aers <[email protected]>
  - Update JUnit dependency to version '5.11.2' of 'junit-jupiter-api'
  - Update Maven Plugin Api dependency to version '3.9.9'

Signed-off-by: Koen Aers <[email protected]>
  - Use version '4.0.0-beta-4' of maven-plugin-api
  - Avoid some warnings by adding encoding and specifying compiler version 17
  - Change the package info in class EnhanceMojo
  - Use Maven annotations instead of Javadoc tags as per the Maven advice
  - Add a simple dummy unit test

Signed-off-by: Koen Aers <[email protected]>
  - Some reformatting of class 'EnhanceMojo'
  - Implement a meaningful test 'EnhanceMojoTest#testExecute()'

Signed-off-by: Koen Aers <[email protected]>
  - Add an integration test for EnhanceMojo

Signed-off-by: Koen Aers <[email protected]>
  - Use the default value for 'outputDirectory' in the integration test

Signed-off-by: Koen Aers <[email protected]>
  - Add new dependency on version '3.15.0' of 'maven-plugin-annotations'
  - Use version '3.9.9' of the 'maven-plugin-api' dependency
  - Use the annotations from the new 'maven-plugin-annotations' depencency

Signed-off-by: Koen Aers <[email protected]>
  - Add a gradle.build file that delegates the build to maven

Signed-off-by: Koen Aers <[email protected]>
  - Add Maven wrapper functionality

Signed-off-by: Koen Aers <[email protected]>
  - 'build.gradle' uses the Maven wrapper

Signed-off-by: Koen Aers <[email protected]>
  - Include a dependency on Maven 'file-management'
  - Perform some optimizations in 'pom.xml'

Signed-off-by: Koen Aers <[email protected]>
  - Extract the 'touch' method

Signed-off-by: Koen Aers <[email protected]>
  - Add version '7.0.0.Beta1' of 'hibernate-core' as a dependency

Signed-off-by: Koen Aers <[email protected]>
  - Add a java source file ('org.foo.Bar.java') to the integration test
  - Verify the existence of the 'target/classes' folder in 'verifyAfter'

Signed-off-by: Koen Aers <[email protected]>
  - Remove the 'verifyBefore.groovy' script as it is not needed
  - Rename the 'verifyAfter.groovy' script to 'verify.groovy'
  - Add a verification for the existence of the class file 'org/foo/Bar.class'

Signed-off-by: Koen Aers <[email protected]>
  - Change name of 'outputDirectory' field to 'classesDirectory'
  - Change default value of 'classesDirectory' to '${project.build.dir}/classes'
  - Generate the 'touch.txt' file in the parent directory of 'classesDirectory'
  - Adapt the tests

Signed-off-by: Koen Aers <[email protected]>
  - Rename 'EnhanceMojoTest#testExecute()' to 'EnhanceMojoTest#testTouch()'
  - Use introspection to invoke the 'EnhanceMojo#touch()' method

Signed-off-by: Koen Aers <[email protected]>
  - Add a method 'EnhanceMojo#assembleSourceSet()' to populate the 'sourceSet' list
  - Add a test method 'EnhanceMojoTest#testAssembleSourceSet()'

Signed-off-by: Koen Aers <[email protected]>
  - Remove the unneeded method 'EnhanceMojo#touch()'
  - Remove the obsolete test method 'EnhanceMojoTest#testTouch()'

Signed-off-by: Koen Aers <[email protected]>
  - Remove the existence check of 'touch.txt' from the 'verify.groovy' script
  - Add method 'EnhanceMojo#createClassLoader()' that returns a URL class loader containing the classes folder
  - Add test method 'EnhanceMojoTest#testCreateClassLoader' to test the above new method

Signed-off-by: Koen Aers <[email protected]>
  - Add new class 'org.hibernate.orm.tooling.maven.enhance.EnhancementContext' that inherits from 'DefaultEnhancementContext'
  - Add new test class 'EnhancementContextTest' to test the overridden logic in the above class

Signed-off-by: Koen Aers <[email protected]>
  - Add a verification to 'verify.groovy' to test for some particular output in the build.log file

Signed-off-by: Koen Aers <[email protected]>
  - Log the configuration of the Mojo to the 'build.log'
  - Verify that this happens in the 'verify.groovy' script

Signed-off-by: Koen Aers <[email protected]>
  - Add new parameter 'enableAssociationManagement' with default value of 'false' and pass that parameter in the creation of the enhancement context
  - Adapt test method 'EnhanceMojoTest#testCreateEnhancementContext()'
  - Add a verification assertion to 'verify.groovy'

Signed-off-by: Koen Aers <[email protected]>
  - Add new parameter 'enableDirtyTracking' with default value of 'false' and pass that parameter in the creation of the enhancement context
  - Adapt test method 'EnhanceMojoTest#testCreateEnhancementContext()'
  - Add a verification assertion to 'verify.groovy'

Signed-off-by: Koen Aers <[email protected]>
  - Remove the 'EnhanceMojo#logConfiguration()' method as this is already done by default
  - Adapt 'verify.groovy' to account for the change above
  - Add new parameter 'enableLazyInitialization' with default value of 'false' and pass that parameter in the creation of the enhancement context
  - Adapt test method 'EnhanceMojoTest#testCreateEnhancementContext()'
  - Add a verification assertion to 'verify.groovy'

Signed-off-by: Koen Aers <[email protected]>
  - Add new parameter 'enableExtendedEnhancement' with default value of 'false' and pass that parameter in the creation of the enhancement context
  - Adapt test method 'EnhanceMojoTest#testCreateEnhancementContext()'
  - Add a verification assertion to 'verify.groovy'

Signed-off-by: Koen Aers <[email protected]>
  - Add an install goal to the invocation of 'maven-invoker-plugin' to make sure we test the currently building version of the 'hibernate-maven-plugin'
  - Create a new method 'EnhanceMojo#createEnhancer()'
  - Add a new test method 'EnhanceMojoTest#testCreateEnhancer()' to test the above new method

Signed-off-by: Koen Aers <[email protected]>
  - Removing unneeded stuff from 'EnhanceMojo#execute()'
  - Reporting an error if constructing the classloader fails in 'EnhanceMojo#createClassLoader()'
  - Add methods 'EnhanceMojo#determineClassName(File)', 'EnhanceMojo#discoverTypesForClass(File,Enhancer)' and 'EnhanceMojo#discoverTypes(Enhancer)'
  - Invoke method 'EnhanceMojo#discoverTypes(Enhancer) in 'EnhanceMojo#execute()'

Signed-off-by: Koen Aers <[email protected]>
  - Refactor/Cleanup of class EnhanceMojoTest

Signed-off-by: Koen Aers <[email protected]>
  - Add new test method 'EnhanceMojoTest#testDetermineClassName()'
  - Correct implementation of method 'EnhanceMojo#determineClassName()'

Signed-off-by: Koen Aers <[email protected]>
  - Make sure that the plugin is invoked in the right lifecycle phase (process-classes)
  - Add some logging info to the methods in EnhanceMojo
  - Test for the presence of the new logging info in the 'verify.groovy' script

Signed-off-by: Koen Aers <[email protected]>
  - Add new test method 'EnhanceMojoTest#testDiscoverTypesForClass()'

Signed-off-by: Koen Aers <[email protected]>
  - Add new test method 'EnhanceMojoTest#testDiscoverTypes()'

Signed-off-by: Koen Aers <[email protected]>
  - Create new method 'EnhanceMojo#clearFile(File)'
  - Add new test method 'EnhanceMojoTest#testClearFile()'

Signed-off-by: Koen Aers <[email protected]>
  - Create new method 'EnhanceMojo#writeByteCodeToFile(byte[],File)'
  - Add new test method 'EnhanceMojoTest#testWriteByteCodeToFile()'

Signed-off-by: Koen Aers <[email protected]>
  - Add the 'Enhancer' as a instance variable 'enhancer'
  - Adapt the methods that deal with Enhancer in EnhanceMojo
  - Adapt the tests for the above methods

Signed-off-by: Koen Aers <[email protected]>
  - Create new method 'EnhanceMojo#enhanceClass(File)'
  - Add new test method 'EnhanceMojoTest#testEnhanceFile()'

Signed-off-by: Koen Aers <[email protected]>
  - Create new method 'EnhanceMojo#performEnhancement()'
  - Add new test method 'EnhanceMojoTest#testPerformEnhancement()'

Signed-off-by: Koen Aers <[email protected]>
  - Modify 'EnhanceMojo#execute()' to call the 'EnhanceMojo#performEnhancement()' method
  - Modify the integration test by:
    * Adding a dependency on 'hibernate-core' (we need an entity)
    * Add an non-entity class 'org.foo.Foo'
    * Modify class 'org.foo.Bar' to make it an entity (the one that needs to be enhanced)
    * Modify the 'verify.groovy' script to make sure that the entity is enhanced and the non-entity class is skipped

Signed-off-by: Koen Aers <[email protected]>
  - Remove the 'public' modifier from the test methods in EnhanceMojoTest
  - Change 'EnhanceMojoTest#testClearFile()' and 'EnhanceMojoTest#testWriteByteCodeToFile()' because the difference between the two 'lastModified' timestamps was sometimes less than a millisecond
  - Add test method 'EnhanceMojoTest#testExecute()'

Signed-off-by: Koen Aers <[email protected]>
  - Add new method 'EnhanceMojo#verifyParameters()' to issue some deprecation warnings if needed
  - Add new test method 'EnhanceMojo#testVerifyParameters()' to test the above method
  - Redirect the logging of 'EnhanceMojo' during the tests to a test Log implementation that allows for more verifications

Signed-off-by: Koen Aers <[email protected]>
  - Invoke 'EnhanceMojo#verifyParameters()' from 'EnhanceMojo#execute()'
  - Test the presence of the appropriate logging messages in 'EnhanceMojoTest#testExecute()'

Signed-off-by: Koen Aers <[email protected]>
  - Create new method 'EnhanceMojo#addFileSetToSourceSet(FileSet)'
  - Add new test method 'EnhanceMojoTest#testAddFileSetToSourceSet()'
  - Add a new 'FileSet[]' parameter that has 'null' as a default
  - Use default scope for dependency on 'org.apache.maven.shared:file-management'

Signed-off-by: Koen Aers <[email protected]>
  - Rename method 'EnhanceMojo#verifyParameters()' to 'EnhanceMojo#processParameters()' and populate the 'fileSets' instance variable if it is 'null'
  - Rename test method 'EnhanceMojoTest#testVerifyParameters()' to 'EnhanceMojoTest#testProcessParameters()' and add some checks for the above changes

Signed-off-by: Koen Aers <[email protected]>
  - Iterate over the 'fileSets' parameter in 'EnhanceMojo#assembleSourceSet()' and call 'EnhanceMojo#addFileSetToSourceSet(FileSet)' for each fileSet found
  - Adapt test class EnhanceMojoTest
    * Add a new field 'fileSetsField' and populate it in the 'EnhanceMojoTest#beforeEach()' method
    * Change test method 'EnhanceMojoTest#testAssembleSourceSet()' to prepare and set a fileSet in the 'enhanceMojo' object under test
    * Use the new 'fileSetsField' instance variable in the test method 'EnhanceMojoTest#testProcessParameters()'
  - Adapt the integration test
    * Add a new java class 'org.foo.Baz'
    * Add some new 'fileSets' configuration to the 'pom.xml'
    * Add some new assertions to the 'verify.groovy' script

Signed-off-by: Koen Aers <[email protected]>
  - Remove unneeded method 'EnhanceMojo#addToSourceSetIfNeeded(File)'

Signed-off-by: Koen Aers <[email protected]>
  - Isolate the message strings for method 'EnhanceMojo#clearFile(File)'
  - Use the isolated messages above and add verifications concerning the logging in 'EnhanceMojoTest#testClearFile()'

Signed-off-by: Koen Aers <[email protected]>
  - Isolate the message strings for method 'EnhanceMojo#writeByteCodeToFile(File)'
  - Use the isolated messages above and add verifications concerning the logging in 'EnhanceMojoTest#testWriteByteCodeToFile()'

Signed-off-by: Koen Aers <[email protected]>
      - Isolate the message strings for method 'EnhanceMojo#determineClassName(File)'
      - Use the isolated messages above and add verifications concerning the logging in 'EnhanceMojoTest#testDetermineClassName)'

Signed-off-by: Koen Aers <[email protected]>
          - Isolate the message strings for method 'EnhanceMojo#enhanceClass(File)'
  - Use the isolated messages above and add verifications concerning the logging in 'EnhanceMojoTest#testEnhanceClass()'

Signed-off-by: Koen Aers <[email protected]>
  - Isolate the message strings for method 'EnhanceMojo#performEnhancement()'
  - Use the isolated messages above and add verifications concerning the logging in 'EnhanceMojoTest#testPerformEnhancement()'

Signed-off-by: Koen Aers <[email protected]>
@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Oct 21, 2024

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

koentsje and others added 2 commits October 21, 2024 16:57
  - Add 'tooling/hibernate-maven-plugin/' from commit '637c1b519e0638956f95ab5535113ad431ded7ff'

  - git-subtree-dir: tooling/hibernate-maven-plugin
  - git-subtree-mainline: bf5c499
  - git-subtree-split: 637c1b5
@koentsje koentsje changed the title Hhh 18644 HHH-18644 - New and improved hibernate-maven-plugin Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants