-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: HibernateToolTask destdir not respected from chained ant
PostPosted: Sat Feb 03, 2007 6:10 pm 
Newbie

Joined: Sat Feb 03, 2007 4:26 pm
Posts: 3
Description of Problem
Using ant HibernateToolTask to generate ddl using hbm2ddl. This task is located in ./inner/build.xml.

Problem is that when ant build files are chained together, i.e. ./outer/build.xml calls ./inner/build.xml, the ddl output is written to a directory relative to ./outer, not ./inner as is specified by the "destdir" attribute in the ant task.

I'm attaching both the inner and outer build.xml's as well as the output from running them. I've added echo statements to show that the value of "destdir" is identical whether run from inner or outer.

Any help appreciated! This is causing us to write lots of hacky build deployment code as our build scripts are chained.

My only other suspect is HSQLDB is causing this, but the connection url in hibernate.properties is pointing to dir 'junk' and that is apparently not being used in either case (inner or outer).

Thanks,

Michael

directory structure of projects
[michael@mkd610 hbtoolsbug]$ ls
inner outer

./inner/build.xml
-------------
Code:
<project name="INNER" default="all" basedir=".">
    <property name="proj" value="inner"/>

    <property name="proj.root.dir" value="${basedir}"/>
    <property name="src" value="${proj.root.dir}/src"/>
    <property name="build" value="${proj.root.dir}/build"/>
    <property name="lib" value="${proj.root.dir}/lib"/>
    <property name="data.dir" value="${proj.root.dir}/data"/>
    <property name="db.name" value="dbname"/>

    <!-- build.cp: classpath used for inner builds -->
    <path id="build.cp">
        <fileset dir="${lib}">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <target name="clean">
        <delete dir="${build}" quiet="true"/>
    </target>

    <!-- init: creates necessary directory structure if it doesn't exist -->
    <target name="init">
        <!-- Create the time stamp -->
        <tstamp/>
        <mkdir dir="${data.dir}"/>
        <mkdir dir="${build}"/>
        <delete file="hibernate.log"/>
    </target>

    <patternset id="meta.files">
        <include name="**/*.hbm.xml"/>
        <include name="**/*.properties"/>
    </patternset>

    <target name="copy.meta.files">
        <copy todir="${build}">
          <fileset dir="${src}">
            <patternset refid="meta.files"/>
            </fileset>
        </copy>       
    </target>

    <target name="schema-gen" depends="clean,init,copy.meta.files">
        <echo message="destdir attribute points to: ${data.dir}"/>
        <echo message="deleting old schema files in ${data.dir} ..."/>
        <delete quiet="true">
            <fileset dir="${data.dir}">
                <include name="**/*"/>
            </fileset>
        </delete>
        <!-- taskdef is inside target on purpose to insure build directory exists when taskdef is defined -->
        <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
            classpathref="build.cp"/>
        <!-- WARNING! WARNING! WARNING!  The value for destdir is not respected.
             When this build file is called from another build file, the files
             get written to a directory off-the root of the other build file!!!!
             -->
        <hibernatetool destdir="${data.dir}">
            <classpath path="${build}"/>
            <configuration>
                <fileset dir="${src}">
                    <include name="**/*.hbm.xml"/>
                </fileset>
            </configuration>
            <hbm2ddl drop="false" create="true" export="true" update="false"/>
        </hibernatetool>
    </target>

    <!-- This only succeeds when the build is run from this directory -->
    <target name="validate_schema_gen_output" depends="schema-gen">
        <echo message="Looking for: ${data.dir}/${db.name}.script..."/>
        <condition property="dbname.script.present" value="true">
            <available file="${data.dir}/${db.name}.script" property="dbname.script.present"/>
        </condition>
        <fail message="${data.dir}/${db.name}.script is missing!" unless="dbname.script.present"/>
        <echo message="Found it!"/>
    </target>

    <target name="all" depends="validate_schema_gen_output"/>
</project>


./outer/build.xml
------------
Code:
<project name="OUTER" default="go" basedir=".">
    <property name="proj" value="outer"/>
    <property name="proj.root.dir" value="${basedir}"/>
    <property name="inner.proj.dir" value="../inner"/>

    <!-- clean data dir (relative to this project) in case it exists.  It shouldn't be created here anyway! -->
    <target name="clean">
        <delete dir="data"/>
    </target>

    <target name="go" depends="clean">
        <ant dir="${inner.proj.dir}" inheritall="false"/>
    </target>
</project>


RESULTS when run from ./inner (OK)
Quote:
[michael@mkd610 inner]$ ant
Buildfile: build.xml

clean:
[delete] Deleting directory /home/michael/p4/private/mkintzer/hbtoolsbug/inner/build

init:
[mkdir] Created dir: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/build
[delete] Deleting: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/hibernate.log

copy.meta.files:
[copy] Copying 3 files to /home/michael/p4/private/mkintzer/hbtoolsbug/inner/build

schema-gen:
[echo] destdir attribute points to: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data
[echo] deleting old schema files in /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data ...
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] create table EXAMPLE (EXAMPLE_ID integer generated by default as identity (start with 1), aprop varchar(255), primary key (EXAMPLE_ID));

validate_schema_gen_output:
[echo] Looking for: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data/dbname.script...
[echo] Found it!

all:

BUILD SUCCESSFUL
Total time: 3 seconds

Quote:
[michael@mkd610 hbtoolsbug]$ find . -name dbname.script
./inner/data/dbname.script


RESULTS when run from ./outer (BUG)
Quote:
[michael@mkd610 outer]$ ant
Buildfile: build.xml

clean:
[delete] Deleting directory /home/michael/p4/private/mkintzer/hbtoolsbug/outer/data

go:

clean:
[delete] Deleting directory /home/michael/p4/private/mkintzer/hbtoolsbug/inner/build

init:
[mkdir] Created dir: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/build
[delete] Deleting: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/hibernate.log

copy.meta.files:
[copy] Copying 3 files to /home/michael/p4/private/mkintzer/hbtoolsbug/inner/build

schema-gen:
[echo] destdir attribute points to: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data
[echo] deleting old schema files in /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data ...
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] create table EXAMPLE (EXAMPLE_ID integer generated by default as identity (start with 1), aprop varchar(255), primary key (EXAMPLE_ID));

validate_schema_gen_output:
[echo] Looking for: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data/dbname.script...

BUILD FAILED
/home/michael/p4/private/mkintzer/hbtoolsbug/outer/build.xml:12: The following error occurred while executing this line:
/home/michael/p4/private/mkintzer/hbtoolsbug/inner/build.xml:76: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data/dbname.script is missing!

Total time: 3 seconds

Quote:
[michael@mkd610 hbtoolsbug]$ find . -name dbname.script
./outer/data/dbname.script

-----------

Hibernate version: 3.2.0-beta9a
Hibernate Tools version: 3.2.0-beta9a
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="Example" table="EXAMPLE">
        <meta attribute="class-description">
            Each record represents an example
        </meta>

        <id name="id" type="int" column="EXAMPLE_ID">
            <generator class="native"/>
        </id>

        <property name="aprop" type="string">
            <meta attribute="field-description">an example prop</meta>
        </property>
    </class>
</hibernate-mapping>

Name and version of the database you are using: HSQLDB 1.8.0-7

hibernate.properties:
Code:
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:junk/dbname
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.connection.shutdown=true


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 04, 2007 3:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we dont do anything special since it is Ant that is passing us the java.io.File and from that we just do new File(destDir, fileName)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 04, 2007 11:52 am 
Newbie

Joined: Sat Feb 03, 2007 4:26 pm
Posts: 3
Perhaps, but the value passed from ant when run in both cases is identical:

When run from ./inner/build.xml
Quote:
[echo] destdir attribute points to: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data


When run from ./outer/build.xml
Quote:
[echo] destdir attribute points to: /home/michael/p4/private/mkintzer/hbtoolsbug/inner/data


So according to the echo statements, ant in both cases has evaluated destdir to be the same absolute path, yet the output ends up in two different locations depending on where the build was run from.

-Michael


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 12:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
please create a *minimal* .zip with the proper structure and instructions and put it in jira so i can reproduce it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 9:45 pm 
Newbie

Joined: Sat Feb 03, 2007 4:26 pm
Posts: 3
Thanks Max. JIRA bug entered. - Michael
http://opensource.atlassian.com/projects/hibernate/browse/HBX-868


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.