From 14f760492cdf18560bccf1b7afcf8ae052228237 Mon Sep 17 00:00:00 2001
From: Steve Loughran
Date: Fri, 27 Oct 2006 22:33:42 +0000
Subject: [PATCH] Made web.xml non optional again, as it was hiding too many
bugs (e.g war files for tomcat 5), but added an attribute to make it
optional.
More tests, especially for updates. One test is disabled because it fails. The task fails if you are pulling in a web.xml on an existing web.xml file via a fileset if update=false, because the fileset version checking is hiding the inclusion of the web.xml file from the war task -its being dropped before we notice. This is not a BC problem. Maybe I should always make web.xml mandatory to stop this behavior arising.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@468568 13f79535-47bb-0310-9956-ffa450edef68
---
WHATSNEW | 5 +-
docs/manual/CoreTasks/war.html | 27 ++++++---
.../org/apache/tools/ant/taskdefs/War.java | 27 ++++++---
src/tests/antunit/taskdefs/war-test.xml | 56 +++++++++++++++++--
4 files changed, 93 insertions(+), 22 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index c53f9b534..eacf34256 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -28,9 +28,8 @@ Other changes:
Bugzilla 40019.
* task now allows you to omit the web.xml file. as this is optional
- in the servlet 2.5 and Java EE 5 APIs. If you do want a web.xml file, it
- can be pulled in by any nested fileset or resource reference; the webxml
- attribute is optional.
+ in the servlet 2.5 and Java EE 5 APIs. set needxmlfile="false" to
+ avoid a missing web.xml file from halting the build.
* Diagnostics catches and logs security exceptions when accessing system properties.
diff --git a/docs/manual/CoreTasks/war.html b/docs/manual/CoreTasks/war.html
index 0ed78f46b..3f3926011 100644
--- a/docs/manual/CoreTasks/war.html
+++ b/docs/manual/CoreTasks/war.html
@@ -41,14 +41,17 @@ attributes of zipfilesets in a Zip or Jar task.)
Before Servlet API 2.5/Java EE 5, a WEB-INF/web.xml file was mandatory in a
WAR file, so this task failed if the webxml
attribute was missing.
- As the web.xml file is now optional, the webxml
attribute is now
- downgraded to being optional. The task will warn if the file is not
- included as an attribute or in a fileset, but still succeed. The task
- will also complain if more than one web.xml file is added to the JAR.
+ As the web.xml file is now optional, the webxml
attribute may now
+ be made optional. However, as most real web applications do need a web.xml file,
+ it is not optional by default. The task will fail if the file is not
+ included, unless the needxmlfile
attribute
+ is set to true
. The task
+ will warn if more than one web.xml file is added to the JAR
+ through the filesets.
-Please note that the zip format allows multiple files of the same
+
Please note that the Zip format allows multiple files of the same
fully-qualified name to exist within a single archive. This has been
documented as causing various problems for unsuspecting users. If you wish
to avoid this behavior you must set the duplicate
attribute
@@ -73,8 +76,18 @@ to a value other than its default, "add"
.
webxml |
- The deployment descriptor to use (WEB-INF/web.xml). |
- No (since Ant1.7) |
+ The servlet configuration descriptor to use (WEB-INF/web.xml). |
+ Yes, unless needxmlfile is true,
+ the file is pulled in via a nested fileset, or an existing WAR file is
+ being updated. |
+
+
+ needxmlfile |
+ Flag to indicate whether or not the web.xml file is needed.
+ I=it should be set to false when generating
+ servlet 2.5+ WAR files without a web.xml file.
+ Since Ant 1.7 |
+ No -default "true" |
basedir |
diff --git a/src/main/org/apache/tools/ant/taskdefs/War.java b/src/main/org/apache/tools/ant/taskdefs/War.java
index 96d3fced6..0981f55fb 100644
--- a/src/main/org/apache/tools/ant/taskdefs/War.java
+++ b/src/main/org/apache/tools/ant/taskdefs/War.java
@@ -55,11 +55,15 @@ public class War extends Jar {
/**
* flag set if the descriptor is added
*/
- private boolean descriptorAdded;
+ private boolean needxmlfile=true;
private File addedWebXmlFile;
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
- private static final String XML_DESCRIPTOR_PATH = "web-inf/web.xml";
+ /** path to web.xml file */
+ private static final String XML_DESCRIPTOR_PATH = "WEB-INF/web.xml";
+ /** lower case version for comparisons */
+ private static final String XML_DESCRIPTOR_PATH_LC =
+ XML_DESCRIPTOR_PATH.toLowerCase(Locale.ENGLISH);
/** Constructor for the War Task. */
public War() {
@@ -100,6 +104,15 @@ public class War extends Jar {
super.addFileset(fs);
}
+
+ /**
+ * Set the policy on the web.xml file, that is, whether or not it is needed
+ * @param needxmlfile whether a web.xml file is needed. Default: true
+ */
+ public void setNeedxmlfile(boolean needxmlfile) {
+ this.needxmlfile = needxmlfile;
+ }
+
/**
* add files under WEB-INF/lib/
* @param fs the zip file set to add
@@ -168,7 +181,7 @@ public class War extends Jar {
String vPathLowerCase = vPath.toLowerCase(Locale.ENGLISH);
//by default, we add the file.
boolean addFile = true;
- if (XML_DESCRIPTOR_PATH.equals(vPathLowerCase)) {
+ if (XML_DESCRIPTOR_PATH_LC.equals(vPathLowerCase)) {
//a web.xml file was found. See if it is a duplicate or not
if (addedWebXmlFile != null) {
//a second web.xml file, so skip it
@@ -189,7 +202,6 @@ public class War extends Jar {
//there is no web.xml file, so add it
addFile = true;
//and remember that we did
- descriptorAdded = true;
deploymentDescriptor = file;
}
}
@@ -204,10 +216,9 @@ public class War extends Jar {
* gets executed.
*/
protected void cleanUp() {
- if(addedWebXmlFile==null) {
- log("No WEB-INF/web.xml file was added.\n"
- +"This WAR file is only valid on Java EE 5+ runtimes\n"
- +"and web servers that support v2.5 Web Applications");
+ if(addedWebXmlFile==null && needxmlfile && !isInUpdateMode()) {
+ throw new BuildException("No WEB-INF/web.xml file was added.\n"
+ +"If this is your intent, set needxml='false' ");
}
addedWebXmlFile = null;
super.cleanUp();
diff --git a/src/tests/antunit/taskdefs/war-test.xml b/src/tests/antunit/taskdefs/war-test.xml
index 2a4281e96..8de6cdd2e 100644
--- a/src/tests/antunit/taskdefs/war-test.xml
+++ b/src/tests/antunit/taskdefs/war-test.xml
@@ -54,6 +54,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -83,7 +116,7 @@
Instead it pulls in
-->
-
+
@@ -91,11 +124,26 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -103,7 +151,7 @@
-
+