PR: 2053 Submitted by: Peter Janes <peterj@liberate.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269324 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -102,6 +102,9 @@ Other changes: | |||||
| * regexp mapper now supports the java.util.regex package of JDK 1.4. | * regexp mapper now supports the java.util.regex package of JDK 1.4. | ||||
| * New filesonly attribute for <zip> and friends to suppress directory | |||||
| entries. | |||||
| Fixed bugs: | Fixed bugs: | ||||
| ----------- | ----------- | ||||
| @@ -51,6 +51,11 @@ attributes of zipfilesets in a Zip or Jar task.)</p> | |||||
| likely be unreadable for Java otherwise.</strong></td> | likely be unreadable for Java otherwise.</strong></td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">filesonly</td> | |||||
| <td valign="top">Store only file entries, defaults to false</td> | |||||
| <td align="center" valign="top">No</td> | |||||
| </tr> | |||||
| <tr> | <tr> | ||||
| <td valign="top">includes</td> | <td valign="top">includes</td> | ||||
| <td valign="top">comma separated list of patterns of files that must be | <td valign="top">comma separated list of patterns of files that must be | ||||
| @@ -73,6 +73,11 @@ include an empty one for you.)</p> | |||||
| likely be unreadable for Java otherwise.</strong></td> | likely be unreadable for Java otherwise.</strong></td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">filesonly</td> | |||||
| <td valign="top">Store only file entries, defaults to false</td> | |||||
| <td align="center" valign="top">No</td> | |||||
| </tr> | |||||
| <tr> | <tr> | ||||
| <td valign="top">includes</td> | <td valign="top">includes</td> | ||||
| <td valign="top">comma separated list of patterns of files that must be | <td valign="top">comma separated list of patterns of files that must be | ||||
| @@ -53,6 +53,11 @@ attributes of zipfilesets in a Zip or Jar task.)</p> | |||||
| likely be unreadable for Java otherwise.</strong></td> | likely be unreadable for Java otherwise.</strong></td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">filesonly</td> | |||||
| <td valign="top">Store only file entries, defaults to false</td> | |||||
| <td align="center" valign="top">No</td> | |||||
| </tr> | |||||
| <tr> | <tr> | ||||
| <td valign="top">includes</td> | <td valign="top">includes</td> | ||||
| <td valign="top">comma separated list of patterns of files that must be | <td valign="top">comma separated list of patterns of files that must be | ||||
| @@ -74,6 +74,11 @@ Java.</p> | |||||
| Defaults to the platform's default character encoding.</td> | Defaults to the platform's default character encoding.</td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">filesonly</td> | |||||
| <td valign="top">Store only file entries, defaults to false</td> | |||||
| <td align="center" valign="top">No</td> | |||||
| </tr> | |||||
| <tr> | <tr> | ||||
| <td valign="top">includes</td> | <td valign="top">includes</td> | ||||
| <td valign="top">comma separated list of patterns of files that must be | <td valign="top">comma separated list of patterns of files that must be | ||||
| @@ -78,6 +78,7 @@ public class Zip extends MatchingTask { | |||||
| private File zipFile; | private File zipFile; | ||||
| private File baseDir; | private File baseDir; | ||||
| private boolean doCompress = true; | private boolean doCompress = true; | ||||
| private boolean doFilesonly = false; | |||||
| protected String archiveType = "zip"; | protected String archiveType = "zip"; | ||||
| // For directories: | // For directories: | ||||
| private static long emptyCrc = new CRC32 ().getValue (); | private static long emptyCrc = new CRC32 ().getValue (); | ||||
| @@ -114,6 +115,13 @@ public class Zip extends MatchingTask { | |||||
| doCompress = c; | doCompress = c; | ||||
| } | } | ||||
| /** | |||||
| * Emulate Sun's jar utility by not adding parent dirs | |||||
| */ | |||||
| public void setFilesonly(boolean f) { | |||||
| doFilesonly = f; | |||||
| } | |||||
| /** | /** | ||||
| * Adds a set of files (nested fileset attribute). | * Adds a set of files (nested fileset attribute). | ||||
| */ | */ | ||||
| @@ -529,27 +537,28 @@ public class Zip extends MatchingTask { | |||||
| protected void addParentDirs(File baseDir, String entry, | protected void addParentDirs(File baseDir, String entry, | ||||
| ZipOutputStream zOut, String prefix) | ZipOutputStream zOut, String prefix) | ||||
| throws IOException { | throws IOException { | ||||
| Stack directories = new Stack(); | |||||
| int slashPos = entry.length(); | |||||
| while ((slashPos = entry.lastIndexOf((int)'/', slashPos-1)) != -1) { | |||||
| String dir = entry.substring(0, slashPos+1); | |||||
| if (addedDirs.get(prefix+dir) != null) { | |||||
| break; | |||||
| if( !doFilesonly ) { | |||||
| Stack directories = new Stack(); | |||||
| int slashPos = entry.length(); | |||||
| while ((slashPos = entry.lastIndexOf((int)'/', slashPos-1)) != -1) { | |||||
| String dir = entry.substring(0, slashPos+1); | |||||
| if (addedDirs.get(prefix+dir) != null) { | |||||
| break; | |||||
| } | |||||
| directories.push(dir); | |||||
| } | } | ||||
| directories.push(dir); | |||||
| } | |||||
| while (!directories.isEmpty()) { | |||||
| String dir = (String) directories.pop(); | |||||
| File f = null; | |||||
| if (baseDir != null) { | |||||
| f = new File(baseDir, dir); | |||||
| } else { | |||||
| f = new File(dir); | |||||
| while (!directories.isEmpty()) { | |||||
| String dir = (String) directories.pop(); | |||||
| File f = null; | |||||
| if (baseDir != null) { | |||||
| f = new File(baseDir, dir); | |||||
| } else { | |||||
| f = new File(dir); | |||||
| } | |||||
| zipDir(f, zOut, prefix+dir); | |||||
| } | } | ||||
| zipDir(f, zOut, prefix+dir); | |||||
| } | } | ||||
| } | } | ||||