You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@locus.apache.org on 2000/12/07 13:00:58 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs War.java Zip.java
donaldp 00/12/07 04:00:57
Modified: src/main/org/apache/tools/ant/taskdefs War.java Zip.java
Log:
moved PrefixFileSets from War Task to Zip task
Revision Changes Path
1.5 +1 -70 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/War.java
Index: War.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/War.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- War.java 2000/11/25 02:38:37 1.4
+++ War.java 2000/12/07 12:00:54 1.5
@@ -73,7 +73,6 @@
private Vector libFileSets = new Vector();
private Vector classesFileSets = new Vector();
private Vector webInfFileSets = new Vector();
- private Vector locFileSets = new Vector();
public War() {
super();
@@ -102,24 +101,6 @@
}
/**
- * 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 @@
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 @@
+ 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 @@
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);
}
@@ -188,51 +164,6 @@
} else {
log("Warning: selected "+archiveType+" files include a WEB-INF/web.xml which will be ignored " +
"(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);
}
}
}
1.19 +72 -3 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
Index: Zip.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Zip.java 2000/11/25 02:38:37 1.18
+++ Zip.java 2000/12/07 12:00:55 1.19
@@ -82,6 +82,7 @@
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
@@ -114,6 +115,24 @@
}
/**
+ * 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: <code>fail</code> (throw an exception
* and halt the build); <code>skip</code> (do not create
@@ -146,9 +165,12 @@
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 @@
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 {
@@ -184,6 +208,18 @@
}
/**
+ * 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
* prependig the given prefix to each filename.
*
@@ -416,6 +452,39 @@
String dir = (String) directories.pop();
File f = new File(baseDir, 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);
}
}
}