Browse Source

Added a nested prefixedfileset element to <war>

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268136 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
6103df477a
4 changed files with 116 additions and 7 deletions
  1. +2
    -0
      WHATSNEW
  2. +67
    -4
      docs/index.html
  3. +46
    -2
      src/main/org/apache/tools/ant/taskdefs/War.java
  4. +1
    -1
      src/main/org/apache/tools/ant/types/FileSet.java

+ 2
- 0
WHATSNEW View File

@@ -8,6 +8,8 @@ Other changes:

* Added output attribute to <java>.

* Added nested prefixedfileset element to <war>

Fixed bugs:
-----------



+ 67
- 4
docs/index.html View File

@@ -26,7 +26,7 @@
<li>Dave Walend (<a href="mailto:dwalend@cs.tufts.edu">dwalend@cs.tufts.edu</a>)</li>
</ul>

<p>Version 1.3 - 2000/10/27</p>
<p>Version 1.3 - 2000/10/31</p>

<hr>
<h2>Table of Contents</h2>
@@ -4220,9 +4220,12 @@ carried from tarfile.</p>
<h2><a name="war">War</a></h2>
<h3>Description</h3>
<p>An extension of the <a href="#jar">Jar</a> task with special
treatment for files that should end up in the <code>WEB-INF/lib</code>,
<code>WEB-INF/classes</code> or <code>WEB-INF</code> directories of the Web
Application Archive.</p>
treatment for files that should end up in the
<code>WEB-INF/lib</code>, <code>WEB-INF/classes</code> or
<code>WEB-INF</code> 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 <code>prefixedfileset</code>
element.</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
@@ -4306,6 +4309,60 @@ href="#fileset">FileSet</a>. All files included in this fileset will
end up in the <code>WEB-INF</code> directory of the war file. If this
fileset includes a file named <code>web.xml</code>, the file is
ignored and you will get a warning.</p>
<h4>prefixedfileset</h4>
<p>The nested <code>prefixedfileset</code> element specifies a <a
href="#fileset">FileSet</a> with an additional prefix attribute. All
files included in this fileset will end up in the <em>prefix</em>
directory of the war file, where <em>prefix</em> is the value of the
<code>prefix</code> attribute.</p>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">prefix</td>
<td valign="top">The prefix directory to add to each filename when
adding it to the archive. Default is none.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">dir</td>
<td valign="top">The root of the directory tree of this FileSet.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">defaultexcludes</td>
<td valign="top">indicates whether default excludes should be used or not
(&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includes</td>
<td valign="top">comma separated list of patterns of files that must be
included. All files are included when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">includesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an include pattern</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludes</td>
<td valign="top">comma separated list of patterns of files that must be
excluded. No files (except default excludes) are excluded when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">excludesfile</td>
<td valign="top">the name of a file. Each line of this file is
taken to be an exclude pattern</td>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Examples</h3>
<p>Assume the following structure in the project's base directory:
<pre>
@@ -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
</pre>
then the war file <code>myapp.war</code> created with
<pre>
@@ -4325,6 +4384,8 @@ then the war file <code>myapp.war</code> created with
&lt;exclude name=&quot;jdbc1.jar&quot; /&gt;
&lt;/lib&gt;
&lt;classes dir=&quot;build/main&quot; /&gt;
&lt;prefixedfileset dir=&quot;src/graphics/images/gifs&quot;
prefix="images"/&gt;
&lt;/war&gt;
</pre>
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
</pre>
using Ant's default manifest file. The content of
<code>WEB-INF/web.xml</code> is identical to


+ 46
- 2
src/main/org/apache/tools/ant/taskdefs/War.java View File

@@ -64,7 +64,7 @@ import java.util.zip.*;
/**
* Creates a WAR archive.
*
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
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<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
- 1
src/main/org/apache/tools/ant/types/FileSet.java View File

@@ -71,7 +71,7 @@ import java.util.Vector;
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
* @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>
* @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class FileSet extends DataType {


Loading…
Cancel
Save