git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273617 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -68,7 +68,11 @@ import java.util.zip.ZipException; | |||||
| */ | */ | ||||
| public class ZipEntry extends java.util.zip.ZipEntry { | 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 internalAttributes = 0; | ||||
| private int platform = PLATFORM_FAT; | |||||
| private long externalAttributes = 0; | private long externalAttributes = 0; | ||||
| private Vector extraFields = new Vector(); | private Vector extraFields = new Vector(); | ||||
| @@ -186,6 +190,32 @@ public class ZipEntry extends java.util.zip.ZipEntry { | |||||
| externalAttributes = 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 "version made | |||||
| * by" 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; | |||||
| } | |||||
| /** | /** | ||||
| * Replaces all currently attached extra fields with the new array. | * Replaces all currently attached extra fields with the new array. | ||||
| * | * | ||||
| @@ -519,7 +519,7 @@ public class ZipOutputStream extends DeflaterOutputStream { | |||||
| written += 4; | written += 4; | ||||
| // version made by | // version made by | ||||
| out.write((new ZipShort(20)).getBytes()); | |||||
| out.write((new ZipShort((ze.getPlatform() << 8) | 20)).getBytes()); | |||||
| written += 2; | written += 2; | ||||
| // version needed to extract | // version needed to extract | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
| @@ -121,4 +121,22 @@ public class ZipEntryTest extends TestCase { | |||||
| } catch (java.util.NoSuchElementException nse) { | } 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); | |||||
| } | |||||
| } | } | ||||