ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject Re: easier way to conditionally copy file? / write my own task?
Date Fri, 12 Oct 2001 19:49:13 GMT
As a general rule-of-thumb, when I find myself creating targets that are
essentially doing the same thing, I probably want to start thinking about
creating a target to <antcall> to. For example, in your case (btw: I've
set the dirs into properties, but you don't really have to do that -- I
just find it easier to deal with):

  <property name="tomcat.fms.classes" value="foodir"/>
  <property name="was.fms.dev.home" value="foodir"/>
  <property name="was.fms.test.home" value="foodir"/>
  <property name="tomcat.classes"
            value="${tomcat.fms.classes}/com/sprint/fms"/>
  <property name="dev.home"
            value="${was.fms.dev.home}/classes/resource/com/sprint/fms"/>
  <property name="test.home"
            value="${was.fms.test.home}/classes/resource"/>
  <property name="sprint.fms" value="src/com/sprint/fms"/>
  <property name="sprint.com" value="src/com/sprint/com"/>

  <target name="copyFiles">
    <antcall target="doCopy">
      <param name="dir" value="${sprint.fms}"/>
      <param name="todir" value="${tomcat.classes}"/>
    </antcall>
    <antcall target="doCopy">
      <param name="dir" value="${sprint.fms}"/>
      <param name="todir" value="${dev.home}"/>
    </antcall>
    <antcall target="doCopy">
      <param name="dir" value="${sprint.com}"/>
      <param name="todir" value="${test.home}"/>
    </antcall>
  </target>

  <target name="doCopy" depends="checkFile" unless="constantsAvailable">
    <copy file="${dir}/constants-defaults.properties"
          tofile="${todir}/constants.properties"/>
  </target>

  <target name="checkFile">
    <condition property="constantsAvailable">
      <available file="${todir}/constants.properties"/>
    </condition>
  </target>

If you need to add additional files to check for, just add an <antcall>
for them. If it turns out the filenames won't always be the same, add a
(eg.) "file" parameter to pass as well (ie., changing things like
file="${dir}/constants-defaults.properties" to file="${dir}/${file}").

Diane


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

Mime
View raw message