-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBX-2869: Create a GenerateHBM Mojo in the Maven plugin - Test the Mojo
Signed-off-by: Koen Aers <koen.aers@gmail.com>
- Loading branch information
Showing
8 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
invoker.java.version = 1.8+ | ||
invoker.goals = generate-resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.tool</groupId> | ||
<artifactId>hibernate-tools-maven</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> |
7 changes: 7 additions & 0 deletions
7
test/maven/src/it/generateHbm/src/main/resources/hibernate.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
11 changes: 11 additions & 0 deletions
11
test/maven/src/it/generateHbm/src/main/resources/hibernate.reveng.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
29 changes: 29 additions & 0 deletions
29
test/maven/src/it/generateHbm/src/main/resources/templates/pojo/Pojo.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
|
7 changes: 7 additions & 0 deletions
7
test/maven/src/it/generateHbm/src/main/resources/templates/pojo/PojoFields.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |