cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java

2004-10-30 Thread stevel
stevel  2004/10/30 12:44:02

  Modified:docs/manual/CoreTasks unzip.html
   src/etc/testcases/taskdefs unzip.xml
   src/main/org/apache/tools/ant/taskdefs Expand.java
Untar.java
   src/main/org/apache/tools/zip ZipFile.java
   src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java
  Log:
  Patch in PR# 21996
  add a flatten to unzip.
  I actually only patched in the mapper nested element support; with that the 
flatten attribute can only introduce inconsistency (what if you spec a mapper 
and flatten=true).
  And the patch was modified to keep the attributes private, with a getMapper() 
operation for subclasses (like untar) to get when needed.
  Did a bit of cleanup -especially of the unzip tests- while at it.
  
  Revision  ChangesPath
  1.14  +14 -1 ant/docs/manual/CoreTasks/unzip.html
  
  Index: unzip.html
  ===
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/unzip.html,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- unzip.html9 Feb 2004 21:50:06 -   1.13
  +++ unzip.html30 Oct 2004 19:44:02 -  1.14
  @@ -15,9 +15,12 @@
   pa href=../CoreTypes/patternset.htmlPatternSet/as are used to select 
files to extract
   Ifrom/I the archive.  If no patternset is used, all files are extracted.
   /p
  -pa href=../CoreTypes/fileset.htmlFileSet/as may be used used to 
select archived files
  +pa href=../CoreTypes/fileset.htmlFileSet/as may be used to select 
archived files
   to perform unarchival upon.
   /p
  +pYou can define filename transformations by using a nested a 
href=../CoreTypes/mapper.htmlmapper/a element.  The default mapper is the
  +a href=../CoreTypes/mapper.html#identity-mapperidentity mapper/a.
  +/p
   pFile permissions will not be restored on extracted files./p
   pThe untar task recognizes the long pathname entries used by GNU tar.p
   h3Parameters/h3
  @@ -99,6 +102,16 @@
   lt;include name=quot;**/*.zipquot;/gt;
   lt;exclude name=quot;**/tmp*.zipquot;/gt;
   lt;/filesetgt;
  +lt;/unzipgt;
  +/pre/p
  +/blockquote
  +blockquote
  +ppre
  +lt;unzip src=quot;apache-ant-bin.zipquot; 
dest=quot;${tools.home}quot;gt;
  +lt;patternsetgt;
  +lt;include name=quot;apache-ant/lib/ant.jarquot;/gt;
  +lt;/patternsetgt;
  +lt;mapper type=quot;flattenquot;/gt;
   lt;/unzipgt;
   /pre/p
   /blockquote
  
  
  
  1.10  +29 -0 ant/src/etc/testcases/taskdefs/unzip.xml
  
  Index: unzip.xml
  ===
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/unzip.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- unzip.xml 21 Aug 2003 17:45:12 -  1.9
  +++ unzip.xml 30 Oct 2004 19:44:02 -  1.10
  @@ -93,4 +93,33 @@
   unzip src=unziptest.zip dest=unziptestout encoding=UnicodeBig/
 /target
   
  +  !-- Bugzilla Report 21996 --
  +  target name=testFlattenMapper depends=prepareTestZip
  +unzip dest=unziptestout src=unziptest.zip
  +  patternset
  +include name=1/**/
  +  /patternset
  +  mapper type=flatten/
  +/unzip
  +  /target
  +
  +  !-- Bugzilla Report 21996 --
  +  target name=testGlobMapper depends=prepareTestZip
  +unzip dest=unziptestout src=unziptest.zip
  +  patternset
  +include name=1/**/
  +  /patternset
  +  mapper type=glob from=* to=*.txt/
  +/unzip
  +  /target
  +
  +  target name=testTwoMappers depends=prepareTestZip
  +unzip dest=unziptestout src=unziptest.zip
  +  patternset
  +include name=1/**/
  +  /patternset
  +  mapper type=glob from=* to=*.txt/
  +  mapper type=flatten/  
  +/unzip
  +  /target
   /project
  
  
  
  1.54  +62 -12ant/src/main/org/apache/tools/ant/taskdefs/Expand.java
  
  Index: Expand.java
  ===
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Expand.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- Expand.java   9 Mar 2004 16:48:04 -   1.53
  +++ Expand.java   30 Oct 2004 19:44:02 -  1.54
  @@ -30,9 +30,13 @@
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.FileSet;
  +import org.apache.tools.ant.types.Mapper;
   import org.apache.tools.ant.types.PatternSet;
   import org.apache.tools.ant.types.selectors.SelectorUtils;
  +import org.apache.tools.ant.util.FileNameMapper;
   import org.apache.tools.ant.util.FileUtils;
  +import org.apache.tools.ant.util.FlatFileNameMapper;
  +import org.apache.tools.ant.util.IdentityMapper;
   import org.apache.tools.zip.ZipEntry;
   import org.apache.tools.zip.ZipFile;
   
  @@ -50,12 +54,14 @@
   private File dest; //req
   

cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java

2003-07-03 Thread bodewig
bodewig 2003/07/03 01:30:12

  Modified:src/main/org/apache/tools/ant/taskdefs Expand.java
   src/main/org/apache/tools/zip ZipFile.java
   src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java
  Log:
  Finish implementation of ZipFile, use it in Expand (AKA unzip).
  
  Revision  ChangesPath
  1.44  +11 -41ant/src/main/org/apache/tools/ant/taskdefs/Expand.java
  
  Index: Expand.java
  ===
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Expand.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- Expand.java   23 Jun 2003 14:56:32 -  1.43
  +++ Expand.java   3 Jul 2003 08:30:11 -   1.44
  @@ -56,16 +56,13 @@
   
   import java.io.File;
   import java.io.FileInputStream;
  -import java.io.RandomAccessFile;
   import java.io.FileOutputStream;
   import java.io.FileNotFoundException;
   import java.io.InputStream;
   import java.io.IOException;
  -import java.util.Arrays;
   import java.util.Date;
  +import java.util.Enumeration;
   import java.util.Vector;
  -import java.util.zip.ZipInputStream;
  -import java.util.zip.ZipEntry;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.Project;
  @@ -74,6 +71,8 @@
   import org.apache.tools.ant.types.PatternSet;
   import org.apache.tools.ant.types.selectors.SelectorUtils;
   import org.apache.tools.ant.util.FileUtils;
  +import org.apache.tools.zip.ZipEntry;
  +import org.apache.tools.zip.ZipFile;
   
   /**
* Unzip a file.
  @@ -154,37 +153,13 @@
*/
   protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
   log(Expanding:  + srcF +  into  + dir, Project.MSG_INFO);
  -ZipInputStream zis = null;
  -FileInputStream fis = null;
  -RandomAccessFile raf = null;
  -byte[] buff = new byte[MARKER_SIZE];
  +ZipFile zf = null;
   try {
  -raf = new RandomAccessFile(srcF, r);
  -long offset = 0;
  -int more = raf.read(buff);
  -boolean foundMarker = false;
  -while (more != -1 || offset  MAX_LOOKAHEAD) {
  -if (Arrays.equals(buff, ZIPMARKER)) {
  -foundMarker = true;
  -break;
  -}
  -raf.seek(++offset);
  -more = raf.read(buff);
  -}
  -raf.close();
  -raf = null;
  -
  -fis = new FileInputStream(srcF);
  -if (foundMarker  offset  0) {
  -log(found a preamble of  + offset 
  -+  bytes, probably a self-extracting archive);
  -fis.skip(offset);
  -}
  -
  -zis = new ZipInputStream(fis);
  -ZipEntry ze = null;
  -while ((ze = zis.getNextEntry()) != null) {
  -extractFile(fileUtils, srcF, dir, zis,
  +zf = new ZipFile(srcF, UTF8);
  +Enumeration enum = zf.getEntries();
  +while (enum.hasMoreElements()) {
  +ZipEntry ze = (ZipEntry) enum.nextElement();
  +extractFile(fileUtils, srcF, dir, zf.getInputStream(ze),
   ze.getName(), new Date(ze.getTime()),
   ze.isDirectory());
   }
  @@ -194,14 +169,9 @@
   throw new BuildException(Error while expanding  + 
srcF.getPath(),
ioe);
   } finally {
  -if (raf != null) {
  -try {
  -raf.close();
  -} catch (IOException e) {}
  -}
  -if (zis != null) {
  +if (zf != null) {
   try {
  -zis.close();
  +zf.close();
   } catch (IOException e) {}
   }
   }
  
  
  
  1.2   +87 -2 ant/src/main/org/apache/tools/zip/ZipFile.java
  
  Index: ZipFile.java
  ===
  RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipFile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ZipFile.java  2 Jul 2003 14:36:14 -   1.1
  +++ ZipFile.java  3 Jul 2003 08:30:11 -   1.2
  @@ -63,6 +63,8 @@
   import java.util.Date;
   import java.util.Enumeration;
   import java.util.Hashtable;
  +import java.util.zip.Inflater;
  +import java.util.zip.InflaterInputStream;
   import java.util.zip.ZipException;
   
   /**
  @@ -202,7 +204,22 @@
*/
   public InputStream getInputStream(ZipEntry ze)
   throws IOException, ZipException {
  -return null;
  +Long start = (Long) dataOffsets.get(ze);
  +if (start == null) {
  +

cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java

2003-06-23 Thread bodewig
bodewig 2003/06/23 07:47:02

  Modified:src/etc/testcases/taskdefs unzip.xml
   src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java
  Log:
  Demonstrate Bugzilla Report 20969
  
  Revision  ChangesPath
  1.6   +10 -0 ant/src/etc/testcases/taskdefs/unzip.xml
  
  Index: unzip.xml
  ===
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/unzip.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- unzip.xml 24 Apr 2003 13:02:56 -  1.5
  +++ unzip.xml 23 Jun 2003 14:47:02 -  1.6
  @@ -68,4 +68,14 @@
   mkdir dir=unziptestout/
   unzip dest=unziptestout src=zip/test.exe/
 /target
  +
  +  !-- Bugzilla Report 20969 --
  +  target name=testPatternSetSlashOnly depends=prepareTestZip
  +unzip dest=unziptestout src=unziptest.zip
  +  patternset
  +include name=2//
  +  /patternset
  +/unzip
  +  /target
  +
   /project
  
  
  
  1.10  +12 -0 
ant/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java
  
  Index: UnzipTest.java
  ===
  RCS file: 
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/UnzipTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- UnzipTest.java24 Apr 2003 13:02:57 -  1.9
  +++ UnzipTest.java23 Jun 2003 14:47:02 -  1.10
  @@ -143,4 +143,16 @@
   + probably a self-extracting archive);
   }
   
  +
  +/*
  + * PR 20969
  + */
  +public void testPatternSetSlashOnly() {
  +executeTarget(testPatternSetSlashOnly);
  +assertTrue(1/foo is not included,
  +   !getProject().resolveFile(unziptestout/1/foo).exists());
  +assertTrue(2/bar is included,
  +   getProject().resolveFile(unziptestout/2/bar).exists());
  +}
  +
   }
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java

2003-04-24 Thread bodewig
bodewig 2003/04/24 06:02:57

  Modified:.WHATSNEW
   src/etc/testcases/taskdefs unzip.xml
   src/main/org/apache/tools/ant/taskdefs Expand.java
   src/testcases/org/apache/tools/ant/taskdefs UnzipTest.java
  Added:   src/etc/testcases/taskdefs/zip test.exe
  Log:
  unzip can now deal with self-extracting archives.
  
  PR: 16213
  Submitted by: Jason Salter jasonsalter at hotmail dot com
  
  Revision  ChangesPath
  1.405 +3 -0  ant/WHATSNEW
  
  Index: WHATSNEW
  ===
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.404
  retrieving revision 1.405
  diff -u -r1.404 -r1.405
  --- WHATSNEW  24 Apr 2003 09:11:38 -  1.404
  +++ WHATSNEW  24 Apr 2003 13:02:53 -  1.405
  @@ -273,6 +273,9 @@
   
   * A wrapper script for OS/2 has been added.
   
  +* unzip will now detect and successfully extract self-extracting
  +  archives.  Bugzilla Report 16213.
  +
   Changes from Ant 1.5.2 to Ant 1.5.3
   ===
   
  
  
  
  1.5   +5 -0  ant/src/etc/testcases/taskdefs/unzip.xml
  
  Index: unzip.xml
  ===
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/unzip.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- unzip.xml 7 Feb 2003 14:59:06 -   1.4
  +++ unzip.xml 24 Apr 2003 13:02:56 -  1.5
  @@ -63,4 +63,9 @@
 /patternset
   /unzip
 /target
  +
  +  target name=selfExtractingArchive
  +mkdir dir=unziptestout/
  +unzip dest=unziptestout src=zip/test.exe/
  +  /target
   /project
  
  
  
  1.1  ant/src/etc/testcases/taskdefs/zip/test.exe
  
Binary file
  
  
  1.42  +40 -7 ant/src/main/org/apache/tools/ant/taskdefs/Expand.java
  
  Index: Expand.java
  ===
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Expand.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- Expand.java   7 Mar 2003 11:23:01 -   1.41
  +++ Expand.java   24 Apr 2003 13:02:56 -  1.42
  @@ -56,14 +56,16 @@
   
   import java.io.File;
   import java.io.FileInputStream;
  -import java.io.FileNotFoundException;
  +import java.io.RandomAccessFile;
   import java.io.FileOutputStream;
  -import java.io.IOException;
  +import java.io.FileNotFoundException;
   import java.io.InputStream;
  +import java.io.IOException;
  +import java.util.Arrays;
   import java.util.Date;
   import java.util.Vector;
  -import java.util.zip.ZipEntry;
   import java.util.zip.ZipInputStream;
  +import java.util.zip.ZipEntry;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.Project;
  @@ -78,6 +80,7 @@
* @author [EMAIL PROTECTED]
* @author Stefan Bodewig
* @author Magesh Umasankar
  + * @author a href=mailto:[EMAIL PROTECTED]Jason Salter/a
*
* @since Ant 1.1
*
  @@ -92,6 +95,9 @@
   private boolean overwrite = true;
   private Vector patternsets = new Vector();
   private Vector filesets = new Vector();
  +private static final byte[] ZIPMARKER = {0x50, 0x4b, 0x03, 0x04};
  +private static final int MARKER_SIZE = ZIPMARKER.length;
  +private static final int MAX_LOOKAHEAD = 50 * 1024; // 50K.
   
   /**
* Do the work.
  @@ -148,11 +154,34 @@
   protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
   log(Expanding:  + srcF +  into  + dir, Project.MSG_INFO);
   ZipInputStream zis = null;
  +FileInputStream fis = null;
  +RandomAccessFile raf = null;
  +byte[] buff = new byte[MARKER_SIZE];
   try {
  -// code from WarExpand
  -zis = new ZipInputStream(new FileInputStream(srcF));
  -ZipEntry ze = null;
  +raf = new RandomAccessFile(srcF, r);
  +long offset = 0;
  +int more = raf.read(buff);
  +boolean foundMarker = false;
  +while (more != -1 || offset  MAX_LOOKAHEAD) {
  +if (Arrays.equals(buff, ZIPMARKER)) {
  +foundMarker = true;
  +break;
  +}
  +raf.seek(++offset);
  +more = raf.read(buff);
  +}
  +raf.close();
  +raf = null;
   
  +fis = new FileInputStream(srcF);
  +if (foundMarker  offset  0) {
  +log(found a preamble of  + offset 
  ++  bytes, probably a self-extracting archive);
  +fis.skip(offset);
  +}
  +
  +zis = new ZipInputStream(fis);
  +ZipEntry ze = null;
   while ((ze = zis.getNextEntry()) !=