From ff57800ccd3c58258d1847b68ccb1d8a1b0267c3 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 19 Sep 2025 17:10:37 +0200 Subject: [PATCH 01/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Reorganize 'pom.xml' file Signed-off-by: Koen Aers --- maven/pom.xml | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/maven/pom.xml b/maven/pom.xml index 7a70741db..2e37894e7 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -47,7 +47,7 @@ jakarta.xml.bind jakarta.xml.bind-api - + org.junit.jupiter junit-jupiter-engine @@ -124,8 +124,8 @@ default-descriptor process-classes - hibernate-tools - + hibernate-tools + help-goal @@ -133,8 +133,8 @@ helpmojo - hibernate-tools - + hibernate-tools + @@ -185,19 +185,6 @@ - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - integration-test - verify - - - - org.codehaus.mojo @@ -215,6 +202,7 @@ + add-test-resource generate-test-resources @@ -235,6 +223,8 @@ + org.apache.maven.plugins maven-resources-plugin @@ -256,16 +246,30 @@ - ${*} + ${h2.version} + ${hibernate.version} + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + - + maven-project-info-reports-plugin From 9e0a9c34bad6e08656b53c6276596f5d86f3359c Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 19 Sep 2025 17:21:19 +0200 Subject: [PATCH 02/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Reorganize test class ExamplesTestIT Signed-off-by: Koen Aers --- .../hibernate/tool/maven/ExamplesTestIT.java | 67 ++++++++++++++----- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java index f29bf7322..8ad0d1d54 100644 --- a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java +++ b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.apache.maven.cli.MavenCli; @@ -21,6 +22,14 @@ public class ExamplesTestIT { private static File baseFolder; private static File localRepo; + private File projectFolder; + private MavenCli mavenCli; + + private String[] databaseCreationScript = new String[] { + // This is the default database which can be overridden per test + "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))" + }; + @BeforeAll public static void beforeAll() throws Exception { // The needed resource for this test are put in place @@ -29,32 +38,26 @@ public static void beforeAll() throws Exception { // See the 'pom.xml' baseFolder = determineBaseFolder(); localRepo = new File(baseFolder.getParentFile(), "local-repo"); - createDatabase(); } - private MavenCli mavenCli; + @BeforeEach + public void beforeEach() throws Exception { + createDatabase(); + } @Test public void test5MinuteTutorial() throws Exception { - File projectFolder = prepareProjectFolder("5-minute-tutorial"); - File generatedPersonFile = new File(projectFolder, "target/generated-sources/Person.java"); - assertFalse(generatedPersonFile.exists()); - new MavenCli().doMain( - new String[]{"-Dmaven.repo.local=" + localRepo.getAbsolutePath(), "generate-sources"}, - projectFolder.getAbsolutePath(), - null, - null); - assertTrue(generatedPersonFile.exists()); - String personFileContents = new String(Files.readAllBytes(generatedPersonFile.toPath())); - assertTrue(personFileContents.contains("public class Person")); + prepareProject("5-minute-tutorial"); + assertNotGeneratedYet(); + runGenerateSources(); + assertGeneratedContains("public class Person"); } - private File prepareProjectFolder(String projectName) throws Exception { - File projectFolder = new File(baseFolder, projectName); + private void prepareProject(String projectName) throws Exception { + projectFolder = new File(baseFolder, projectName); assertTrue(projectFolder.exists()); System.setProperty(MVN_HOME, projectFolder.getAbsolutePath()); createHibernatePropertiesFile(projectFolder); - return projectFolder; } private void createHibernatePropertiesFile(File projectFolder) throws Exception { @@ -73,18 +76,46 @@ private void createHibernatePropertiesFile(File projectFolder) throws Exception assertTrue(hibernatePropertiesFile.exists()); } + private void runGenerateSources() { + new MavenCli().doMain( + new String[]{"-Dmaven.repo.local=" + localRepo.getAbsolutePath(), "generate-sources"}, + projectFolder.getAbsolutePath(), + null, + null); + } + + private void assertNotGeneratedYet() { + assertFalse(new File(projectFolder, "target/generated-sources/Person.java").exists()); + } + + private void assertGeneratedContains(String contents) throws Exception { + assertTrue(readGeneratedContents().contains(contents)); + } + + private void assertGeneratedDoesNotContain(String contents) throws Exception { + assertFalse(readGeneratedContents().contains(contents)); + } + + private String readGeneratedContents() throws Exception { + File generatedPersonFile = new File(projectFolder, "target/generated-sources/Person.java"); + assertTrue(generatedPersonFile.exists()); + return new String(Files.readAllBytes(generatedPersonFile.toPath())); + } + private static File determineBaseFolder() throws Exception { return new File(ExamplesTestIT.class.getClassLoader().getResource("5-minute-tutorial/pom.xml").toURI()) .getParentFile().getParentFile(); } - private static void createDatabase() throws Exception { + private void createDatabase() throws Exception { File databaseFile = new File(baseFolder, "database/test.mv.db"); assertFalse(databaseFile.exists()); assertFalse(databaseFile.isFile()); Connection connection = DriverManager.getConnection(constructJdbcConnectionString()); Statement statement = connection.createStatement(); - statement.execute("create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"); + for (String s : databaseCreationScript) { + statement.execute(s); + } statement.close(); connection.close(); assertTrue(databaseFile.exists()); From d22cd115246e4562e70147bb73eefdc62d86570c Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 19 Sep 2025 17:30:57 +0200 Subject: [PATCH 03/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add the 'hbm2java/jpa-default' example - Remove erroneous line from '5-minute-tutorial/README.md' Signed-off-by: Koen Aers --- .../docs/examples/5-minute-tutorial/README.md | 1 - .../examples/hbm2java/jpa-default/README.md | 21 ++++++++ .../examples/hbm2java/jpa-default/pom.xml | 53 +++++++++++++++++++ .../src/main/resources/hibernate.properties | 23 ++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 maven/docs/examples/hbm2java/jpa-default/README.md create mode 100644 maven/docs/examples/hbm2java/jpa-default/pom.xml create mode 100644 maven/docs/examples/hbm2java/jpa-default/src/main/resources/hibernate.properties diff --git a/maven/docs/examples/5-minute-tutorial/README.md b/maven/docs/examples/5-minute-tutorial/README.md index 52dce31ac..84a3e3453 100644 --- a/maven/docs/examples/5-minute-tutorial/README.md +++ b/maven/docs/examples/5-minute-tutorial/README.md @@ -18,5 +18,4 @@ To run this example: - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running - Issue one of the following commands from a command-line window opened in this folder: - `mvn generate-sources -Dh2.version=${h2.version} -Dproject.version=${hibernate.version}` - - `mvn hbm2java -Dh2.version=${h2.version} -Dproject.version=${hibernate.version}` \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/jpa-default/README.md b/maven/docs/examples/hbm2java/jpa-default/README.md new file mode 100644 index 000000000..b7b95463c --- /dev/null +++ b/maven/docs/examples/hbm2java/jpa-default/README.md @@ -0,0 +1,21 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following commands from a command-line window opened in this folder: + `mvn generate-sources -Dh2.version=${h2.version} -Dhibernate.version=${hibernate.version}` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/jpa-default/pom.xml b/maven/docs/examples/hbm2java/jpa-default/pom.xml new file mode 100644 index 000000000..155065d44 --- /dev/null +++ b/maven/docs/examples/hbm2java/jpa-default/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + five-minute-tutorial + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/jpa-default/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/jpa-default/src/main/resources/hibernate.properties new file mode 100644 index 000000000..60b2483a2 --- /dev/null +++ b/maven/docs/examples/hbm2java/jpa-default/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + From 841fa6fa88871551757e93245c2b8bb5376e70c3 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 19 Sep 2025 18:00:30 +0200 Subject: [PATCH 04/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add a test for jpa-default and reorganize test class Signed-off-by: Koen Aers --- .../hibernate/tool/maven/ExamplesTestIT.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java index 8ad0d1d54..15e4699b7 100644 --- a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java +++ b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + import org.apache.maven.cli.MavenCli; @@ -25,6 +27,9 @@ public class ExamplesTestIT { private File projectFolder; private MavenCli mavenCli; + @TempDir + private File tempFolder; + private String[] databaseCreationScript = new String[] { // This is the default database which can be overridden per test "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))" @@ -53,6 +58,14 @@ public void test5MinuteTutorial() throws Exception { assertGeneratedContains("public class Person"); } + @Test + public void testJpaDefault() throws Exception { + prepareProject("hbm2java/jpa-default"); + assertNotGeneratedYet(); + runGenerateSources(); + assertGeneratedContains("import jakarta.persistence.Entity;"); + } + private void prepareProject(String projectName) throws Exception { projectFolder = new File(baseFolder, projectName); assertTrue(projectFolder.exists()); @@ -108,7 +121,7 @@ private static File determineBaseFolder() throws Exception { } private void createDatabase() throws Exception { - File databaseFile = new File(baseFolder, "database/test.mv.db"); + File databaseFile = new File(tempFolder, "database/test.mv.db"); assertFalse(databaseFile.exists()); assertFalse(databaseFile.isFile()); Connection connection = DriverManager.getConnection(constructJdbcConnectionString()); @@ -122,8 +135,8 @@ private void createDatabase() throws Exception { assertTrue(databaseFile.isFile()); } - private static String constructJdbcConnectionString() { - return "jdbc:h2:" + baseFolder.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; + private String constructJdbcConnectionString() { + return "jdbc:h2:" + tempFolder.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } } From 5ad2f96dda49785935b416b9110305fe8933946b Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 19 Sep 2025 18:10:22 +0200 Subject: [PATCH 05/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add the 'hbm2java/no-annotations' example Signed-off-by: Koen Aers --- .../hbm2java/no-annotations/README.md | 21 +++++++ .../examples/hbm2java/no-annotations/pom.xml | 56 +++++++++++++++++++ .../src/main/resources/hibernate.properties | 23 ++++++++ 3 files changed, 100 insertions(+) create mode 100644 maven/docs/examples/hbm2java/no-annotations/README.md create mode 100644 maven/docs/examples/hbm2java/no-annotations/pom.xml create mode 100644 maven/docs/examples/hbm2java/no-annotations/src/main/resources/hibernate.properties diff --git a/maven/docs/examples/hbm2java/no-annotations/README.md b/maven/docs/examples/hbm2java/no-annotations/README.md new file mode 100644 index 000000000..b7b95463c --- /dev/null +++ b/maven/docs/examples/hbm2java/no-annotations/README.md @@ -0,0 +1,21 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following commands from a command-line window opened in this folder: + `mvn generate-sources -Dh2.version=${h2.version} -Dhibernate.version=${hibernate.version}` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/no-annotations/pom.xml b/maven/docs/examples/hbm2java/no-annotations/pom.xml new file mode 100644 index 000000000..3c007a168 --- /dev/null +++ b/maven/docs/examples/hbm2java/no-annotations/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-no-annotations + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + false + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/no-annotations/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/no-annotations/src/main/resources/hibernate.properties new file mode 100644 index 000000000..60b2483a2 --- /dev/null +++ b/maven/docs/examples/hbm2java/no-annotations/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + From 171ec1e828a3dcf71028fa92c7e23e011532ae29 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 19 Sep 2025 18:16:14 +0200 Subject: [PATCH 06/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add a test for no-annotations and reorganize test class Signed-off-by: Koen Aers --- .../java/org/hibernate/tool/maven/ExamplesTestIT.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java index 15e4699b7..77bef2568 100644 --- a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java +++ b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java @@ -66,6 +66,13 @@ public void testJpaDefault() throws Exception { assertGeneratedContains("import jakarta.persistence.Entity;"); } + @Test + public void testNoAnnotations() throws Exception { + prepareProject("hbm2java/no-annotations"); + assertNotGeneratedYet(); + runGenerateSources(); + assertGeneratedDoesNotContain("import jakarta.persistence.Entity;"); + } private void prepareProject(String projectName) throws Exception { projectFolder = new File(baseFolder, projectName); assertTrue(projectFolder.exists()); From ed90874c3dc59e286e1d3df7832d7042b33e21e1 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Mon, 22 Sep 2025 11:39:22 +0200 Subject: [PATCH 07/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add the 'hbm2java/no-generics' example Signed-off-by: Koen Aers --- .../examples/hbm2java/no-generics/README.md | 21 +++++++ .../examples/hbm2java/no-generics/pom.xml | 56 +++++++++++++++++++ .../src/main/resources/hibernate.properties | 23 ++++++++ 3 files changed, 100 insertions(+) create mode 100644 maven/docs/examples/hbm2java/no-generics/README.md create mode 100644 maven/docs/examples/hbm2java/no-generics/pom.xml create mode 100644 maven/docs/examples/hbm2java/no-generics/src/main/resources/hibernate.properties diff --git a/maven/docs/examples/hbm2java/no-generics/README.md b/maven/docs/examples/hbm2java/no-generics/README.md new file mode 100644 index 000000000..b7b95463c --- /dev/null +++ b/maven/docs/examples/hbm2java/no-generics/README.md @@ -0,0 +1,21 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following commands from a command-line window opened in this folder: + `mvn generate-sources -Dh2.version=${h2.version} -Dhibernate.version=${hibernate.version}` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/no-generics/pom.xml b/maven/docs/examples/hbm2java/no-generics/pom.xml new file mode 100644 index 000000000..de0b1216b --- /dev/null +++ b/maven/docs/examples/hbm2java/no-generics/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-no-generics + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + false + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/no-generics/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/no-generics/src/main/resources/hibernate.properties new file mode 100644 index 000000000..60b2483a2 --- /dev/null +++ b/maven/docs/examples/hbm2java/no-generics/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + From e9a9d0319e8f38f7909bb36f1d3431534a927b5f Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Mon, 22 Sep 2025 11:55:31 +0200 Subject: [PATCH 08/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add a test for no-generics Signed-off-by: Koen Aers --- .../org/hibernate/tool/maven/ExamplesTestIT.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java index 77bef2568..2421c8817 100644 --- a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java +++ b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java @@ -80,6 +80,19 @@ private void prepareProject(String projectName) throws Exception { createHibernatePropertiesFile(projectFolder); } + @Test + public void testNoGenerics() throws Exception { + databaseCreationScript = new String[] { + "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))", + "create table ITEM (ID int not null, NAME varchar(20), OWNER_ID int not null, " + + " primary key (ID), foreign key (OWNER_ID) references PERSON(ID))" + }; + prepareProject("hbm2java/no-generics"); + assertNotGeneratedYet(); + runGenerateSources(); + assertGeneratedDoesNotContain("Set"); + } + private void createHibernatePropertiesFile(File projectFolder) throws Exception { File projectResourcesFolder = new File(projectFolder, "src/main/resources"); projectResourcesFolder.mkdirs(); From cebad9a4643c418922dbeb2afa79c8157f8d8f4c Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Mon, 22 Sep 2025 12:43:36 +0200 Subject: [PATCH 09/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add the 'hbm2java/use-generics' example Signed-off-by: Koen Aers --- .../examples/hbm2java/use-generics/README.md | 21 ++++++++ .../examples/hbm2java/use-generics/pom.xml | 53 +++++++++++++++++++ .../src/main/resources/hibernate.properties | 23 ++++++++ 3 files changed, 97 insertions(+) create mode 100644 maven/docs/examples/hbm2java/use-generics/README.md create mode 100644 maven/docs/examples/hbm2java/use-generics/pom.xml create mode 100644 maven/docs/examples/hbm2java/use-generics/src/main/resources/hibernate.properties diff --git a/maven/docs/examples/hbm2java/use-generics/README.md b/maven/docs/examples/hbm2java/use-generics/README.md new file mode 100644 index 000000000..b7b95463c --- /dev/null +++ b/maven/docs/examples/hbm2java/use-generics/README.md @@ -0,0 +1,21 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following commands from a command-line window opened in this folder: + `mvn generate-sources -Dh2.version=${h2.version} -Dhibernate.version=${hibernate.version}` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/use-generics/pom.xml b/maven/docs/examples/hbm2java/use-generics/pom.xml new file mode 100644 index 000000000..3a201eb1f --- /dev/null +++ b/maven/docs/examples/hbm2java/use-generics/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-use-generics + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/use-generics/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/use-generics/src/main/resources/hibernate.properties new file mode 100644 index 000000000..60b2483a2 --- /dev/null +++ b/maven/docs/examples/hbm2java/use-generics/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + From 744ad64d45cfbc48fa308e9b70c372c6bd1e02cf Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Mon, 22 Sep 2025 13:20:04 +0200 Subject: [PATCH 10/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add a test for use-generics - Make sure database is correctly created - Add assertion for the amount of generated files - Modify some utility methods to accept file name parameter Signed-off-by: Koen Aers --- .../hibernate/tool/maven/ExamplesTestIT.java | 76 ++++++++++++------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java index 2421c8817..96b4d85e3 100644 --- a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java +++ b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java @@ -1,11 +1,10 @@ package org.hibernate.tool.maven; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -45,39 +44,31 @@ public static void beforeAll() throws Exception { localRepo = new File(baseFolder.getParentFile(), "local-repo"); } - @BeforeEach - public void beforeEach() throws Exception { - createDatabase(); - } - @Test public void test5MinuteTutorial() throws Exception { prepareProject("5-minute-tutorial"); - assertNotGeneratedYet(); + assertNotGeneratedYet("Person.java"); runGenerateSources(); - assertGeneratedContains("public class Person"); + assertNumberOfGeneratedFiles(1); + assertGeneratedContains("Person.java", "public class Person"); } @Test public void testJpaDefault() throws Exception { prepareProject("hbm2java/jpa-default"); - assertNotGeneratedYet(); + assertNotGeneratedYet("Person.java"); runGenerateSources(); - assertGeneratedContains("import jakarta.persistence.Entity;"); + assertNumberOfGeneratedFiles(1); + assertGeneratedContains("Person.java","import jakarta.persistence.Entity;"); } @Test public void testNoAnnotations() throws Exception { prepareProject("hbm2java/no-annotations"); - assertNotGeneratedYet(); + assertNotGeneratedYet("Person.java"); runGenerateSources(); - assertGeneratedDoesNotContain("import jakarta.persistence.Entity;"); - } - private void prepareProject(String projectName) throws Exception { - projectFolder = new File(baseFolder, projectName); - assertTrue(projectFolder.exists()); - System.setProperty(MVN_HOME, projectFolder.getAbsolutePath()); - createHibernatePropertiesFile(projectFolder); + assertNumberOfGeneratedFiles(1); + assertGeneratedDoesNotContain("Person.java", "import jakarta.persistence.Entity;"); } @Test @@ -88,9 +79,32 @@ public void testNoGenerics() throws Exception { " primary key (ID), foreign key (OWNER_ID) references PERSON(ID))" }; prepareProject("hbm2java/no-generics"); - assertNotGeneratedYet(); + assertNotGeneratedYet("Person.java"); + runGenerateSources(); + assertNumberOfGeneratedFiles(2); + assertGeneratedDoesNotContain("Person.java", "Set"); + } + + @Test + public void testUseGenerics() throws Exception { + databaseCreationScript = new String[] { + "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))", + "create table ITEM (ID int not null, NAME varchar(20), OWNER_ID int not null, " + + " primary key (ID), foreign key (OWNER_ID) references PERSON(ID))" + }; + prepareProject("hbm2java/use-generics"); + assertNotGeneratedYet("Person.java"); runGenerateSources(); - assertGeneratedDoesNotContain("Set"); + assertNumberOfGeneratedFiles(2); + assertGeneratedContains("Person.java", "Set"); + } + + private void prepareProject(String projectName) throws Exception { + projectFolder = new File(baseFolder, projectName); + assertTrue(projectFolder.exists()); + System.setProperty(MVN_HOME, projectFolder.getAbsolutePath()); + createHibernatePropertiesFile(projectFolder); + createDatabase(); } private void createHibernatePropertiesFile(File projectFolder) throws Exception { @@ -117,20 +131,24 @@ private void runGenerateSources() { null); } - private void assertNotGeneratedYet() { - assertFalse(new File(projectFolder, "target/generated-sources/Person.java").exists()); + private void assertNotGeneratedYet(String fileName) { + assertFalse(new File(projectFolder, "target/generated-sources/" + fileName).exists()); + } + + private void assertGeneratedContains(String fileName, String contents) throws Exception { + assertTrue(readGeneratedContents(fileName).contains(contents)); } - private void assertGeneratedContains(String contents) throws Exception { - assertTrue(readGeneratedContents().contains(contents)); + private void assertGeneratedDoesNotContain(String fileName, String contents) throws Exception { + assertFalse(readGeneratedContents(fileName).contains(contents)); } - private void assertGeneratedDoesNotContain(String contents) throws Exception { - assertFalse(readGeneratedContents().contains(contents)); + private void assertNumberOfGeneratedFiles(int amount) throws Exception { + assertEquals(amount, new File(projectFolder, "target/generated-sources").list().length); } - private String readGeneratedContents() throws Exception { - File generatedPersonFile = new File(projectFolder, "target/generated-sources/Person.java"); + private String readGeneratedContents(String fileName) throws Exception { + File generatedPersonFile = new File(projectFolder, "target/generated-sources/" + fileName); assertTrue(generatedPersonFile.exists()); return new String(Files.readAllBytes(generatedPersonFile.toPath())); } From a14b078f5fa0bc571e3bfb1ae29523333452b94b Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Mon, 22 Sep 2025 15:58:20 +0200 Subject: [PATCH 11/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add the 'hbm2java/template-path' example - Add a test for template-path Signed-off-by: Koen Aers --- .../examples/hbm2java/jpa-default/pom.xml | 2 +- .../examples/hbm2java/template-path/README.md | 26 +++++++++ .../examples/hbm2java/template-path/pom.xml | 56 +++++++++++++++++++ .../src/main/resources/hibernate.properties | 23 ++++++++ .../template-path/templates/pojo/Pojo.ftl | 18 ++++++ maven/pom.xml | 5 +- .../hibernate/tool/maven/ExamplesTestIT.java | 10 ++++ 7 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 maven/docs/examples/hbm2java/template-path/README.md create mode 100644 maven/docs/examples/hbm2java/template-path/pom.xml create mode 100644 maven/docs/examples/hbm2java/template-path/src/main/resources/hibernate.properties create mode 100644 maven/docs/examples/hbm2java/template-path/templates/pojo/Pojo.ftl diff --git a/maven/docs/examples/hbm2java/jpa-default/pom.xml b/maven/docs/examples/hbm2java/jpa-default/pom.xml index 155065d44..94ac1fbd9 100644 --- a/maven/docs/examples/hbm2java/jpa-default/pom.xml +++ b/maven/docs/examples/hbm2java/jpa-default/pom.xml @@ -20,7 +20,7 @@ 4.0.0 org.hibernate.tool.maven.test - five-minute-tutorial + hbm2java-jpa-default 0.0.1-SNAPSHOT diff --git a/maven/docs/examples/hbm2java/template-path/README.md b/maven/docs/examples/hbm2java/template-path/README.md new file mode 100644 index 000000000..fa81c4911 --- /dev/null +++ b/maven/docs/examples/hbm2java/template-path/README.md @@ -0,0 +1,26 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following command from a command-line window opened in this folder: +```shell +mvn generate-sources + -Dh2.version=${h2.version} + -Dhibernate.version=${hibernate.version} + -Dtemplate.dir=./templates +``` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/template-path/pom.xml b/maven/docs/examples/hbm2java/template-path/pom.xml new file mode 100644 index 000000000..11e23132d --- /dev/null +++ b/maven/docs/examples/hbm2java/template-path/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-template-path + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + ${template.dir} + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/template-path/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/template-path/src/main/resources/hibernate.properties new file mode 100644 index 000000000..60b2483a2 --- /dev/null +++ b/maven/docs/examples/hbm2java/template-path/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + diff --git a/maven/docs/examples/hbm2java/template-path/templates/pojo/Pojo.ftl b/maven/docs/examples/hbm2java/template-path/templates/pojo/Pojo.ftl new file mode 100644 index 000000000..18f3de1a5 --- /dev/null +++ b/maven/docs/examples/hbm2java/template-path/templates/pojo/Pojo.ftl @@ -0,0 +1,18 @@ + +// This is just an example of a custom template + + diff --git a/maven/pom.xml b/maven/pom.xml index 2e37894e7..2c1319ef7 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -246,9 +246,10 @@ - ${h2.version} - ${hibernate.version} + ${*.version} + false + \ diff --git a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java index 96b4d85e3..f5433bf8b 100644 --- a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java +++ b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java @@ -85,6 +85,16 @@ public void testNoGenerics() throws Exception { assertGeneratedDoesNotContain("Person.java", "Set"); } + @Test + public void testTemplatePath() throws Exception { + System.setProperty("template.dir", "${project.basedir}/templates"); + prepareProject("hbm2java/template-path"); + assertNotGeneratedYet("Person.java"); + runGenerateSources(); + assertNumberOfGeneratedFiles(1); + assertGeneratedContains("Person.java", "// This is just an example of a custom template"); + } + @Test public void testUseGenerics() throws Exception { databaseCreationScript = new String[] { From 36d2a182f43bdbc5c591daea6d8af455c5ee1096 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Mon, 22 Sep 2025 16:32:27 +0200 Subject: [PATCH 12/12] HBX-3128: Avoid use of Maven invoker plugin while performing functional testing - Add the 'hbm2java/output-dir' example - Add a test for 'hbm2java/output-dir' Signed-off-by: Koen Aers --- .../hbm2java/output-directory/README.md | 26 +++++++++ .../hbm2java/output-directory/pom.xml | 56 +++++++++++++++++++ .../src/main/resources/hibernate.properties | 23 ++++++++ maven/pom.xml | 2 - .../hibernate/tool/maven/ExamplesTestIT.java | 13 +++++ 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 maven/docs/examples/hbm2java/output-directory/README.md create mode 100644 maven/docs/examples/hbm2java/output-directory/pom.xml create mode 100644 maven/docs/examples/hbm2java/output-directory/src/main/resources/hibernate.properties diff --git a/maven/docs/examples/hbm2java/output-directory/README.md b/maven/docs/examples/hbm2java/output-directory/README.md new file mode 100644 index 000000000..a5b85c8ec --- /dev/null +++ b/maven/docs/examples/hbm2java/output-directory/README.md @@ -0,0 +1,26 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following command from a command-line window opened in this folder: +```shell +mvn generate-sources + -Dh2.version=${h2.version} + -Dhibernate.version=${hibernate.version} + -Doutput.dir=./generated-classes +``` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/output-directory/pom.xml b/maven/docs/examples/hbm2java/output-directory/pom.xml new file mode 100644 index 000000000..1ece83935 --- /dev/null +++ b/maven/docs/examples/hbm2java/output-directory/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-jpa-default + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + ${output.dir} + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/output-directory/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/output-directory/src/main/resources/hibernate.properties new file mode 100644 index 000000000..60b2483a2 --- /dev/null +++ b/maven/docs/examples/hbm2java/output-directory/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + diff --git a/maven/pom.xml b/maven/pom.xml index 2c1319ef7..732e3d5f5 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -248,8 +248,6 @@ ${*.version} - false - \ diff --git a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java index f5433bf8b..b11f0b2c2 100644 --- a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java +++ b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java @@ -85,6 +85,19 @@ public void testNoGenerics() throws Exception { assertGeneratedDoesNotContain("Person.java", "Set"); } + @Test + public void testOutputDirectory() throws Exception { + System.setProperty("output.dir", "${project.basedir}/generated-classes"); + prepareProject("hbm2java/output-directory"); + File outputDirectory = new File(projectFolder, "generated-classes"); + File personFile = new File(outputDirectory, "Person.java"); + assertFalse(outputDirectory.exists()); + assertFalse(personFile.exists()); + runGenerateSources(); + assertEquals(1, outputDirectory.list().length); // 1 file is generated in 'generated-classes' + assertTrue(personFile.exists()); // The Person.java file should have been generated + } + @Test public void testTemplatePath() throws Exception { System.setProperty("template.dir", "${project.basedir}/templates");