diff --git a/src/main/org/apache/tools/ant/taskdefs/War.java b/src/main/org/apache/tools/ant/taskdefs/War.java index fc3930e38..9a18a6ef3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/War.java +++ b/src/main/org/apache/tools/ant/taskdefs/War.java @@ -73,7 +73,6 @@ public class War extends Jar { private Vector libFileSets = new Vector(); private Vector classesFileSets = new Vector(); private Vector webInfFileSets = new Vector(); - private Vector locFileSets = new Vector(); public War() { super(); @@ -101,24 +100,6 @@ public class War extends Jar { webInfFileSets.addElement(fs); } - /** - * FileSet with an additional prefix attribute to specify the - * location we want to move the files to (inside the archive). - */ - public static class PrefixedFileSet extends FileSet { - private String prefix = ""; - - public void setPrefix(String loc) { - prefix = loc; - } - - public String getPrefix() {return prefix;} - } - - public void addPrefixedFileSet(PrefixedFileSet fs) { - locFileSets.addElement(fs); - } - /** * Add the deployment descriptor as well as all files added the * special way of nested lib, classes or webinf filesets. @@ -138,7 +119,6 @@ public class War extends Jar { addFiles(libFileSets, zOut, "WEB-INF/lib/"); addFiles(classesFileSets, zOut, "WEB-INF/classes/"); addFiles(webInfFileSets, zOut, "WEB-INF/"); - addPrefixedFiles(locFileSets, zOut); super.initZipOutputStream(zOut); } @@ -156,8 +136,7 @@ public class War extends Jar { + 1 // web.xml + libFileSets.size() + classesFileSets.size() - + webInfFileSets.size() - + locFileSets.size()]; + + webInfFileSets.size()]; System.arraycopy(scanners, 0, myScanners, 0, scanners.length); @@ -172,9 +151,6 @@ public class War extends Jar { classesFileSets); addScanners(myScanners, scanners.length+1+libFileSets.size()+classesFileSets.size(), webInfFileSets); - addScanners(myScanners, scanners.length + 1 + libFileSets.size() - +classesFileSets.size()+webInfFileSets.size(), - locFileSets); return super.isUpToDate(myScanners, zipFile); } @@ -190,49 +166,4 @@ public class War extends Jar { "(please use webxml attribute to "+archiveType+" task)", Project.MSG_WARN); } } - - /** - * Add a DirectoryScanner for each FileSet included in fileSets to scanners - * starting with index startIndex. - */ - protected void addScanners(FileScanner[] scanners, int startIndex, - Vector fileSets) { - for (int i=0; i 0 - && !prefix.endsWith("/") - && !prefix.endsWith("\\")) { - prefix += "/"; - } - zipDir(null, zOut, prefix); - addFiles(ds, zOut, prefix); - } - } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java index 5a31d2bd4..b1cd097d5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Zip.java +++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java @@ -82,6 +82,7 @@ public class Zip extends MatchingTask { protected String emptyBehavior = "skip"; private Vector filesets = new Vector (); private Hashtable addedDirs = new Hashtable(); + private Vector locFileSets = new Vector(); /** * This is the name/location of where to @@ -113,6 +114,24 @@ public class Zip extends MatchingTask { filesets.addElement(set); } + /** + * FileSet with an additional prefix attribute to specify the + * location we want to move the files to (inside the archive). + */ + public static class PrefixedFileSet extends FileSet { + private String prefix = ""; + + public void setPrefix(String loc) { + prefix = loc; + } + + public String getPrefix() {return prefix;} + } + + public void addPrefixedFileSet(PrefixedFileSet fs) { + locFileSets.addElement(fs); + } + /** * Sets behavior of the task when no files match. * Possible values are: fail (throw an exception @@ -146,9 +165,12 @@ public class Zip extends MatchingTask { FileSet fs = (FileSet) filesets.elementAt(i); dss.addElement (fs.getDirectoryScanner(project)); } - FileScanner[] scanners = new FileScanner[dss.size()]; + int dssSize = dss.size(); + FileScanner[] scanners = new FileScanner[dssSize + locFileSets.size()]; dss.copyInto(scanners); + addScanners(scanners, dssSize, locFileSets); + // quick exit if the target is up to date // can also handle empty archives if (isUpToDate(scanners, zipFile)) return; @@ -164,8 +186,10 @@ public class Zip extends MatchingTask { zOut.setMethod(ZipOutputStream.STORED); } initZipOutputStream(zOut); - - for (int j = 0; j < scanners.length; j++) { + + addPrefixedFiles(locFileSets, zOut); + + for (int j = 0; j < dssSize; j++) { addFiles(scanners[j], zOut, ""); } } finally { @@ -183,6 +207,18 @@ public class Zip extends MatchingTask { } } + /** + * Add a DirectoryScanner for each FileSet included in fileSets to scanners + * starting with index startIndex. + */ + protected void addScanners(FileScanner[] scanners, int startIndex, + Vector fileSets) { + for (int i=0; i 0 + && !prefix.endsWith("/") + && !prefix.endsWith("\\")) { + prefix += "/"; + } + zipDir(null, zOut, prefix); + addFiles(ds, zOut, prefix); + } + } }