Skip to content

Commit db46cb0

Browse files
committed
HBX-3130: Take into account the 'hibernate.cfg.xml' file in the Ant reverse engineering task
- Enable the test and add proper reading of the 'hibernate.cfg.xml' configuration values Signed-off-by: Koen Aers <[email protected]>
1 parent 8284d44 commit db46cb0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

ant/src/it/java/org/hibernate/tool/ant/ExamplesTestIT.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.apache.tools.ant.Project;
66
import org.apache.tools.ant.ProjectHelper;
77
import org.junit.jupiter.api.BeforeAll;
8-
import org.junit.jupiter.api.Disabled;
98
import org.junit.jupiter.api.Test;
109

1110
import java.io.ByteArrayOutputStream;
@@ -46,10 +45,15 @@ public void test5MinuteTutorial() throws Exception {
4645
assertTrue(personFile.exists());
4746
}
4847

49-
@Disabled
5048
@Test
5149
public void testCfgXml() throws Exception {
5250
File buildFile = new File(baseFolder, "cfgxml/build.xml");
51+
File cfgXmlFile = new File(baseFolder, "cfgxml/hibernate.cfg.xml");
52+
String cfgXmlFileContents = Files.readString(cfgXmlFile.toPath())
53+
.replace("jdbc:h2:tcp://localhost/./sakila", constructJdbcConnectionString())
54+
.replace(">sa<", "><")
55+
.replace(">SAKILA<", ">TEST<");
56+
Files.writeString(cfgXmlFile.toPath(), cfgXmlFileContents);
5357
Project project = createProject(buildFile);
5458
assertNotNull(project);
5559
File personFile = new File(baseFolder, "cfgxml/generated/Person.java");

ant/src/main/java/org/hibernate/tool/ant/JDBCConfigurationTask.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
import java.io.File;
2121
import java.lang.reflect.Constructor;
22+
import java.util.Map;
2223
import java.util.Properties;
2324

2425
import org.apache.tools.ant.BuildException;
2526
import org.apache.tools.ant.Project;
2627
import org.apache.tools.ant.types.Path;
2728
import org.hibernate.boot.cfgxml.internal.ConfigLoader;
29+
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
2830
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
2931
import org.hibernate.tool.api.metadata.MetadataDescriptor;
3032
import org.hibernate.tool.api.metadata.MetadataDescriptorFactory;
@@ -121,8 +123,8 @@ public void setDetectManyToMany(boolean b) {
121123
public void setDetectOptimisticLock(boolean b) {
122124
detectOptimisticLock = b;
123125
}
124-
125-
private RevengStrategy loadreverseEngineeringStrategy(final String className, RevengStrategy delegate)
126+
127+
private RevengStrategy loadreverseEngineeringStrategy(final String className, RevengStrategy delegate)
126128
throws BuildException {
127129
try {
128130
Class<?> clazz = ReflectionUtil.classForName(className);
@@ -147,9 +149,10 @@ private RevengStrategy loadreverseEngineeringStrategy(final String className, Re
147149
}
148150
}
149151

150-
private Properties loadCfgXmlFile() {
152+
private Map<String, Object> loadCfgXmlFile() {
151153
return new ConfigLoader(new BootstrapServiceRegistryBuilder().build())
152-
.loadProperties(getConfigurationFile());
154+
.loadConfigXmlFile(getConfigurationFile())
155+
.getConfigurationValues();
153156
}
154157

155158
private Properties loadProperties() {

0 commit comments

Comments
 (0)