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
32 changes: 32 additions & 0 deletions ant/docs/examples/cfgxml/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
~ 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.
-->
<project name="5-minute-tutorial" default="reveng">

<!-- Include the 'hibernatetool' task definition from the file '../common/included.xml' -->
<include file="../common/included.xml"/>

<target name="reveng" depends="common.clean">
<!-- Generation of the artefacts in folder 'generated-sources' -->
<hibernatetool destdir="generated">
<!-- JDBC Configuration based on 'hibernate.cfg.xml' file -->
<jdbcconfiguration configurationfile="hibernate.cfg.xml" />
<!-- The Java file exporter -->
<hbm2java/>
</hibernatetool>
</target>

</project>

11 changes: 11 additions & 0 deletions ant/docs/examples/cfgxml/hibernate.cfg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:tcp://localhost/./sakila</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.default_catalog">SAKILA</property>
<property name="hibernate.default_schema">PUBLIC</property>
</session-factory>
</hibernate-configuration>
13 changes: 13 additions & 0 deletions ant/src/it/java/org/hibernate/tool/ant/ExamplesTestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}