From 06a60f3215e6a3332077560e90ad8f09973e9748 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 19 Jul 2024 12:55:18 +0300 Subject: [PATCH] HBX-2869: Create a GenerateHBM Mojo in the Maven plugin - Test the Mojo Signed-off-by: Koen Aers --- .../src/it/generateHbm/invoker.properties | 2 + test/maven/src/it/generateHbm/pom.xml | 53 ++++++++++++++++++ .../src/main/resources/hibernate.properties | 7 +++ .../src/main/resources/hibernate.reveng.xml | 11 ++++ .../main/resources/templates/pojo/Pojo.ftl | 29 ++++++++++ .../resources/templates/pojo/PojoFields.ftl | 7 +++ test/maven/src/it/generateHbm/test.mv.db | Bin 0 -> 28672 bytes test/maven/src/it/generateHbm/verify.groovy | 6 ++ 8 files changed, 115 insertions(+) create mode 100644 test/maven/src/it/generateHbm/invoker.properties create mode 100644 test/maven/src/it/generateHbm/pom.xml create mode 100644 test/maven/src/it/generateHbm/src/main/resources/hibernate.properties create mode 100644 test/maven/src/it/generateHbm/src/main/resources/hibernate.reveng.xml create mode 100644 test/maven/src/it/generateHbm/src/main/resources/templates/pojo/Pojo.ftl create mode 100644 test/maven/src/it/generateHbm/src/main/resources/templates/pojo/PojoFields.ftl create mode 100644 test/maven/src/it/generateHbm/test.mv.db create mode 100644 test/maven/src/it/generateHbm/verify.groovy diff --git a/test/maven/src/it/generateHbm/invoker.properties b/test/maven/src/it/generateHbm/invoker.properties new file mode 100644 index 0000000000..13598db400 --- /dev/null +++ b/test/maven/src/it/generateHbm/invoker.properties @@ -0,0 +1,2 @@ +invoker.java.version = 1.8+ +invoker.goals = generate-resources \ No newline at end of file diff --git a/test/maven/src/it/generateHbm/pom.xml b/test/maven/src/it/generateHbm/pom.xml new file mode 100644 index 0000000000..31b70c7f7e --- /dev/null +++ b/test/maven/src/it/generateHbm/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + org.hibernate.tool.test + hbm2ddl + 0.0.1-SNAPSHOT + + + UTF-8 + UTF-8 + + 1.8 + 1.4.195 + + + + + + org.hibernate.tool + hibernate-tools-maven + @project.version@ + + + HBM generation + generate-resources + + generateHbm + + + ${project.build.directory}/generated-sources + ${project.basedir}/src/main/resources/templates/ + + + + + ${project.basedir}/src/main/resources/hibernate.reveng.xml + + + + + com.h2database + h2 + ${h2.version} + + + + + + + \ No newline at end of file diff --git a/test/maven/src/it/generateHbm/src/main/resources/hibernate.properties b/test/maven/src/it/generateHbm/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..71496b3adc --- /dev/null +++ b/test/maven/src/it/generateHbm/src/main/resources/hibernate.properties @@ -0,0 +1,7 @@ +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:./test;DB_CLOSE_ON_EXIT=FALSE +hibernate.connection.username=sa +hibernate.connection.password= +hibernate.connection.pool_size=1 +hibernate.show_sql=true \ No newline at end of file diff --git a/test/maven/src/it/generateHbm/src/main/resources/hibernate.reveng.xml b/test/maven/src/it/generateHbm/src/main/resources/hibernate.reveng.xml new file mode 100644 index 0000000000..7ac52fd2cf --- /dev/null +++ b/test/maven/src/it/generateHbm/src/main/resources/hibernate.reveng.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/Pojo.ftl b/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/Pojo.ftl new file mode 100644 index 0000000000..84ff76a5b2 --- /dev/null +++ b/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/Pojo.ftl @@ -0,0 +1,29 @@ +${pojo.getPackageDeclaration()} +// Generated ${date} by Hibernate Tools ${version} + +<#assign classbody> +<#include "PojoTypeDeclaration.ftl"/> { + +<#if !pojo.isInterface()> +<#include "PojoFields.ftl"/> + +<#include "PojoConstructors.ftl"/> + +<#include "PojoPropertyAccessors.ftl"/> + +<#include "PojoToString.ftl"/> + +<#include "PojoEqualsHashcode.ftl"/> + +<#else> +<#include "PojoInterfacePropertyAccessors.ftl"/> + + +<#include "PojoExtraClassCode.ftl"/> + +} + + +${pojo.generateImports()} +${classbody} + diff --git a/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/PojoFields.ftl b/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/PojoFields.ftl new file mode 100644 index 0000000000..18cf396cc6 --- /dev/null +++ b/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/PojoFields.ftl @@ -0,0 +1,7 @@ +<#-- // Fields --> +<#list pojo.getAllPropertiesIterator() as field><#if pojo.getMetaAttribAsBool(field, "gen-property", true)><#if pojo.hasMetaAttribute(field, "field-description")> /** + ${pojo.getFieldJavaDoc(field, 0)} + */ + ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${c2j.keyWordCheck(field.name)}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}; + + diff --git a/test/maven/src/it/generateHbm/test.mv.db b/test/maven/src/it/generateHbm/test.mv.db new file mode 100644 index 0000000000000000000000000000000000000000..72d79270f88b69518fe17598ef53debfe7371c91 GIT binary patch literal 28672 zcmeI4TWcFf6vuZJtBI93AWCQ-S{NtPPC+O$yV{#*OJr$-L?zisa!8)c>@6{IBxB1V z^r3{d^r_Hq(9hAAmVAOd=B*IOW4}Y`XlG}4t&1bas&UB?W-qg=oio4H#sB}Aqk35> zIC}&4iCA}czw^rkV_a|_AN8M<00AHX1b_e#00KY&2mk>f00e*l5V!yY>O%L6HR%5f za91D%AOHk_01yBIKmZ5;0U!VbfB+Bx0*fUOC;7!BfIYv@vieWyewni6^D=R8q3=H* zmes;OedHf9pWt9HV3~izWRnCiRt&5bhPzMMq=A4C*KwWHlmK*=$7uGzs`OTpWl8$v zg(Tf+v-Mp`dj0D1^(+gps7sPOkbjXbOIN~S6g5|Dc;N{oTq@yG4VR^GsXdE^?M8DS zv;rUY-tIHM#RjdYxG>t@ibkB^(EJF89^udgj*td+a2kiEQY*pXif+BATYaosVy3%I z--VL63r5tfD!MIAxeJ=+7)iI@jXq_!XRz=0dk3_CNZlcuuyJ@TY(46GgXZ87-x*S8 z&oAPu;gP+8)1v$FcE=AE`^tl>0RbQY1b_e#00KY&2mk>f00cfP0u%as+I;#zQ3F@? zoU^Fu>CeqY{RfdERU<_@Mevr!1+N<_&trmDF;pw1|AXnB&e_WJzx}sP`Y39DnFWo|`D_=!?wmPh}^ALS&Ka7LoO*^b< z$3&a$xSa>vsIg0|qc2t-F^CNAlmW5v*HCq{-R*TMqcKIJOQyt%Cmt2- z(Lo*p`y5!yyuF;2@|jhV&)ihM6SXP*8)p8r=2%`L^5XC0p+lF3tf{{OE~+kMJz*PV_e zjn=PUEyvm}^IN7WEuWuHm?|29U2mk>f z00e*l5C8&c0$g>b^taIetSSCIJy*x38Bl9dBcHWJ9U z`G0M!N=O%p=~P(^wo2GdI&~JR|9|{24HsU06y^W<4(R{%7cFc90U!VbfB+Bx0zlw` z5SYk13;nOTiT)3;>bt~q&m^a(K3VAh@qBZl|7Yg^jX5gMr}jB-BhUZ8;o9yl&;RrK z|6}?8?^F5zDcVkmJojXg7iYZBLFFYGZ*sg+--`49=OX)N#zA8m=b!^;M&SqzJZ?@2 zG5R0f@D2iz{!jFG VtpB}~{wErC70;hnInRGy?qAGfE9C$H literal 0 HcmV?d00001 diff --git a/test/maven/src/it/generateHbm/verify.groovy b/test/maven/src/it/generateHbm/verify.groovy new file mode 100644 index 0000000000..586fe51dc5 --- /dev/null +++ b/test/maven/src/it/generateHbm/verify.groovy @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "target/generated-sources/Person.hbm.xml"); +if (!file.isFile()) { + throw new FileNotFoundException("Could not find generated HBM file: " + file); +}