Skip to content

Commit

Permalink
HBX-2869: Create a GenerateHBM Mojo in the Maven plugin - Test the Mojo
Browse files Browse the repository at this point in the history
Signed-off-by: Koen Aers <[email protected]>
  • Loading branch information
koentsje committed Jul 24, 2024
1 parent 09c5bce commit 76415e9
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/maven-plugin/src/it/generateHbm/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.java.version = 1.8+
invoker.goals = generate-resources
53 changes: 53 additions & 0 deletions test/maven-plugin/src/it/generateHbm/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.hibernate.tool.test</groupId>
<artifactId>hbm2ddl</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>
<h2.version>1.4.195</h2.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>HBM generation</id>
<phase>generate-resources</phase>
<goals>
<goal>generateHbm</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<templatePath>${project.basedir}/src/main/resources/templates/</templatePath>
</configuration>
</execution>
</executions>
<configuration>
<revengFile>${project.basedir}/src/main/resources/hibernate.reveng.xml</revengFile>
</configuration>
<dependencies>
<dependency>
<!-- DB Driver of your choice -->
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>

<type-mapping>
<sql-type jdbc-type="DATE" hibernate-type="java.time.LocalDate"/>
<sql-type jdbc-type="TIMESTAMP" hibernate-type="java.time.LocalDateTime"/>
</type-mapping>

</hibernate-reverse-engineering>
Original file line number Diff line number Diff line change
@@ -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"/>

</#if>
<#include "PojoExtraClassCode.ftl"/>

}
</#assign>

${pojo.generateImports()}
${classbody}

Original file line number Diff line number Diff line change
@@ -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)}
*/
</#if> ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${c2j.keyWordCheck(field.name)}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
</#if>
</#list>
Binary file not shown.
6 changes: 6 additions & 0 deletions test/maven-plugin/src/it/generateHbm/verify.groovy
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 76415e9

Please sign in to comment.