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
5 changes: 4 additions & 1 deletion maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
</sources>
</configuration>
</execution>
<!-- add the examples as test resources -->
<!-- add the examples along with the other resources of the functional tests as test resources -->
<execution>
<id>add-test-resource</id>
<phase>generate-test-resources</phase>
Expand All @@ -205,6 +205,9 @@
<exclude>**/hibernate.properties</exclude>
</excludes>
</resource>
<resource>
<directory>src/functionalTest/resources</directory>
</resource>
</resources>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.hibernate.tool.maven;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

import org.apache.maven.cli.MavenCli;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class TransformHbmTestIT {

public static final String MVN_HOME = "maven.multiModuleProjectDirectory";

@TempDir
private Path projectPath;

@Test
public void testSimpleHbmTransformation() throws Exception {
System.setProperty(MVN_HOME, projectPath.toAbsolutePath().toString());
writePomFile();
copyHbmFile();

runTransformHbmToOrm();
}

private void writePomFile() throws Exception {
File pomFile = new File(projectPath.toFile(), "pom.xml");
assertFalse(pomFile.exists());
Path pomPath = projectPath.resolve("pom.xml");
Files.writeString(pomPath, simplePomContents);
assertTrue(pomFile.exists());
}

private void copyHbmFile() throws Exception {
URL originUrl = TransformHbmTestIT.class.getResource("simple.hbm.xml");
assertNotNull(originUrl);
Path originPath = Paths.get(Objects.requireNonNull(originUrl).toURI());
File destinationDir = new File(projectPath.toFile(), "src/main/resources/");
assertTrue(destinationDir.mkdirs());
File destinationFile = new File(destinationDir, "simple.hbm.xml");
assertFalse(destinationFile.exists());
Files.copy(originPath, destinationFile.toPath());
assertTrue(destinationFile.exists());
}

private void runTransformHbmToOrm() {
File destinationDir = new File(projectPath.toFile(), "src/main/resources/");
File ormXmlFile = new File(destinationDir, "simple.mapping.xml");
assertFalse(ormXmlFile.exists());
new MavenCli().doMain(
new String[]{"org.hibernate.tool:hibernate-tools-maven:7.2.0.CR2:hbm2orm", "generate-sources"},
projectPath.toAbsolutePath().toString(),
null,
null);
assertTrue(ormXmlFile.exists());
}

private static final String simplePomContents =
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.hibernate.tool.maven.test</groupId>
<artifactId>simplest</artifactId>
<version>0.1-SNAPSHOT</version>
</project>
""";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="org.bar.Foo">
<id name="id" type="long">
<generator class="assigned"/>
</id>
<property name="name" type="string"/>
</class>

</hibernate-mapping>