ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peterrei...@apache.org>
Subject Re: AW: AW: how to fail on valid zip file
Date Fri, 08 Oct 2004 16:42:46 GMT
You could do this:
<project default="run" xmlns:ac="antlib:net.sf.antcontrib">
  <macrodef name="fail_on_valid_zip">
    <attribute name="file"/>
    <sequential>
      <mkdir dir="${temp.dir}/ziptest"/>
      <ac:trycatch>
        <ac:try>
          <unzip src="@{file}" dest="${temp.dir}/ziptest"/>
          <property name="@{file}_can_be_unzipped" value="yes"/>
        </ac:try>
        <ac:catch>
          <property name="@{file}_can_be_unzipped" value="no"/>
        </ac:catch>
        <ac:finally>
          <delete dir="${temp.dir}/ziptest"
                  quiet="yes"
                  failonerror="no"/>
        </ac:finally>
      </ac:trycatch>
      <ac:if>
        <equals arg1="@{file}_can_be_unzipped" arg2="yes"/>
        <then>
          <fail>@{file} can be unzipped</fail>
        </then>
      </ac:if>
    </sequential>
  </macrodef>

  <property name="temp.dir" location="tmp"/>

  <target name="run">
    <fail_on_valid_zip file="x.zip"/>
  </target>
</project>


But this does generate a lot of noise:

run:
    [mkdir] Created dir: /home/preilly/learning/a/try/tmp/ziptest
    [unzip] Expanding: /home/preilly/learning/a/try/x.zip into 
/home/preilly/learning/a/try/tmp/ziptest
[ac:trycatch] Caught exception: Error while expanding 
/home/preilly/learning/a/try/x.zip
   [delete] Deleting directory /home/preilly/learning/a/try/tmp/ziptest

So it may be better to write a custom task.

Peter

Jeffrey Bacon wrote:

> here, unzip is throwing the exception and it's seemingly not getting 
> caught, do I need to explicitly catch the BuildException? (with a 
> <catch> block)
>
> Jeffrey Bacon
> jbacon@magmic.com
> Creative Developer
> http://www.magmic.com
>
> Jan.Materne@rzf.fin-nrw.de wrote:
>
>> oh, yes - sorry.
>> In JUnit you work with different Exceptions
>>
>> try {
>>     test...
>>     fail();
>> } catch (MyException) {
>>     // noop
>> }
>>
>> The fail() itself throws an Exception ...
>>
>> Nothing different here, BUT we´re working only with BuildExceptions ...
>>
>> Jan
>>
>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Jeffrey Bacon [mailto:jbacon@magmic.com]
>>> Gesendet am: Freitag, 8. Oktober 2004 17:02
>>> An: Ant Users List
>>> Betreff: Re: AW: how to fail on valid zip file
>>>
>>> It still fails on the invalid ZIP file (which I want it to succeed on):
>>>
>>>     [mkdir] Created dir: C:\workspace\BreakFast\temp\ziptest
>>>     [unzip] Expanding: C:\workspace\BreakFast\bin\BreakFast_res.cod 
>>> into C:\workspace\BreakFast\temp\ziptest
>>>    [delete] Deleting directory C:\workspace\BreakFast\temp\ziptest
>>>
>>> BUILD FAILED
>>> C:\workspace\BreakFast\build.xml:251: Following error occured while 
>>> executing this line
>>> C:\workspace\BreakFast\build.xml:687: Error while expanding 
>>> C:\workspace\BreakFast\bin\BreakFast_res.cod
>>>
>>>
>>> here's my code snippit:
>>>
>>>     <contrib:trycatch>
>>>       <contrib:try>
>>>         <mkdir dir="${basedir}/${temp.dir}/ziptest" />
>>>         <unzip 
>>> src="${basedir}/${bin.dir}/${${project-name}.name}.cod" 
>>> dest="${basedir}/${temp.dir}/ziptest" />
>>>         <contrib:if>
>>>           <contrib:not>
>>>             <contrib:isset property="ignoreSiblingCODs" />
>>>           </contrib:not>
>>>           <contrib:then>
>>>             <fail message="${${project-name}.name}.cod is a sibling 
>>> COD file which will not install OTA on a BES &lt;4.0" />
>>>           </contrib:then>
>>>           <contrib:else>
>>>             <echo level="warn">WARNING: ${${project-name}.name}.cod 
>>> is a sibling COD file which will not install OTA on a BES 
>>> &lt;4.0</echo>
>>>           </contrib:else>
>>>         </contrib:if>
>>>       </contrib:try>
>>>       <contrib:finally>
>>>         <delete dir="${basedir}/${temp.dir}/ziptest"
>>>                 quiet="true"
>>>                 failonerror="false"
>>>                 includeEmptyDirs="true" />
>>>       </contrib:finally>
>>>     </contrib:trycatch>
>>>
>>>
>>> Jeffrey Bacon
>>> jbacon@magmic.com
>>> Creative Developer
>>> http://www.magmic.com
>>>
>>> Jan.Materne@rzf.fin-nrw.de wrote:
>>>
>>>> in unit tests you would do
>>>>
>>>> try {
>>>>   test...
>>>>   fail();
>>>> } catch {
>>>>   // fine
>>>> }
>>>>
>>>> so you can use AntContrib for that
>>>>
>>>> <trycatch>
>>>>    <try>
>>>>        <unzip/>
>>>>        <fail/>
>>>>    </try>
>>>> </trycatch>
>>>>
>>>>
>>>> Jan
>>>>
>>>> > -----Ursprüngliche Nachricht-----
>>>> > Von: Jeffrey Bacon [mailto:jbacon@magmic.com]
>>>> > Gesendet am: Freitag, 8. Oktober 2004 15:46
>>>> > An: Ant Users List
>>>> > Betreff: how to fail on valid zip file
>>>> >
>>>> > During my build process, I want to test a file to see if it
>>>> > is a valid
>>>> > ZIP file.  However, I want to FAIL if it IS valid and succeed
>>>> > if it is
>>>> > NOT valid.  Is there some way I can do this with the unzip task?
>>>> > --
>>>> > Jeffrey Bacon
>>>> > jbacon@magmic.com
>>>> > Creative Developer
>>>> > http://www.magmic.com
>>>> >
>>>> >
>>>>
>>>
>>
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>


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


Mime
View raw message