ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Joshua" <daniel.jos...@gridnode.com>
Subject Bug with property/propertyfile ?
Date Fri, 18 Jul 2003 12:14:13 GMT
Hi all,

I am not really sure if this is a bug actually.

I used <propertyfile> to write to a file, and then read from that file using
<property file="">,
and write again, then read again, etc.

However, after writing to the file and reading from it,
the value that is read is still the original value sometimes, and not the
recently written one.




Here's my scenario:

I am using ant (with ant-contrib) to build and application and the below is
a snippet of how I try to execute
sql files to setup my database. New sql files are often added, and only the
new ones should be executed.
So I store the filenames of the sql files I have executed to exclude them
from the fileset.





  <!-- initialise the database -->
  <target name="init.db">
    <echo message="[${layer.module}] Executing target: init.db"/>
    <property name="db.file" value="${app.home}/env/db.properties"/>
    <property name="db.file.key"
value="sqlscripts.excluded.${layer.module}"/>
  </target>





  <!-- setting up the database tables -->
  <target name="create.module.db.tables">
    <echo message="[${layer.module}] Executing target:
create.module.db.tables"/>
    <antcall target="process.sqlscripts">
      <param name="includes" value="create-tables.sql"/>
    </antcall>
  </target>





  <!-- populate the database -->
  <target name="populate.module.db.tables">
    <echo message="[${layer.module}] Executing target:
populate.module.db.tables"/>
    <antcall target="process.sqlscripts">
      <param name="includes"
value="insert-metainfo.sql,create-default.sql"/>
    </antcall>
  </target>





  <!-- patch the database -->
  <target name="patch.module.db.tables">
    <echo message="[${layer.module}] Executing target:
patch.module.db.tables"/>
    <antcall target="process.sqlscripts">
      <param name="includes" value="patch*.sql"/>
    </antcall>
  </target>





  <!-- processing sql scripts -->
  <target name="process.sqlscripts">
    <!-- retrieve previously excluded sqlscripts -->
    <property file="${db.file}"/>
    <propertycopy name="excludes"
                  from="${db.file.key}"
                  silent="true"/>

    <!-- fileset of sqlscripts to execute -->
    <property name="dbscript.dir" value="${sqlscripts.dir}/${db.name}"/>
    <fileset id="db.sqlscripts.fileset"
             dir="${dbscript.dir}"
             includes="${includes}"
             excludes="${excludes}"/>

    <if>
      <!-- ... -->
      <then>
        <!-- execute sqlscripts -->
        <apply executable="${layer.dir}/dbscript.bat">
          <arg value="${db.exec.cmd}"/>
          <fileset refid="db.sqlscripts.fileset"/>
        </apply>
      </then>
    </if>

    <!-- record all processed sqlscripts -->
    <trycatch>
      <try>
        <foreach target="record.sqlscript"
                 param="sqlscript.file"
                 inheritall="true">
          <path>
            <fileset refid="db.sqlscripts.fileset"/>
          </path>
        </foreach>
      </try>
      <catch>
        <!-- ignore error caused by empty fileset -->
      </catch>
    </trycatch>
  </target>





  <target name="record.sqlscript">
    <!-- get filename of sqlscript -->
    <basename property="sqlscript.filename" file="${sqlscript.file}"/>
    <echo message="[${layer.module}] Executing target: record.sqlscript for
${sqlscript.filename}"/>

    <!-- retrieve previously excluded sqlscripts -->
    <property file="${db.file}"/>
    <propertycopy name="sqlscripts.excluded"
                  from="${db.file.key}"
                  silent="true"/>

<echo message=" [DEBUG] sqlscripts.excluded ==> ${sqlscripts.excluded}"/>

    <!-- append previously excluded sqlscripts -->
    <if>
      <isset property="sqlscripts.excluded"/>
      <then>
        <property name="sqlscripts.excluded.filenames"
value="${sqlscripts.excluded},${sqlscript.filename}"/>
      </then>
      <else>
        <property name="sqlscripts.excluded.filenames"
value="${sqlscript.filename}"/>
      </else>
    </if>

    <!-- update file -->
    <propertyfile file="${db.file}">
      <entry  key="sqlscripts.excluded.${layer.module}"
value="${sqlscripts.excluded.filenames}"/>
    </propertyfile>
  </target>


Regards,
Daniel


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message