From 6103df477a1462aaa01639cec094e2b53172d711 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 31 Oct 2000 13:53:07 +0000 Subject: [PATCH] Added a nested prefixedfileset element to git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268136 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 + docs/index.html | 71 +++++++++++++++++-- .../org/apache/tools/ant/taskdefs/War.java | 48 ++++++++++++- .../org/apache/tools/ant/types/FileSet.java | 2 +- 4 files changed, 116 insertions(+), 7 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 3be85d088..86711d438 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -8,6 +8,8 @@ Other changes: * Added output attribute to . +* Added nested prefixedfileset element to + Fixed bugs: ----------- diff --git a/docs/index.html b/docs/index.html index 131de72d7..b13d31612 100644 --- a/docs/index.html +++ b/docs/index.html @@ -26,7 +26,7 @@
  • Dave Walend (dwalend@cs.tufts.edu)
  • -

    Version 1.3 - 2000/10/27

    +

    Version 1.3 - 2000/10/31


    Table of Contents

    @@ -4220,9 +4220,12 @@ carried from tarfile.

    War

    Description

    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.

    +treatment for files that should end up in the +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.

    Parameters

    @@ -4306,6 +4309,60 @@ href="#fileset">FileSet. All files included in this fileset will end up in the WEB-INF directory of the war file. If this fileset includes a file named web.xml, the file is ignored and you will get a warning.

    +

    prefixedfileset

    +

    The nested prefixedfileset element specifies a FileSet with an additional prefix attribute. All +files included in this fileset will end up in the prefix +directory of the war file, where prefix is the value of the +prefix attribute.

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    AttributeDescriptionRequired
    prefixThe prefix directory to add to each filename when + adding it to the archive. Default is none.No
    dirThe root of the directory tree of this FileSet.Yes
    defaultexcludesindicates whether default excludes should be used or not + ("yes"/"no"). Default excludes are used when omitted.No
    includescomma separated list of patterns of files that must be + included. All files are included when omitted.No
    includesfilethe name of a file. Each line of this file is + taken to be an include patternNo
    excludescomma separated list of patterns of files that must be + excluded. No files (except default excludes) are excluded when omitted.No
    excludesfilethe name of a file. Each line of this file is + taken to be an exclude patternNo

    Examples

    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.gif
     
    then 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 0 + && !prefix.endsWith("/") + && !prefix.endsWith("\\")) { + prefix += "/"; + } + zipDir(null, zOut, prefix); + addFiles(ds, zOut, prefix); + } + } } diff --git a/src/main/org/apache/tools/ant/types/FileSet.java b/src/main/org/apache/tools/ant/types/FileSet.java index 716cfd09f..26a5b353c 100644 --- a/src/main/org/apache/tools/ant/types/FileSet.java +++ b/src/main/org/apache/tools/ant/types/FileSet.java @@ -71,7 +71,7 @@ import java.util.Vector; * @author Stefano Mazzocchi stefano@apache.org * @author Sam Ruby rubys@us.ibm.com * @author Jon S. Stevens jon@clearink.com - * @author Stefan Bodewig + * @author Stefan Bodewig */ public class FileSet extends DataType {