Skip to content

Commit b0d134e

Browse files
committed
HBX-3234: Improve the Maven hbm2orm Mojo
- Better determination of the base folder in TransformHbmTestIT Signed-off-by: Koen Aers <[email protected]>
1 parent 745137a commit b0d134e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

maven/src/functionalTest/java/org/hibernate/tool/maven/TransformHbmTestIT.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,14 @@
2020
public class TransformHbmTestIT {
2121

2222
public static final String MVN_HOME = "maven.multiModuleProjectDirectory";
23-
private static File baseFolder;
2423
private static File localRepo;
2524

2625
@TempDir
2726
private Path projectPath;
2827

2928
@BeforeAll
3029
public static void beforeAll() throws Exception {
31-
// The needed resource for this test are put in place
32-
// in the 'baseFolder' (normally 'target/test-classes')
33-
// by the 'build-helper-maven-plugin' execution.
34-
// See the 'pom.xml'
35-
baseFolder = determineBaseFolder();
36-
localRepo = new File(baseFolder.getParentFile(), "local-repo");
30+
localRepo = new File(determineBaseFolder().getParentFile(), "local-repo");
3731
}
3832
@Test
3933
public void testSimpleHbmTransformation() throws Exception {
@@ -75,17 +69,21 @@ private void runTransformHbmToOrm() throws Exception {
7569
projectPath.toAbsolutePath().toString(),
7670
null,
7771
null);
78-
// Check the existaence of the transformed file
72+
// Check the existence of the transformed file
7973
assertTrue(ormXmlFile.exists());
8074
// Check if it's pretty printed
8175
assertTrue(Files.readString(ormXmlFile.toPath()).contains("\n <table name=\"Foo\"/>\n"));
8276
}
8377

8478
private static File determineBaseFolder() throws Exception {
85-
URL classUrl = TransformHbmTestIT.class.getResource(
86-
"/" + TransformHbmTestIT.class.getName().replace(".", "/") + ".class");
87-
return new File(classUrl.toURI())
88-
.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile();
79+
Class<?> thisClass = TransformHbmTestIT.class;
80+
URL classUrl = thisClass.getResource("/" + thisClass.getName().replace(".", "/") + ".class");
81+
assert classUrl != null;
82+
File result = new File(classUrl.toURI());
83+
for (int i = 0; i < thisClass.getName().chars().filter(ch -> ch == '.').count() + 1; i++) {
84+
result = result.getParentFile();
85+
}
86+
return result;
8987
}
9088

9189
private static final String simplePomContents =

0 commit comments

Comments
 (0)