git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268327 13f79535-47bb-0310-9956-ffa450edef68master
@@ -73,7 +73,6 @@ public class War extends Jar { | |||||
private Vector libFileSets = new Vector(); | private Vector libFileSets = new Vector(); | ||||
private Vector classesFileSets = new Vector(); | private Vector classesFileSets = new Vector(); | ||||
private Vector webInfFileSets = new Vector(); | private Vector webInfFileSets = new Vector(); | ||||
private Vector locFileSets = new Vector(); | |||||
public War() { | public War() { | ||||
super(); | super(); | ||||
@@ -101,24 +100,6 @@ public class War extends Jar { | |||||
webInfFileSets.addElement(fs); | 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 | * Add the deployment descriptor as well as all files added the | ||||
* special way of nested lib, classes or webinf filesets. | * 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(libFileSets, zOut, "WEB-INF/lib/"); | ||||
addFiles(classesFileSets, zOut, "WEB-INF/classes/"); | addFiles(classesFileSets, zOut, "WEB-INF/classes/"); | ||||
addFiles(webInfFileSets, zOut, "WEB-INF/"); | addFiles(webInfFileSets, zOut, "WEB-INF/"); | ||||
addPrefixedFiles(locFileSets, zOut); | |||||
super.initZipOutputStream(zOut); | super.initZipOutputStream(zOut); | ||||
} | } | ||||
@@ -156,8 +136,7 @@ public class War extends Jar { | |||||
+ 1 // web.xml | + 1 // web.xml | ||||
+ libFileSets.size() | + libFileSets.size() | ||||
+ classesFileSets.size() | + classesFileSets.size() | ||||
+ webInfFileSets.size() | |||||
+ locFileSets.size()]; | |||||
+ webInfFileSets.size()]; | |||||
System.arraycopy(scanners, 0, myScanners, 0, scanners.length); | System.arraycopy(scanners, 0, myScanners, 0, scanners.length); | ||||
@@ -172,9 +151,6 @@ public class War extends Jar { | |||||
classesFileSets); | classesFileSets); | ||||
addScanners(myScanners, scanners.length+1+libFileSets.size()+classesFileSets.size(), | addScanners(myScanners, scanners.length+1+libFileSets.size()+classesFileSets.size(), | ||||
webInfFileSets); | webInfFileSets); | ||||
addScanners(myScanners, scanners.length + 1 + libFileSets.size() | |||||
+classesFileSets.size()+webInfFileSets.size(), | |||||
locFileSets); | |||||
return super.isUpToDate(myScanners, zipFile); | return super.isUpToDate(myScanners, zipFile); | ||||
} | } | ||||
@@ -190,49 +166,4 @@ public class War extends Jar { | |||||
"(please use webxml attribute to "+archiveType+" task)", Project.MSG_WARN); | "(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<fileSets.size(); i++) { | |||||
FileSet fs = (FileSet) fileSets.elementAt(i); | |||||
scanners[startIndex+i] = fs.getDirectoryScanner(project); | |||||
} | |||||
} | |||||
/** | |||||
* Iterate over the given Vector of filesets and add all files to the | |||||
* ZipOutputStream using the given prefix. | |||||
*/ | |||||
protected void addFiles(Vector v, ZipOutputStream zOut, String prefix) | |||||
throws IOException { | |||||
for (int i=0; i<v.size(); i++) { | |||||
FileSet fs = (FileSet) v.elementAt(i); | |||||
DirectoryScanner ds = fs.getDirectoryScanner(project); | |||||
addFiles(ds, zOut, prefix); | |||||
} | |||||
} | |||||
/** | |||||
* Iterate over the given Vector of relocatablefilesets and add | |||||
* all files to the ZipOutputStream using the given prefix. | |||||
*/ | |||||
protected void addPrefixedFiles(Vector v, ZipOutputStream zOut) | |||||
throws IOException { | |||||
for (int i=0; i<v.size(); i++) { | |||||
PrefixedFileSet fs = (PrefixedFileSet) v.elementAt(i); | |||||
DirectoryScanner ds = fs.getDirectoryScanner(project); | |||||
String prefix = fs.getPrefix(); | |||||
if (prefix.length() > 0 | |||||
&& !prefix.endsWith("/") | |||||
&& !prefix.endsWith("\\")) { | |||||
prefix += "/"; | |||||
} | |||||
zipDir(null, zOut, prefix); | |||||
addFiles(ds, zOut, prefix); | |||||
} | |||||
} | |||||
} | } |
@@ -82,6 +82,7 @@ public class Zip extends MatchingTask { | |||||
protected String emptyBehavior = "skip"; | protected String emptyBehavior = "skip"; | ||||
private Vector filesets = new Vector (); | private Vector filesets = new Vector (); | ||||
private Hashtable addedDirs = new Hashtable(); | private Hashtable addedDirs = new Hashtable(); | ||||
private Vector locFileSets = new Vector(); | |||||
/** | /** | ||||
* This is the name/location of where to | * This is the name/location of where to | ||||
@@ -113,6 +114,24 @@ public class Zip extends MatchingTask { | |||||
filesets.addElement(set); | 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. | * Sets behavior of the task when no files match. | ||||
* Possible values are: <code>fail</code> (throw an exception | * Possible values are: <code>fail</code> (throw an exception | ||||
@@ -146,9 +165,12 @@ public class Zip extends MatchingTask { | |||||
FileSet fs = (FileSet) filesets.elementAt(i); | FileSet fs = (FileSet) filesets.elementAt(i); | ||||
dss.addElement (fs.getDirectoryScanner(project)); | 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); | dss.copyInto(scanners); | ||||
addScanners(scanners, dssSize, locFileSets); | |||||
// quick exit if the target is up to date | // quick exit if the target is up to date | ||||
// can also handle empty archives | // can also handle empty archives | ||||
if (isUpToDate(scanners, zipFile)) return; | if (isUpToDate(scanners, zipFile)) return; | ||||
@@ -164,8 +186,10 @@ public class Zip extends MatchingTask { | |||||
zOut.setMethod(ZipOutputStream.STORED); | zOut.setMethod(ZipOutputStream.STORED); | ||||
} | } | ||||
initZipOutputStream(zOut); | initZipOutputStream(zOut); | ||||
for (int j = 0; j < scanners.length; j++) { | |||||
addPrefixedFiles(locFileSets, zOut); | |||||
for (int j = 0; j < dssSize; j++) { | |||||
addFiles(scanners[j], zOut, ""); | addFiles(scanners[j], zOut, ""); | ||||
} | } | ||||
} finally { | } 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<fileSets.size(); i++) { | |||||
FileSet fs = (FileSet) fileSets.elementAt(i); | |||||
scanners[startIndex+i] = fs.getDirectoryScanner(project); | |||||
} | |||||
} | |||||
/** | /** | ||||
* Add all files of the given FileScanner to the ZipOutputStream | * Add all files of the given FileScanner to the ZipOutputStream | ||||
* prependig the given prefix to each filename. | * prependig the given prefix to each filename. | ||||
@@ -418,4 +454,37 @@ public class Zip extends MatchingTask { | |||||
zipDir(f, zOut, prefix+dir); | zipDir(f, zOut, prefix+dir); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Iterate over the given Vector of filesets and add all files to the | |||||
* ZipOutputStream using the given prefix. | |||||
*/ | |||||
protected void addFiles(Vector v, ZipOutputStream zOut, String prefix) | |||||
throws IOException { | |||||
for (int i=0; i<v.size(); i++) { | |||||
FileSet fs = (FileSet) v.elementAt(i); | |||||
DirectoryScanner ds = fs.getDirectoryScanner(project); | |||||
addFiles(ds, zOut, prefix); | |||||
} | |||||
} | |||||
/** | |||||
* Iterate over the given Vector of relocatablefilesets and add | |||||
* all files to the ZipOutputStream using the given prefix. | |||||
*/ | |||||
protected void addPrefixedFiles(Vector v, ZipOutputStream zOut) | |||||
throws IOException { | |||||
for (int i=0; i<v.size(); i++) { | |||||
PrefixedFileSet fs = (PrefixedFileSet) v.elementAt(i); | |||||
DirectoryScanner ds = fs.getDirectoryScanner(project); | |||||
String prefix = fs.getPrefix(); | |||||
if (prefix.length() > 0 | |||||
&& !prefix.endsWith("/") | |||||
&& !prefix.endsWith("\\")) { | |||||
prefix += "/"; | |||||
} | |||||
zipDir(null, zOut, prefix); | |||||
addFiles(ds, zOut, prefix); | |||||
} | |||||
} | |||||
} | } |