[hibernate-commits] Hibernate SVN: r11100 - in branches/Branch_3_2/HibernateExt/tools/src: test/org/hibernate/tool/ant and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jan 25 06:36:35 EST 2007


Author: max.andersen at jboss.com
Date: 2007-01-25 06:36:34 -0500 (Thu, 25 Jan 2007)
New Revision: 11100

Added:
   branches/Branch_3_2/HibernateExt/tools/src/testsupport/jpaoverrides.properties
Modified:
   branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java
   branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java
   branches/Branch_3_2/HibernateExt/tools/src/testsupport/anttest-build.xml
Log:
HBX-861 JPA configuration should support propertyfile as a way to do overrides

Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java	2007-01-25 03:28:33 UTC (rev 11099)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java	2007-01-25 11:36:34 UTC (rev 11100)
@@ -67,19 +67,11 @@
 	 */
 	protected void doConfiguration(Configuration configuration) {	
 		validateParameters();		
-		if (propertyFile!=null) { 
-			Properties properties = new Properties(); // TODO: should we "inherit" from the ant projects properties ?
-			try {
-				properties.load(new FileInputStream(propertyFile) );
-			} 
-			catch (FileNotFoundException e) {
-				throw new BuildException(propertyFile + " not found.",e);					
-			} 
-			catch (IOException e) {
-				throw new BuildException("Problem while loading " + propertyFile,e);				
-			}
-			configuration.setProperties(properties);
+		Properties p = getProperties();
+		if(p!=null) {
+			configuration.setProperties(p);
 		}
+		
 		if (entityResolver != null) {
 			try {
 				Class resolver = ReflectHelper.classForName(entityResolver, this.getClass());
@@ -108,6 +100,24 @@
 		if (configurationFile != null) configuration.configure( configurationFile );
 		addMappings(getFiles() );
 	}
+
+	protected Properties getProperties() {
+		if (propertyFile!=null) { 
+			Properties properties = new Properties(); // TODO: should we "inherit" from the ant projects properties ?
+			try {
+				properties.load(new FileInputStream(propertyFile) );
+				return properties;
+			} 
+			catch (FileNotFoundException e) {
+				throw new BuildException(propertyFile + " not found.",e);					
+			} 
+			catch (IOException e) {
+				throw new BuildException("Problem while loading " + propertyFile,e);				
+			}		
+		} else {
+			return null;
+		}
+	}
 	
 	
 	protected void validateParameters() throws BuildException {

Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java	2007-01-25 03:28:33 UTC (rev 11099)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java	2007-01-25 11:36:34 UTC (rev 11100)
@@ -4,6 +4,7 @@
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 
 import org.apache.tools.ant.BuildException;
 import org.hibernate.HibernateException;
@@ -22,6 +23,11 @@
 	protected Configuration createConfiguration() {
 		try {
 			Map overrides = new HashMap();
+			Properties p = getProperties();
+			
+			if(p!=null) {
+				overrides.putAll( p );
+			}
 
 			Class clazz = ReflectHelper.classForName("org.hibernate.ejb.Ejb3Configuration", JPAConfigurationTask.class);
 			Object ejb3cfg = clazz.newInstance();

Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java	2007-01-25 03:28:33 UTC (rev 11099)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java	2007-01-25 11:36:34 UTC (rev 11100)
@@ -88,6 +88,16 @@
 		executeTarget("jpa-punit");		
 	}
 	
+	public void testJPAPropertyOveridesPUnit() {
+		try {
+			executeTarget("jpa-overrides");
+			fail("property overrides not accepted");
+		} catch (BuildException be) {
+			// should happen
+			assertTrue(be.getMessage().indexOf("FAKEDialect")>0);
+		}
+	}
+	
 	public void testHbm2JavaConfiguration() {
 		executeTarget("testanthbm2java");
 	}

Modified: branches/Branch_3_2/HibernateExt/tools/src/testsupport/anttest-build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/testsupport/anttest-build.xml	2007-01-25 03:28:33 UTC (rev 11099)
+++ branches/Branch_3_2/HibernateExt/tools/src/testsupport/anttest-build.xml	2007-01-25 11:36:34 UTC (rev 11100)
@@ -308,6 +308,47 @@
 		<antcall target="afterCfg2hbm" />
 	</target>
 
+	<target name="jpa-overrides">
+		<path id="annlib">
+			<path location="${build.dir}/../../lib/freemarker.jar" />
+
+			<path location="${build.dir}/../../lib/testlibs/hibernate3.jar" />
+			<path location="${build.dir}/../../lib/testlibs/hibernate-annotations.jar" />
+			<path location="${build.dir}/../../lib/testlibs/ejb3-persistence.jar" />
+			<path location="${build.dir}/../../lib/testlibs/hibernate-entitymanager.jar" />
+			<path location="${build.dir}/../../lib/testlibs/jboss-archive-browsing.jar" />
+			<path location="${build.dir}/../../lib/testlibs/javaassist.jar" /> 
+			<path location="${build.dir}/../classes" />
+			<path location="${hibernate-core.home}\jdbc\hsqldb.jar" />
+		</path>
+
+		<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="annlib" />
+
+		<delete dir="${build.dir}/ejb3" />
+		<mkdir dir="${build.dir}/ejb3" />
+
+		<antcall target="prepareCfg2hbm" />
+		<hibernatetool>
+			<jdbcconfiguration propertyfile="../../etc/hibernate.properties" />
+			<hbm2java ejb3="true" jdk5="true" destdir="${build.dir}/ejb3/src" />
+		</hibernatetool>
+
+		<mkdir dir="${build.dir}/ejb3/classes" />
+		<javac classpathref="annlib" srcdir="${build.dir}/ejb3/src" destdir="${build.dir}/ejb3/classes" />
+
+		<copy file="ejb3test-persistence.xml" tofile="${build.dir}/ejb3/classes/META-INF/persistence.xml" />
+		<copy file="ejb3test-hibernate.cfg.xml" tofile="${build.dir}/ejb3/classes/ejb3test-hibernate.cfg.xml" />
+
+		<hibernatetool destdir="${build.dir}">
+			<jpaconfiguration persistenceunit="ejb3test" entityresolver="DummyEntityResolver" propertyfile="jpaoverrides.properties"/>
+			<classpath>
+				<path location="${build.dir}/ejb3/classes" />
+			</classpath>
+			<hbm2ddl export="false" outputfilename="ejb3.sql" />
+		</hibernatetool>
+
+		<antcall target="afterCfg2hbm" />
+	</target>
 	
 	<target name="testantejb3hbm2java">
 		<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="tasks.classpath" />

Added: branches/Branch_3_2/HibernateExt/tools/src/testsupport/jpaoverrides.properties
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/testsupport/jpaoverrides.properties	                        (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/testsupport/jpaoverrides.properties	2007-01-25 11:36:34 UTC (rev 11100)
@@ -0,0 +1,2 @@
+# only used to test jpa overrides being picked up
+hibernate.dialect FAKEDialect
\ No newline at end of file




More information about the hibernate-commits mailing list