You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Christopher Styles <st...@gmail.com> on 2008/01/25 19:02:29 UTC

adding an if-then statement to ftp target...

Hi,

I'm using the ant ftp task to ftp files from my local Windows 2003 Build
Server to a remote Unix environment, and the issue I'm facing is the local
folders(s) that contain the files that are to be ftp'ed don't always
exist.... The folder(s) only get created if there are files in them that
have been updated.... If there are no files that have been updated, my build
process doesn't create the folder.... I would like to add an if-then
statement to the target below, so it will ftp the files if the folder
exists, or move on to the next target if the folder doesn't exist.... Can
someone provide an example I could use, please...??? For the most part I
have the target structured the way that I want it, but I don't want to
execute the target if in one instance the folder doesn't exist, and it
causes my deployment to fail.... And that's another question I have, will it
actually cause my deployment to fail if I execute if as is below, or will
attempt to execute then move on if it can't...??? Also, I'm using
the <modified> selector on the fileset, so ant will keep track of changes
made to the local copies of the files, so only the modified files will be
selected for the ftp transfer. So, with that said, will I need the
<modified> selector if I use an if-then statement...??? If someone can point
me in the right direction I'd surely appreciate it...


<target name="lib-ext">
    <ftp server="${remoteHostName}"
        userid="${remoteInstallUserId}" password="${remoteInstallPassword}"
        remotedir="${remoteAppFtpDir}"
        verbose="yes"
        binary="yes"
        action="put"
        chmod="644">
     <fileset dir="${existingApp.dir}">
        <include name="*.jar"/>
        <include name="*.properties"/>
        <include name="*.txt"/>
        <include name="*.xml"/>
        <include name="*.xsd"/>
        <modified>
          <param name="sunt.ext.cachefile"
        value="${tmpDir}/ftp-sunt-lib-ext-cache.properties"/>
        </modified>
     </fileset>
    </ftp>
</target>

Thanks
Chris

Re: adding an if-then statement to ftp target...

Posted by Christopher Styles <st...@gmail.com>.
David,

This is what I came up with... Do you think this will work...???

<target name="lib-ext">
    <ftp server="${remoteHostName}"
        userid="${remoteInstallUserId}" password="${remoteInstallPassword}"
        remotedir="${remoteAppFtpDir}"
        verbose="yes"
        binary="yes"
        action="put"
        chmod="644">
     <fileset dir="${existingExt.dir}">
        <include name="*.jar"/>
        <include name="*.properties"/>
        <include name="*.txt"/>
        <include name="*.xml"/>
        <include name="*.xsd"/>
        <modified>
          <param name="sunt.ext.cachefile"
        value="${tmpDir}/ftp-sunt-lib-ext-cache.properties"/>
        </modified>
     </fileset>
    </ftp>
    <if>
         <available file="${existingExt.dir}" type="dir"/>
         <then>
         <echo message=""/>
         <echo message="The are new file updates, starting ftp..."/>
         <echo message=""/>
      </then>
      <else>
         <echo message=""/>
         <echo message="No file updates found, ftp will not be
performed..."/>
         <echo message=""/>
      </else>
      </if>
</target>

Thanks
Chris


On 1/25/08, David Weintraub <qa...@gmail.com> wrote:
>
> Take a look at the <available> task. To create an if-then type of
> statement, add a dependency to your task that runs a task that tests
> the condition, and have that set a property. Then have your original
> task depend upon that property:
>
> <target name="my-target-test">
>    <available property="folder-exists"
>       file="${folder.name}"/>
> </target>
>
> <target name="my-target"
>    if="folder-exists"
>    depends="my-target-test>
>    <...>
> </target>
>
> Target "my-target" will be executed, but first the dependency target
> "my-target-test" will be executed. If the folder exists, it will set
> the "folder-exists" property. Now, Ant goes back to the "my-target"
> task and checks the dependency. If "folder-exists" is set, "my-target"
> will be executed. Otherwise, it won't.
>
> Another option is to use the AntContrib <if> task. This is a bit
> easier to follow, but you now depend upon installing the AntContrib
> library.
>
> On Jan 25, 2008 1:02 PM, Christopher Styles <st...@gmail.com> wrote:
> > Hi,
> >
> > I'm using the ant ftp task to ftp files from my local Windows 2003 Build
> > Server to a remote Unix environment, and the issue I'm facing is the
> local
> > folders(s) that contain the files that are to be ftp'ed don't always
> > exist.... The folder(s) only get created if there are files in them that
> > have been updated.... If there are no files that have been updated, my
> build
> > process doesn't create the folder.... I would like to add an if-then
> > statement to the target below, so it will ftp the files if the folder
> > exists, or move on to the next target if the folder doesn't exist....
> Can
> > someone provide an example I could use, please...??? For the most part I
> > have the target structured the way that I want it, but I don't want to
> > execute the target if in one instance the folder doesn't exist, and it
> > causes my deployment to fail.... And that's another question I have,
> will it
> > actually cause my deployment to fail if I execute if as is below, or
> will
> > attempt to execute then move on if it can't...??? Also, I'm using
> > the <modified> selector on the fileset, so ant will keep track of
> changes
> > made to the local copies of the files, so only the modified files will
> be
> > selected for the ftp transfer. So, with that said, will I need the
> > <modified> selector if I use an if-then statement...??? If someone can
> point
> > me in the right direction I'd surely appreciate it...
> >
> >
> > <target name="lib-ext">
> >     <ftp server="${remoteHostName}"
> >         userid="${remoteInstallUserId}"
> password="${remoteInstallPassword}"
> >         remotedir="${remoteAppFtpDir}"
> >         verbose="yes"
> >         binary="yes"
> >         action="put"
> >         chmod="644">
> >      <fileset dir="${existingApp.dir}">
> >         <include name="*.jar"/>
> >         <include name="*.properties"/>
> >         <include name="*.txt"/>
> >         <include name="*.xml"/>
> >         <include name="*.xsd"/>
> >         <modified>
> >           <param name="sunt.ext.cachefile"
> >         value="${tmpDir}/ftp-sunt-lib-ext-cache.properties"/>
> >         </modified>
> >      </fileset>
> >     </ftp>
> > </target>
> >
> > Thanks
> > Chris
> >
>
>
>
> --
> --
> David Weintraub
> qazwart@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Re: adding an if-then statement to ftp target...

Posted by David Weintraub <qa...@gmail.com>.
Take a look at the <available> task. To create an if-then type of
statement, add a dependency to your task that runs a task that tests
the condition, and have that set a property. Then have your original
task depend upon that property:

<target name="my-target-test">
    <available property="folder-exists"
       file="${folder.name}"/>
</target>

<target name="my-target"
    if="folder-exists"
    depends="my-target-test>
    <...>
</target>

Target "my-target" will be executed, but first the dependency target
"my-target-test" will be executed. If the folder exists, it will set
the "folder-exists" property. Now, Ant goes back to the "my-target"
task and checks the dependency. If "folder-exists" is set, "my-target"
will be executed. Otherwise, it won't.

Another option is to use the AntContrib <if> task. This is a bit
easier to follow, but you now depend upon installing the AntContrib
library.

On Jan 25, 2008 1:02 PM, Christopher Styles <st...@gmail.com> wrote:
> Hi,
>
> I'm using the ant ftp task to ftp files from my local Windows 2003 Build
> Server to a remote Unix environment, and the issue I'm facing is the local
> folders(s) that contain the files that are to be ftp'ed don't always
> exist.... The folder(s) only get created if there are files in them that
> have been updated.... If there are no files that have been updated, my build
> process doesn't create the folder.... I would like to add an if-then
> statement to the target below, so it will ftp the files if the folder
> exists, or move on to the next target if the folder doesn't exist.... Can
> someone provide an example I could use, please...??? For the most part I
> have the target structured the way that I want it, but I don't want to
> execute the target if in one instance the folder doesn't exist, and it
> causes my deployment to fail.... And that's another question I have, will it
> actually cause my deployment to fail if I execute if as is below, or will
> attempt to execute then move on if it can't...??? Also, I'm using
> the <modified> selector on the fileset, so ant will keep track of changes
> made to the local copies of the files, so only the modified files will be
> selected for the ftp transfer. So, with that said, will I need the
> <modified> selector if I use an if-then statement...??? If someone can point
> me in the right direction I'd surely appreciate it...
>
>
> <target name="lib-ext">
>     <ftp server="${remoteHostName}"
>         userid="${remoteInstallUserId}" password="${remoteInstallPassword}"
>         remotedir="${remoteAppFtpDir}"
>         verbose="yes"
>         binary="yes"
>         action="put"
>         chmod="644">
>      <fileset dir="${existingApp.dir}">
>         <include name="*.jar"/>
>         <include name="*.properties"/>
>         <include name="*.txt"/>
>         <include name="*.xml"/>
>         <include name="*.xsd"/>
>         <modified>
>           <param name="sunt.ext.cachefile"
>         value="${tmpDir}/ftp-sunt-lib-ext-cache.properties"/>
>         </modified>
>      </fileset>
>     </ftp>
> </target>
>
> Thanks
> Chris
>



-- 
--
David Weintraub
qazwart@gmail.com

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