From 6103df477a1462aaa01639cec094e2b53172d711 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig Version 1.3 - 2000/10/27 Version 1.3 - 2000/10/31
Table of Contents
@@ -4220,9 +4220,12 @@ carried from tarfile.
An extension of the Jar task with special
-treatment for files that should end up in the WEB-INF/lib,
-WEB-INF/classes or WEB-INF directories of the Web
-Application Archive.
WEB-INF/lib, WEB-INF/classes or
+WEB-INF directories of the Web Application Archive. It
+also gives you more control over where your files end up in the
+archive by means of its nested prefixedfileset
+element.
| Attribute | +Description | +Required | +
| prefix | +The prefix directory to add to each filename when + adding it to the archive. Default is none. | +No | +
| dir | +The root of the directory tree of this FileSet. | +Yes | +
| defaultexcludes | +indicates whether default excludes should be used or not + ("yes"/"no"). Default excludes are used when omitted. | +No | +
| includes | +comma separated list of patterns of files that must be + included. All files are included when omitted. | +No | +
| includesfile | +the name of a file. Each line of this file is + taken to be an include pattern | +No | +
| excludes | +comma separated list of patterns of files that must be + excluded. No files (except default excludes) are excluded when omitted. | +No | +
| excludesfile | +the name of a file. Each line of this file is + taken to be an exclude pattern | +No | +
Assume the following structure in the project's base directory:
@@ -4315,6 +4372,8 @@ build/main/com/myco/myapp/Servlet.class src/metadata/myapp.xml src/html/myapp/index.html src/jsp/myapp/front.jsp +src/graphics/images/gifs/small/logo.gif +src/graphics/images/gifs/large/logo.gifthen the war file
myapp.war created with
@@ -4325,6 +4384,8 @@ then the war file myapp.war created with
<exclude name="jdbc1.jar" />
</lib>
<classes dir="build/main" />
+ <prefixedfileset dir="src/graphics/images/gifs"
+ prefix="images"/>
</war>
will consist of
@@ -4335,6 +4396,8 @@ WEB-INF/classes/com/myco/myapp/Servlet.class
META-INF/MANIFEST.MF
index.html
front.jsp
+images/small/logo.gif
+images/large/logo.gif
using Ant's default manifest file. The content of
WEB-INF/web.xml is identical to
diff --git a/src/main/org/apache/tools/ant/taskdefs/War.java b/src/main/org/apache/tools/ant/taskdefs/War.java
index f8e881e14..edb7f0712 100644
--- a/src/main/org/apache/tools/ant/taskdefs/War.java
+++ b/src/main/org/apache/tools/ant/taskdefs/War.java
@@ -64,7 +64,7 @@ import java.util.zip.*;
/**
* Creates a WAR archive.
*
- * @author Stefan Bodewig
+ * @author Stefan Bodewig
*/
public class War extends Jar {
@@ -73,6 +73,7 @@ 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();
@@ -100,6 +101,24 @@ 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.
@@ -119,6 +138,7 @@ 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);
}
@@ -136,7 +156,8 @@ public class War extends Jar {
+ 1 // web.xml
+ libFileSets.size()
+ classesFileSets.size()
- + webInfFileSets.size()];
+ + webInfFileSets.size()
+ + locFileSets.size()];
System.arraycopy(scanners, 0, myScanners, 0, scanners.length);
@@ -151,6 +172,9 @@ 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);
}
@@ -191,4 +215,24 @@ public class War extends Jar {
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