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/zip ZipEntryTest.java
Date Fri, 06 Dec 2002 16:17:37 GMT
bodewig     2002/12/06 08:17:37

  Modified:    src/main/org/apache/tools/zip ZipEntry.java
                        ZipOutputStream.java
               src/testcases/org/apache/tools/zip ZipEntryTest.java
  Log:
  getting close to Info-Zip now, will enable it next week
  
  Revision  Changes    Path
  1.4       +31 -1     jakarta-ant/src/main/org/apache/tools/zip/ZipEntry.java
  
  Index: ZipEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/zip/ZipEntry.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ZipEntry.java	15 Apr 2002 12:11:52 -0000	1.3
  +++ ZipEntry.java	6 Dec 2002 16:17:36 -0000	1.4
  @@ -68,7 +68,11 @@
    */
   public class ZipEntry extends java.util.zip.ZipEntry {
   
  +    private static final int PLATFORM_UNIX = 3;
  +    private static final int PLATFORM_FAT  = 0;
  +
       private int internalAttributes = 0;
  +    private int platform = PLATFORM_FAT;
       private long externalAttributes = 0;
       private Vector extraFields = new Vector();
   
  @@ -184,6 +188,32 @@
        */
       public void setExternalAttributes(long value) {
           externalAttributes = value;
  +    }
  +
  +    /**
  +     * Sets Unix permissions in a way that is understood by Info-Zip's
  +     * unzip command.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void setUnixMode(int mode) {
  +        setExternalAttributes((mode << 16)
  +                              // MS-DOS directory flag
  +                              | (isDirectory() ? 0x10 : 0));
  +        platform = PLATFORM_UNIX;
  +    }
  +
  +    /**
  +     * Platform specification to put into the &quot;version made
  +     * by&quot; part of the central file header.
  +     *
  +     * @return 0 (MS-DOS FAT) unless {@link #setUnixMode setUnixMode}
  +     * has been called, in which case 3 (Unix) will be returned.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public int getPlatform() {
  +        return platform;
       }
   
       /**
  
  
  
  1.8       +2 -2      jakarta-ant/src/main/org/apache/tools/zip/ZipOutputStream.java
  
  Index: ZipOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/zip/ZipOutputStream.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ZipOutputStream.java	15 Apr 2002 14:56:34 -0000	1.7
  +++ ZipOutputStream.java	6 Dec 2002 16:17:36 -0000	1.8
  @@ -519,7 +519,7 @@
           written += 4;
   
           // version made by
  -        out.write((new ZipShort(20)).getBytes());
  +        out.write((new ZipShort((ze.getPlatform() << 8) | 20)).getBytes());
           written += 2;
   
           // version needed to extract
  
  
  
  1.2       +19 -1     jakarta-ant/src/testcases/org/apache/tools/zip/ZipEntryTest.java
  
  Index: ZipEntryTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/zip/ZipEntryTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ZipEntryTest.java	23 Apr 2001 16:12:25 -0000	1.1
  +++ ZipEntryTest.java	6 Dec 2002 16:17:36 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -121,4 +121,22 @@
           } catch (java.util.NoSuchElementException nse) {
           }
       }
  +
  +    public void testUnixMode() {
  +        ZipEntry ze = new ZipEntry("foo");
  +        assertEquals(0, ze.getPlatform());
  +        ze.setUnixMode(0755);
  +        assertEquals(3, ze.getPlatform());
  +        assertEquals(0755, 
  +                     (ze.getExternalAttributes() >> 16) & 0xFFFF);
  +        assertEquals(0, ze.getExternalAttributes()  & 0xFFFF);
  +
  +        ze = new ZipEntry("foo/");
  +        ze.setUnixMode(0577);
  +        assertEquals(3, ze.getPlatform());
  +        assertEquals(0577, 
  +                     (ze.getExternalAttributes() >> 16) & 0xFFFF);
  +        assertEquals(0x10, ze.getExternalAttributes()  & 0xFFFF);
  +    }
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message