ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs JarTest.java
Date Wed, 02 Apr 2003 16:20:14 GMT
bodewig     2003/04/02 08:20:14

  Modified:    src/etc/testcases/taskdefs jar.xml
               src/testcases/org/apache/tools/ant/taskdefs JarTest.java
  Log:
  Make sure that streams get closed
  
  Revision  Changes    Path
  1.12      +4 -2      ant/src/etc/testcases/taskdefs/jar.xml
  
  Index: jar.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/jar.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- jar.xml	2 Apr 2003 15:53:37 -0000	1.11
  +++ jar.xml	2 Apr 2003 16:20:13 -0000	1.12
  @@ -201,11 +201,13 @@
       <unzip src="${tmp.jar}" dest="${tmp.dir}"/>
     </target>
   
  -  <!-- bug 10262 -->
  -  <target name="testNoDuplicateIndex">
  +  <!-- bugs 10262 and 16972 -->
  +  <target name="testIndexTests">
       <mkdir dir="${tmp.dir}/META-INF"/>
       <touch file="${tmp.dir}/META-INF/INDEX.LIST"/>
       <touch file="${tmp.dir}/foo"/>
  +    <mkdir dir="${tmp.dir}/sub"/>
  +    <touch file="${tmp.dir}/sub/foo"/>
       <jar destfile="${tmp.jar}" index="yes" basedir="${tmp.dir}"/>
     </target>
   </project>
  
  
  
  1.21      +56 -9     ant/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java
  
  Index: JarTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- JarTest.java	2 Apr 2003 15:53:38 -0000	1.20
  +++ JarTest.java	2 Apr 2003 16:20:13 -0000	1.21
  @@ -54,8 +54,11 @@
   
   package org.apache.tools.ant.taskdefs;
   
  +import java.io.BufferedReader;
   import java.io.File;
   import java.io.FileReader;
  +import java.io.InputStream;
  +import java.io.InputStreamReader;
   import java.io.IOException;
   import java.io.Reader;
   import java.util.Date;
  @@ -230,17 +233,61 @@
           assertTrue(jarXml.exists());
       }
   
  +    // bugzilla report 10262
       public void testNoDuplicateIndex() throws IOException {
  -        executeTarget("testNoDuplicateIndex");
  -        ZipFile archive = new ZipFile(getProject().resolveFile(tempJar));
  -        Enumeration enum = archive.entries();
  -        int numberOfIndexLists = 0;
  -        while (enum.hasMoreElements()) {
  -            ZipEntry ze = (ZipEntry) enum.nextElement();
  -            if (ze.getName().equals("META-INF/INDEX.LIST")) {
  -                numberOfIndexLists++;
  +        ZipFile archive = null;
  +        try {
  +            executeTarget("testIndexTests");
  +            archive = new ZipFile(getProject().resolveFile(tempJar));
  +            Enumeration enum = archive.entries();
  +            int numberOfIndexLists = 0;
  +            while (enum.hasMoreElements()) {
  +                ZipEntry ze = (ZipEntry) enum.nextElement();
  +                if (ze.getName().equals("META-INF/INDEX.LIST")) {
  +                    numberOfIndexLists++;
  +                }
  +            }
  +            assertEquals(1, numberOfIndexLists);
  +        } finally {
  +            if (archive != null) {
  +                archive.close();
  +            }
  +        }
  +    }
  +
  +    // bugzilla report 16972
  +    public void XtestRootFilesInIndex() throws IOException {
  +        ZipFile archive = null;
  +        try {
  +            executeTarget("testIndexTests");
  +            archive = new ZipFile(getProject().resolveFile(tempJar));
  +            ZipEntry ze = archive.getEntry("META-INF/INDEX.LIST");
  +            InputStream is = archive.getInputStream(ze);
  +            BufferedReader r = new BufferedReader(new InputStreamReader(is,
  +                                                                        "UTF8"));
  +            boolean foundSub = false;
  +            boolean foundSubFoo = false;
  +            boolean foundFoo = false;
  +            
  +            String line = r.readLine();
  +            while (line != null) {
  +                if (line.equals("foo")) {
  +                    foundFoo = true;
  +                } else if (line.equals("sub")) {
  +                    foundSub = true;
  +                } else if (line.equals("sub/foo")) {
  +                    foundSubFoo = true;
  +                }
  +                line = r.readLine();
  +            }
  +
  +            assertTrue(foundSub);
  +            assertTrue(!foundSubFoo);
  +            assertTrue(foundFoo);
  +        } finally {
  +            if (archive != null) {
  +                archive.close();
               }
           }
  -        assertEquals(1, numberOfIndexLists);
       }
   }
  
  
  

Mime
View raw message