ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleksandr Gavenko <gaven...@gmail.com>
Subject Re: <ftp> target does not fail if file does not exist.
Date Tue, 09 Aug 2011 19:33:03 GMT
04.08.2011 17:55, Stefan Bodewig пишет:
> On 2011-08-02, Oleksandr Gavenko wrote:
>
>> <?xml version="1.0" encoding="windows-1251"?>
>> <project default="test" basedir=".">
>
>>      <target name="test">
>>          <ftp action="get"
>>               server="${ftp.server}"
>>               userid="${ftp.user}"
>>               password="${ftp.password}"
>>               remotedir="/dist">
>>              <fileset file="lib/my.jar"/>
>>          </ftp>
>>        <echo message="xxx"/>
>>      </target>
>> </project>
>
>>    $ ant -f my2.xml -emacs
>> Buildfile: d:\test.xml
>
>> test:
>> getting files
>> 0 files retrieved
>> xxx
>
>> I expect that build fail as 'my.jar' is not exist and 'echo' does not
>> executed.
>
> <fileset>  is the set of files that actually exist limited by the
> patterns you provide.  It won't fail if the file doesn't exist, it is
> its contract to accept that some things you specify may or may not be
> there.
>
> I'm afraid that if you want the task to fail you first have to check the
> file is actually there (doing a list and searching through the output)
> or check it has been downloaded using<available>  after the ftp task.
> I'd go for available.
>
Thanks in interest. I develop solution by using macros:

<?xml version="1.0" encoding="windows-1251"?>
<project default="test" basedir=".">
     <property file="${basedir}/build.properties"/> <!-- ftp settings -->
     <taskdef resource="net/sf/antcontrib/antlib.xml"/>

     <macrodef name="goodftp">
       <attribute name="remotedir"/>
       <attribute name="file"/>
       <sequential>
         <if>
           <not><available file="@{file}"/></not>
           <then>
             <ftp action="get"
                  server="${ftp.server}"
                  userid="${ftp.user}"
                  password="${ftp.password}"
                  remotedir="@{remotedir}">
               <fileset file="@{file}"/>
             </ftp>
             <fail message="Can not get '@{file}' from '@{remotedir}' 
ftp dir.">
               <condition>
                 <not>
                   <available file="@{file}"/>
                 </not>
               </condition>
             </fail>
           </then>
         </if>
       </sequential>
     </macrodef>

     <target name="test">
       <goodftp remotedir="${ftp.dir}/${ftp.ver}/x86_32-windows" 
file="my.cab"/>
       <echo message="xxx"/>
     </target>
</project>

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


Mime
View raw message