diff --git a/ant/docs/examples/cfgxml/build.xml b/ant/docs/examples/cfgxml/build.xml new file mode 100644 index 0000000000..0c56dd8ed6 --- /dev/null +++ b/ant/docs/examples/cfgxml/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + diff --git a/ant/docs/examples/cfgxml/hibernate.cfg.xml b/ant/docs/examples/cfgxml/hibernate.cfg.xml new file mode 100644 index 0000000000..50e16665b1 --- /dev/null +++ b/ant/docs/examples/cfgxml/hibernate.cfg.xml @@ -0,0 +1,11 @@ + + + + + org.h2.Driver + jdbc:h2:tcp://localhost/./sakila + sa + SAKILA + PUBLIC + + diff --git a/ant/src/it/java/org/hibernate/tool/ant/ExamplesTestIT.java b/ant/src/it/java/org/hibernate/tool/ant/ExamplesTestIT.java index d6e3f49375..481935d729 100644 --- a/ant/src/it/java/org/hibernate/tool/ant/ExamplesTestIT.java +++ b/ant/src/it/java/org/hibernate/tool/ant/ExamplesTestIT.java @@ -5,6 +5,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; @@ -45,6 +46,18 @@ public void test5MinuteTutorial() throws Exception { assertTrue(personFile.exists()); } + @Disabled + @Test + public void testCfgXml() throws Exception { + File buildFile = new File(baseFolder, "cfgxml/build.xml"); + Project project = createProject(buildFile); + assertNotNull(project); + File personFile = new File(baseFolder, "cfgxml/generated/Person.java"); + assertFalse(personFile.exists()); + project.executeTarget("reveng"); + assertTrue(personFile.exists()); + } + @Test public void testClasspath() throws Exception { PrintStream savedOut = System.out; diff --git a/ant/src/main/java/org/hibernate/tool/ant/JDBCConfigurationTask.java b/ant/src/main/java/org/hibernate/tool/ant/JDBCConfigurationTask.java index ca952ea03e..c9a446040b 100644 --- a/ant/src/main/java/org/hibernate/tool/ant/JDBCConfigurationTask.java +++ b/ant/src/main/java/org/hibernate/tool/ant/JDBCConfigurationTask.java @@ -24,6 +24,8 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Path; +import org.hibernate.boot.cfgxml.internal.ConfigLoader; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.tool.api.metadata.MetadataDescriptor; import org.hibernate.tool.api.metadata.MetadataDescriptorFactory; import org.hibernate.tool.api.metadata.MetadataConstants; @@ -53,7 +55,7 @@ public JDBCConfigurationTask() { setDescription("JDBC Configuration (for reverse engineering)"); } protected MetadataDescriptor createMetadataDescriptor() { - Properties properties = loadPropertiesFile(); + Properties properties = loadProperties(); RevengStrategy res = createReverseEngineeringStrategy(); properties.put(MetadataConstants.PREFER_BASIC_COMPOSITE_IDS, preferBasicCompositeIds); return MetadataDescriptorFactory @@ -144,4 +146,20 @@ private RevengStrategy loadreverseEngineeringStrategy(final String className, Re throw new BuildException("Could not create or find " + className + " with one argument delegate constructor", e); } } + + private Properties loadCfgXmlFile() { + return new ConfigLoader(new BootstrapServiceRegistryBuilder().build()) + .loadProperties(getConfigurationFile()); + } + + private Properties loadProperties() { + Properties result = new Properties(); + if (getPropertyFile() != null) { + result.putAll(loadPropertiesFile()); + } + if (getConfigurationFile() != null) { + result.putAll(loadCfgXmlFile()); + } + return result; + } }