Ant won't load relative changeLogs when called from a different folder

Hi,

Just setting up some simple ant tasks for unit testing my schema scripts - however there is an issue.

I have a top-level install changeLog in a folder src/repository/schema/install.xml that looks like this:

    <?xml version="1.0" encoding="UTF-8"?> http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">    

i.e. it contains an includeAll path relative to the location of the install.xml file. This runs fine if run from the command line in the src/repository/schema folder.

Now, my ant build.xml script is running from a folder one level up from this, i.e. src/repository. It contains the following basic task:

    <path id="lib.path">
    	<pathelement location="${src.java.lib.dir}/liquibase.jar" />
    	<pathelement location="${src.java.lib.dir}/jtds-1.2.5.jar" />
    	<pathelement path="${schema.dir}" />
    </path>
    
    <taskdef resource="liquibasetasks.properties">
    	<classpath refid="lib.path" />
    </taskdef>
    
    <target name="install-db" description="Updates DB">
    
    	<updateDatabase changeLogFile="${install.changelog.file}"
    	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; driver="${database.driver}"
    	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url="${database.url}"
    	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; username="${database.username}"
    	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; password="${database.password}"
    	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; defaultSchemaName="${database.username}"
    	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; promptOnNonLocalDatabase="false"
    	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dropFirst="false"
    	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; classpathref="lib.path" />
    
    </target></ol>
    

    The problem I have is that when this is run, the includeAll tag fails with the following error:

      install-db: [updateDatabase] Jul 28, 2010 12:03:16 PM liquibase.logging.jvm.JavaUtilLogger info [updateDatabase] INFO: Successfully acquired change log lock [updateDatabase] Jul 28, 2010 12:03:17 PM liquibase.logging.jvm.JavaUtilLogger severe [updateDatabase] SEVERE: Error thrown as a SAXException: Could not find directory or directory was empty for includeAll 'install/tab/' [updateDatabase] org.xml.sax.SAXException: Could not find directory or directory was empty for includeAll 'install/tab/' [updateDatabase] at liquibase.parser.core.xml.XMLChangeLogSAXHandler.startElement(XMLChangeLogSAXHandler.java:219)

    i.e. it can no longer determine the relative folder with respect to the initial install.xml file. To workaround this, I either have to use absolute pathnames (not ideal), or I have to move my build.xml to the same folder as the install.xml liquibase changeLogs. This also isn’t ideal. Is there a way that I can get the ant task to correctly change to the databaseChangeLog folder prior to processing the changeLogs? I guess one solution would be to allow the various ant tasks to take a databaseChangeLogFolder/relativeBaseDir property or somesuch - and if defined, to change to this/resolve relative pathnames appropriately.

    I’m happy to raise this as an issue if you think it worth resolving.

    Many thanks.

    Ben

You need to add the relativeToChangelogFile=“true” attribute to includeAll.  By default, liquibase assumes all paths are from the root of the classpath and there is no way we can know you mean relative to the changelog file without telling it.

Nathan

Of course!

Thanks Nathan

Ben