You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Stefan Puiu <st...@axetel.com> on 2003/05/13 12:21:15 UTC
checking whether a file is up-to-date
Hello list,
I'm using ant on a project at work that involves JBoss and datasource
specification files that nedd to be deployed. I had a piece of build.xml
code that would do something like this:
<target name="deploy-setup"
description="Deploy the datasource specifications"
depends="output>
<filter filtersfile="${source.resources}/db.properties"/>
<copy file="${source.resources}/mysql/ca-mysql-service.xml"
todir="${jboss.deploy.dir}" filtering="true"/>
<copy file="${source.resources}/mysql/ca-arch-mysql-service.xml"
todir="${jboss.deploy.dir}" filtering="true"/>
<mkdir dir="${jboss.server.home.dir}/conf/eupki/ca"/>
<mkdir dir="${jboss.server.home.dir}/log/eupki/ca"/>
<echo message="Finished deploying the datasource configuration files"/>
<echo message="You still need to edit
$JBOSS_HOME/server/default/conf/login-config.xml b
y hand"/>
<echo message="And add the needed security realms (you'll find an
example in ${source.re
sources}/mysql/cadb-login-config.xml"/>
<echo message="You also need to restart your jboss server"/>
</target>
However, because of the dependencies between tasks, I would get the
message printed each time I would run a target depending on
deploy-setup. Due to the fact (correct me if I'm wrong) that ant is
*much* weaker than make at handling conditional execution (in a makefile
I would have had a simple $(if or $(ifeq or whatever around the echo
lines), I made another target, which checks whether the files are
already deployed and sets a property (have.ds), then I would make the
deploy-setup target run unless have.ds is set. However, if the files
were there but out of date, they wouldn't be overwritten (here I miss
make again)... So I had to copy the files using overwrite, and use
uptodate to check the files in the first place (if they are up-to-date
they don't get copied, if they aren't they do).
The deploy-check target that sets up the have.ds property looks like this:
<target name="deploy-check"
description="Check what's deployed"
depends="init">
...
<condition property="have.ds">
<and>
<available file="${jboss.deploy.dir}/ca-mysql-service.xml"/>
<available file="${jboss.deploy.dir}/ca-arch-mysql-service.xml"/>
<uptodate targetfile="${jboss.deploy.dir}/ca-mysql-service.xml">
<srcfiles dir="${build.resources}/mysql" includes="*.xml"/>
</uptodate>
</and>
</condition>
</target>
My question is: is there a simpler way to do this? Our build.xml files
are starting to get real big, and the approach I've used has the
drawback that sometimes the files get overwritten even though they don't
differ (and that means I need to restart my JBoss server).