ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs TarTest.java
Date Mon, 19 Mar 2001 12:44:33 GMT
bodewig     01/03/19 04:44:33

  Modified:    .        WHATSNEW
               src/etc/testcases/taskdefs tar.xml
               src/main/org/apache/tools/ant/taskdefs Tar.java
               src/testcases/org/apache/tools/ant/taskdefs TarTest.java
  Log:
  Make <tar> handle empty directories.
  
  PR:             552
  Submitted by:	William Webber <william@live.com.au>
  
  Revision  Changes    Path
  1.92      +2 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- WHATSNEW	2001/03/19 11:22:43	1.91
  +++ WHATSNEW	2001/03/19 12:44:33	1.92
  @@ -19,6 +19,8 @@
   
   * new magic property build.rmic to chose the rmic implementation
   
  +* <tar> will now add empty directories as well
  +
   Fixed bugs:
   -----------
   
  
  
  
  1.4       +8 -0      jakarta-ant/src/etc/testcases/taskdefs/tar.xml
  
  Index: tar.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/tar.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- tar.xml	2001/03/02 15:57:27	1.3
  +++ tar.xml	2001/03/19 12:44:33	1.4
  @@ -20,8 +20,16 @@
            basedir="."/>
     </target>
   
  +  <target name="test5">
  +    <mkdir dir="test5dir"/>
  +    <tar tarfile="test5.tar"
  +         basedir="."
  +         includes="test5dir"/>
  +  </target>
     
     <target name="cleanup"> 
       <delete file="test4.tar"/>
  +    <delete file="test5.tar"/>
  +    <delete dir="test5dir"/>
     </target>
   </project>
  
  
  
  1.15      +29 -12    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java
  
  Index: Tar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Tar.java	2001/03/02 15:58:18	1.14
  +++ Tar.java	2001/03/19 12:44:33	1.15
  @@ -236,8 +236,10 @@
                              TarFileSet tarFileSet)
           throws IOException
       {
  -        FileInputStream fIn = new FileInputStream(file);
  -
  +        FileInputStream fIn = null;
  +        if (file.isDirectory() && vPath.length() != 0 
  +                && vPath.charAt(vPath.length() - 1) != '/')
  +            vPath = vPath + "/";
           try {
               if (vPath.length() >= TarConstants.NAMELEN) {
                   if (longFileMode.equalsIgnoreCase(OMIT)) {
  @@ -259,26 +261,31 @@
               }
   
               TarEntry te = new TarEntry(vPath);
  -            te.setSize(file.length());
               te.setModTime(file.lastModified());
               if (!file.isDirectory()) {
  +                te.setSize(file.length());
                   te.setMode(tarFileSet.getMode());
  -            }
  +            } 
               te.setUserName(tarFileSet.getUserName());
               te.setGroupName(tarFileSet.getGroup());
               
               tOut.putNextEntry(te);
               
  -            byte[] buffer = new byte[8 * 1024];
  -            int count = 0;
  -            do {
  -                tOut.write(buffer, 0, count);
  -                count = fIn.read(buffer, 0, buffer.length);
  -            } while (count != -1);
  +            if (!file.isDirectory()) {
  +                fIn = new FileInputStream(file);
  +
  +                byte[] buffer = new byte[8 * 1024];
  +                int count = 0;
  +                do {
  +                    tOut.write(buffer, 0, count);
  +                    count = fIn.read(buffer, 0, buffer.length);
  +                } while (count != -1);
  +            }
               
               tOut.closeEntry();        
           } finally {
  -            fIn.close();
  +            if (fIn != null)
  +                fIn.close();
           }
       }
   
  @@ -306,10 +313,20 @@
               super();
           }
           
  +        /**
  +         *  Get a list of files and directories specified in the fileset.
  +         *  @return a list of file and directory names, relative to
  +         *    the baseDir for the project.
  +         */
           public String[] getFiles(Project p) {
               if (files == null) {
                   DirectoryScanner ds = getDirectoryScanner(p);
  -                files = ds.getIncludedFiles();
  +                String[] directories = ds.getIncludedDirectories();
  +                String[] filesPerSe = ds.getIncludedFiles();
  +                files = new String [directories.length + filesPerSe.length];
  +                System.arraycopy(directories, 0, files, 0, directories.length);
  +                System.arraycopy(filesPerSe, 0, files, directories.length,
  +                        filesPerSe.length);
               }
               
               return files;
  
  
  
  1.4       +10 -0     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java
  
  Index: TarTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TarTest.java	2001/03/02 16:00:55	1.3
  +++ TarTest.java	2001/03/19 12:44:33	1.4
  @@ -83,6 +83,16 @@
           expectBuildException("test4", "tar cannot include itself");
       }
   
  +    public void test5() {
  +        executeTarget("test5");
  +        java.io.File f 
  +            = new java.io.File("src/etc/testcases/taskdefs/test5.tar");
  +
  +        if (!f.exists()) {
  +            fail("Tarring a directory failed");
  +        }
  +    }
  +
       public void tearDown() {
           executeTarget("cleanup");
       }
  
  
  

Mime
View raw message