Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions maven-plugin/docs/examples/5-minute-tutorial/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2018 - 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.
-->
<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.maven.test</groupId>
<artifactId>five-minute-tutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>@h2.version@</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>Entity generation</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -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

127 changes: 127 additions & 0 deletions maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<!-- Maven Plugins -->
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -41,6 +51,31 @@
<artifactId>maven-plugin-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -93,6 +128,98 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>${maven-invoker-plugin.version}</version>
<configuration>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- run the integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- add the integration test source folder -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/functionalTest/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-resource</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>docs/examples</directory>
<excludes>
<!-- we will not use the Sakila database for the purpose of the integration test -->
<exclude>**/hibernate.properties</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>filter-test-resources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.build.testOutputDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>**/pom.xml</include>
</includes>
</resource>
</resources>
<delimiters>
<delimiter>@*@</delimiter>
</delimiters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.hibernate.tool.maven;

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.Test;

import org.apache.maven.cli.MavenCli;

import java.io.File;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class ExamplesTestIT {

public static final String MVN_HOME = "maven.multiModuleProjectDirectory";
private static File baseFolder;
private static File localRepo;

@BeforeAll
public static void beforeAll() throws Exception {
// The needed resource for this test are put in place
// in the 'baseFolder' (normally 'target/test-classes')
// by the 'build-helper-maven-plugin' execution.
// See the 'pom.xml'
baseFolder = determineBaseFolder();
localRepo = new File(baseFolder.getParentFile(), "local-repo");
createDatabase();
}

private MavenCli mavenCli;

@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"));
}

private File prepareProjectFolder(String projectName) throws Exception {
File 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 {
File projectResourcesFolder = new File(projectFolder, "src/main/resources");
projectResourcesFolder.mkdirs();
File hibernatePropertiesFile = new File(projectResourcesFolder, "hibernate.properties");
assertFalse(hibernatePropertiesFile.exists());
String hibernatePropertiesFileContents =
"hibernate.connection.driver_class=org.h2.Driver\n" +
"hibernate.connection.url=" + constructJdbcConnectionString() + "\n" +
"hibernate.connection.username=\n" +
"hibernate.connection.password=\n" +
"hibernate.default_catalog=TEST\n" +
"hibernate.default_schema=PUBLIC\n";
Files.write(hibernatePropertiesFile.toPath(), hibernatePropertiesFileContents.getBytes());
assertTrue(hibernatePropertiesFile.exists());
}

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 {
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))");
statement.close();
connection.close();
assertTrue(databaseFile.exists());
assertTrue(databaseFile.isFile());
}

private static String constructJdbcConnectionString() {
return "jdbc:h2:" + baseFolder.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
}

}
38 changes: 33 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
<mysql.version>8.0.22</mysql.version>
<oracle.version>19.3.0.0</oracle.version>
<sqlserver.version>9.2.1.jre8</sqlserver.version>
<maven-resolver.version>1.9.24</maven-resolver.version>
<slf4j.version>2.0.17</slf4j.version>

<!-- Plugins not managed by the JBoss parent POM: -->
<maven-plugin-api.version>3.9.11</maven-plugin-api.version>
Expand Down Expand Up @@ -171,11 +173,36 @@
<artifactId>maven-plugin-api</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>${maven-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${maven-plugin-annotations.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>${maven-resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${maven-resolver.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
Expand Down Expand Up @@ -215,11 +242,6 @@
<artifactId>ant</artifactId>
<version>${ant.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
Expand Down Expand Up @@ -251,6 +273,12 @@
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down