diff --git a/docs/index.html b/docs/index.html
index f35137526..8c83b4128 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -2725,6 +2725,11 @@ You should not include META-INF/MANIFEST.MF in your set of files.
If create
(the default), the JAR is created anyway with only a manifest.
If skip
, the JAR is not created and a warning is issued.
If fail
, the JAR is not created and the build is halted with an error.
+
(The Jar task is a shortcut for specifying the manifest file of a JAR file. +The same thing can be accomplished by using the fullpath +attribute of the filesets in a Zip task. The one difference is that if the +manifest attribute is not specified, the Jar task will +include an empty one for you.)
<jar jarfile="${dist}/lib/app.jar" basedir="${build}/classes" />-
jars all files in the ${build}/classes
directory in a file
+
jars all files in the ${build}/classes
directory into a file
called app.jar
in the ${dist}/lib
directory.
<jar jarfile="${dist}/lib/app.jar" basedir="${build}/classes" excludes="**/Test.class" />-
jars all files in the ${build}/classes
directory in a file
+
jars all files in the ${build}/classes
directory into a file
called app.jar
in the ${dist}/lib
directory. Files
with the name Test.class
are excluded.
<jar jarfile="${dist}/lib/app.jar"
@@ -2805,7 +2810,7 @@ with the name Test.class
are excluded.
includes="mypackage/test/**"
excludes="**/Test.class"
/>
-jars all files in the ${build}/classes
directory in a file
+
jars all files in the ${build}/classes
directory into a file
called app.jar
in the ${dist}/lib
directory. Only
files under the directory mypackage/test
are used, and files with
the name Test.class
are excluded.
Test.class
are excluded.
<fileset dir="${src}/resources"/>
</jar>
jars all files in the ${build}/classes
directory and also
-in the ${src}/resources
directory together in a file
+in the ${src}/resources
directory together into a file
called app.jar
in the ${dist}/lib
directory.
Files with the name Test.class
are excluded.
If there are files such as ${build}/classes/mypackage/MyClass.class
@@ -4434,14 +4439,14 @@ task to come up with a .tar.gz package.
<tar tarfile="${dist}/manual.tar" basedir="htdocs/manual" /> <gzip zipfile="${dist}/manual.tar.gz" src="${dist}/manual.tar" />-
tars all files in the htdocs/manual
directory in a file called manual.tar
+
tars all files in the htdocs/manual
directory into a file called manual.tar
in the ${dist}
directory, then applies the gzip task to compress
it.
<tar tarfile="${dist}/manual.tar" basedir="htdocs/manual" excludes="mydocs/**, **/todo.html" />-
tars all files in the htdocs/manual
directory in a file called manual.tar
+
tars all files in the htdocs/manual
directory into a file called manual.tar
in the ${dist}
directory. Files in the directory mydocs
,
or files with the name todo.html
are excluded.
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. It
-also gives you more control over where your files end up in the
-archive by means of its nested prefixedfileset
-element.
WEB-INF
directories of the Web Application Archive.
+(The War task is a shortcut for specifying the particular layout of a WAR file. +The same thing can be accomplished by using the prefix and fullpath +attributes of the filesets in a Zip or Jar task.)
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:
@@ -4941,7 +4892,7 @@ then the war file myapp.war
created with
<exclude name="jdbc1.jar" />
</lib>
<classes dir="build/main" />
- <prefixedfileset dir="src/graphics/images/gifs"
+ <fileset dir="src/graphics/images/gifs"
prefix="images"/>
</war>
@@ -4986,6 +4937,13 @@ if basedir
is set. You may use any mixture of the implicit file set
and optional subelements like <include>
); explicit nested
<fileset>
elements so long as at least one fileset total is specified. The ZIP file will
only reflect the relative paths of files within each fileset.
+Inside of <zip>
elements, nested filesets may include one of two special attributes:
+prefix or fullpath. These attributes modify the location of the files when they are placed
+inside the archive. If the prefix attribute is set, all the files in the fileset are prefixed
+with that path in the archive. If the fullpath attribute is set, the file described by the filset is placed at that
+exact location in the archive. (The fullpath attribute can only be set for filesets that
+represent a single file. The prefix and fullpath attributes cannot both be set on the
+same fileset.)
The whenempty
parameter controls what happens when no files match.
If skip
(the default), the ZIP is not created and a warning is issued.
If fail
, the ZIP is not created and the build is halted with an error.
@@ -5053,31 +5011,36 @@ which should be recognized as such by compliant ZIP manipulation tools.
<zip zipfile="${dist}/manual.zip" basedir="htdocs/manual" />-
zips all files in the htdocs/manual
directory in a file called manual.zip
+
zips all files in the htdocs/manual
directory into a file called manual.zip
in the ${dist}
directory.
<zip zipfile="${dist}/manual.zip" basedir="htdocs/manual" excludes="mydocs/**, **/todo.html" />-
zips all files in the htdocs/manual
directory in a file called manual.zip
-in the ${dist}
directory. Files in the directory mydocs
,
+
zips all files in the htdocs/manual
directory. Files in the directory mydocs
,
or files with the name todo.html
are excluded.
<zip zipfile="${dist}/manual.zip" basedir="htdocs/manual" includes="api/**/*.html" excludes="**/todo.html" />-
zips all files in the htdocs/manual
directory in a file called manual.zip
-in the ${dist}
directory. Only html files under the directory api
+
zips all files in the htdocs/manual
directory. Only html files under the directory api
are zipped, and files with the name todo.html
are excluded.
<zip zipfile="${dist}/manual.zip"> <fileset dir="htdocs/manual"/> <fileset dir="." includes="ChangeLog.txt"/> </zip>-
zips all files in the htdocs/manual
directory in a file called manual.zip
-in the ${dist}
directory, and also adds the file ChangeLog.txt
in the
+
zips all files in the htdocs/manual
directory, and also adds the file ChangeLog.txt
in the
current directory. ChangeLog.txt
will be added to the top of the ZIP file, just as if
it had been located at htdocs/manual/ChangeLog.txt
.
<zip zipfile="${dist}/manual.zip"> + <fileset dir="htdocs/manual" prefix="docs/user-guide"/> + <fileset dir="." includes="ChangeLog27.txt" fullpath="docs/ChangeLog.txt"/> + </zip>+
zips all files in the htdocs/manual
directory into the docs/user-guide
directory
+in the archive, and also adds the file ChangeLog27.txt
in the
+current directory as docs/ChangeLog.txt
. For example, the archive might end up containing two files:
+docs/user-guide/html/index.html
and docs/ChangeLog.txt
<fileset>
basedir="htdocs/manual"
/>
-cabs all files in the htdocs/manual directory in a file called +
cabs all files in the htdocs/manual directory into a file called manual.cab in the ${dist} directory.
-<cab cabfile="${dist}/manual.cab" @@ -5196,7 +5159,7 @@ manual.cab in the ${dist} directory. excludes="mydocs/**, **/todo.html" />
cabs all files in the htdocs/manual directory in a file called +
cabs all files in the htdocs/manual directory into a file called manual.cab in the ${dist} directory. Files in the directory mydocs, or files with the name todo.html are excluded.
-@@ -5207,7 +5170,7 @@ or files with the name todo.html are excluded. verbose="yes" />
cab all files in the htdocs/manual directory in a file called +
cab all files in the htdocs/manual directory into a file called
manual.cab in the ${dist} directory. Only html files under the
directory api are archived, and files with the name todo.html are
excluded. Output from the cabarc tool is displayed in the build
diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java
index 825a8f2ce..6dc3e6a31 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Jar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java
@@ -68,35 +68,45 @@ import java.util.zip.*;
public class Jar extends Zip {
private File manifest;
-
+ private boolean manifestAdded;
+
public Jar() {
super();
archiveType = "jar";
emptyBehavior = "create";
}
- public void execute() {
- if (manifest != null && !manifest.exists())
- throw new BuildException("Manifest file: " + manifest + " does not exists.");
- super.execute();
- }
-
public void setJarfile(File jarFile) {
super.setZipfile(jarFile);
}
+
+ /**
+ * Adds a set of files (nested fileset attribute).
+ */
+ public void addPrefixedfileset(PrefixedFileSet set) {
+ log("Warning: Prefixfileset is a deprecated feature. The fileset subelement can be used in it's place", Project.MSG_WARN);
+ addFileset(set);
+ }
public void setManifest(File manifestFile) {
manifest = manifestFile;
+ if (!manifest.exists())
+ throw new BuildException("Manifest file: " + manifest + " does not exist.");
+
+ // Create a PrefixedFileSet for this file, and pass it up.
+ PrefixedFileSet fs = new PrefixedFileSet();
+ fs.setDir(new File(manifest.getParent()));
+ fs.setIncludes(manifest.getName());
+ fs.setFullpath("META-INF/MANIFEST.MF");
+ super.addFileset(fs);
}
+
protected void initZipOutputStream(ZipOutputStream zOut)
throws IOException, BuildException
{
- // add manifest first
- if (manifest != null) {
- zipDir(new File(manifest.getParent()), zOut, "META-INF/");
- super.zipFile(manifest, zOut, "META-INF/MANIFEST.MF");
- } else {
+ // If no manifest is specified, add the default one.
+ if (manifest == null) {
String s = "/org/apache/tools/ant/defaultManifest.mf";
InputStream in = this.getClass().getResourceAsStream(s);
if ( in == null )
@@ -104,53 +114,27 @@ public class Jar extends Zip {
zipDir(null, zOut, "META-INF/");
zipFile(in, zOut, "META-INF/MANIFEST.MF", System.currentTimeMillis());
}
- }
-
- protected boolean isUpToDate(FileScanner[] scanners, File zipFile) throws BuildException
- {
- File[] files = grabFiles(scanners);
-
- if (manifest != null) {
- // just add the manifest file to the mix
-
- DirectoryScanner ds = new DirectoryScanner();
- ds.setBasedir(new File(manifest.getParent()));
- ds.setIncludes(new String[] {manifest.getName()});
- ds.scan();
- FileScanner[] myScanners = new FileScanner[scanners.length+1];
- System.arraycopy(scanners, 0, myScanners, 0, scanners.length);
- myScanners[scanners.length] = ds;
-
- boolean retval = super.isUpToDate(myScanners, zipFile);
- if (!retval && files.length == 0) {
- log("Note: creating empty "+archiveType+" archive " + zipFile,
- Project.MSG_INFO);
- }
- return retval;
-
- } else if (emptyBehavior.equals("create") && files.length == 0) {
-
- log("Note: creating empty "+archiveType+" archive " + zipFile,
- Project.MSG_INFO);
- return false;
-
- } else {
- // all other cases are handled correctly by Zip's method
- return super.isUpToDate(scanners, zipFile);
- }
+ super.initZipOutputStream(zOut);
}
protected void zipFile(File file, ZipOutputStream zOut, String vPath)
throws IOException
{
- // We already added a META-INF/MANIFEST.MF
- if (!vPath.equalsIgnoreCase("META-INF/MANIFEST.MF")) {
- super.zipFile(file, zOut, vPath);
+ // If the file being added is META-INF/MANIFEST.MF, we warn if it's not the
+ // one specified in the "manifest" attribute - or if it's being added twice,
+ // meaning the same file is specified by the "manifeset" attribute and in
+ // a