From 01967f4543e3d84e079481c6ea968fb0b517fad2 Mon Sep 17 00:00:00 2001
From: Jacobus Martinus Kruithof
Date: Sun, 2 Oct 2005 20:04:39 +0000
Subject: [PATCH] Updated the Jar task to have an whenmanifestonly attribute,
creating the possibility to skip jar files that would otherwise only contain
a jar file. Also started to use this for the optional tasks in the build.xml
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@293157 13f79535-47bb-0310-9956-ffa450edef68
---
build.xml | 18 ++++++++-----
docs/manual/CoreTasks/jar.html | 12 +++++++++
.../org/apache/tools/ant/taskdefs/Jar.java | 25 +++++++++++++++++++
3 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/build.xml b/build.xml
index c31efa79e..af4a5a769 100644
--- a/build.xml
+++ b/build.xml
@@ -777,7 +777,8 @@
+ basedir="${build.classes}"
+ whenmanifestonly="fail">
@@ -786,7 +787,8 @@
+ manifest="${manifest}"
+ whenmanifestonly="fail">
@@ -835,7 +837,8 @@
+ manifest="${manifest}"
+ whenmanifestonly="fail">
@@ -849,7 +852,8 @@
+ manifest="${manifest.tmp}"
+ whenmanifestonly="skip">
@@ -895,7 +899,8 @@
+ manifest="${manifest.tmp}"
+ whenmanifestonly="skip">
@@ -928,7 +933,8 @@
+ manifest="${manifest.tmp}"
+ whenmanifestonly="skip">
diff --git a/docs/manual/CoreTasks/jar.html b/docs/manual/CoreTasks/jar.html
index cfec1977a..dc0a42c0a 100644
--- a/docs/manual/CoreTasks/jar.html
+++ b/docs/manual/CoreTasks/jar.html
@@ -43,6 +43,13 @@ note that ZIP files store file modification times with a granularity
of two seconds. If a file is less than two seconds newer than the
entry in the archive, Ant will not consider it newer.
+The whenmanifestonly
parameter controls what happens when no
+files, apart from the manifest file, match.
+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.
+If create
, (default) an empty JAR file (only containing a manifest)
+is created.
+
(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 a zipfileset in a Zip task. The one difference is that if the
@@ -155,6 +162,11 @@ to a value other than its default, "add"
.
the destination file if it already exists. Default is "false".
No |
+
+ whenmanifestonly |
+ behavior when no files match. Valid values are "fail", "skip", and "create". Default is "create". |
+ No |
+
duplicate |
behavior when a duplicate file is found. Valid values are "add", "preserve", and "fail". The default value is "add". |
diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java
index d3ed97cda..2ada0d2ca 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Jar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java
@@ -140,6 +140,8 @@ public class Jar extends Zip {
private ZipExtraField[] JAR_MARKER = new ZipExtraField[] {
JarMarker.getInstance()
};
+
+ protected String emptyBehavior = "create";
/** constructor */
public Jar() {
@@ -160,6 +162,16 @@ public class Jar extends Zip {
Project.MSG_WARN);
}
+ /**
+ * Not used for jar files.
+ * @param we not used
+ * @ant.attribute ignore="true"
+ */
+ public void setWhenmanifestonly(WhenEmpty we) {
+ emptyBehavior = we.getValue();
+ }
+
+
/**
* Set the destination file.
* @param jarFile the destination file
@@ -677,6 +689,18 @@ public class Jar extends Zip {
return true;
}
+ if (emptyBehavior.equals("skip")) {
+ log("Warning: skipping " + archiveType + " archive "
+ + zipFile + " because no files were included.",
+ Project.MSG_WARN);
+ return true;
+ } else if (emptyBehavior.equals("fail")) {
+ throw new BuildException("Cannot create " + archiveType
+ + " archive " + zipFile
+ + ": no files were included.",
+ getLocation());
+ }
+
ZipOutputStream zOut = null;
try {
log("Building MANIFEST-only jar: "
@@ -737,6 +761,7 @@ public class Jar extends Zip {
*/
public void reset() {
super.reset();
+ emptyBehavior = "create";
configuredManifest = null;
filesetManifestConfig = null;
mergeManifestsMain = false;