Browse Source

New filesonly attribute for <zip> and friends - suppresses directories.

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-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
e5fcb12320
6 changed files with 51 additions and 19 deletions
  1. +3
    -0
      WHATSNEW
  2. +5
    -0
      docs/manual/CoreTasks/ear.html
  3. +5
    -0
      docs/manual/CoreTasks/jar.html
  4. +5
    -0
      docs/manual/CoreTasks/war.html
  5. +5
    -0
      docs/manual/CoreTasks/zip.html
  6. +28
    -19
      src/main/org/apache/tools/ant/taskdefs/Zip.java

+ 3
- 0
WHATSNEW View File

@@ -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:
----------- -----------




+ 5
- 0
docs/manual/CoreTasks/ear.html View File

@@ -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


+ 5
- 0
docs/manual/CoreTasks/jar.html View File

@@ -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


+ 5
- 0
docs/manual/CoreTasks/war.html View File

@@ -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


+ 5
- 0
docs/manual/CoreTasks/zip.html View File

@@ -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


+ 28
- 19
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -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);
} }
} }




Loading…
Cancel
Save