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-ffa450edef68master
@@ -28,9 +28,8 @@ Other changes: | |||
Bugzilla 40019. | |||
* <war> 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. | |||
@@ -41,14 +41,17 @@ attributes of zipfilesets in a Zip or Jar task.)</p> | |||
<p> | |||
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 <code>webxml</code> attribute was missing. | |||
As the web.xml file is now optional, the <code>webxml</code> 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 <code>webxml</code> 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 <code>needxmlfile</code> attribute | |||
is set to <code>true</code>. The task | |||
will warn if more than one web.xml file is added to the JAR | |||
through the filesets. | |||
</p> | |||
<p><b>Please note that the zip format allows multiple files of the same | |||
<p><b>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 <code>duplicate</code> attribute | |||
@@ -73,8 +76,18 @@ to a value other than its default, <code>"add"</code>.</b></p> | |||
</tr> | |||
<tr> | |||
<td valign="top">webxml</td> | |||
<td valign="top">The deployment descriptor to use (WEB-INF/web.xml).</td> | |||
<td valign="top" align="center">No (since Ant1.7)</td> | |||
<td valign="top">The servlet configuration descriptor to use (WEB-INF/web.xml).</td> | |||
<td valign="top" align="center">Yes, unless <tt>needxmlfile</tt> is true, | |||
the file is pulled in via a nested fileset, or an existing WAR file is | |||
being updated.</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">needxmlfile</td> | |||
<td valign="top">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. | |||
<em>Since Ant 1.7</em></td> | |||
<td valign="top" align="center">No -default "true"</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">basedir</td> | |||
@@ -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(); | |||
@@ -54,6 +54,39 @@ | |||
<au:assertFileExists file="${webxml.generated}" /> | |||
</target> | |||
<target name="testWebXmlMissingFromUpdate" depends="init"> | |||
<mkwar webxml="${web.xml}" /> | |||
<!-- there is no web.xml file, but that is ok, as | |||
we are updating --> | |||
<mkwar update="true"> | |||
<classes dir="." includes="web.xml"/> | |||
</mkwar> | |||
<expandwar/> | |||
<au:assertFileExists file="${webxml.generated}" /> | |||
</target> | |||
<target name="testWebXmlInImplicitUpdate" depends="init"> | |||
<mkwar webxml="${web.xml}" /> | |||
<!-- when we are implicitly updating, the web.xml file does not get | |||
pulled in, but the command still succeeds.--> | |||
<mkwar webxml="${web.xml}" > | |||
<classes dir="." includes="web.xml"/> | |||
</mkwar> | |||
<expandwar/> | |||
<au:assertFileExists file="${webxml.generated}" /> | |||
</target> | |||
<target name="NotestWebXmlFilesetInImplicitUpdate" depends="init"> | |||
<mkwar webxml="${web.xml}" /> | |||
<!-- when we are implicitly updating, the web.xml file does not get | |||
pulled in, but the command still succeeds.--> | |||
<mkwar > | |||
<webinf dir="." includes="web.xml"/> | |||
</mkwar> | |||
<expandwar/> | |||
<au:assertFileExists file="${webxml.generated}" /> | |||
</target> | |||
<target name="testDuplicateWebXml" depends="init"> | |||
<mkwar webxml="${web.xml}" > | |||
@@ -83,7 +116,7 @@ | |||
Instead it pulls in | |||
--> | |||
<target name="testWebXmlOptional" depends="init"> | |||
<mkwar > | |||
<mkwar needxmlfile="false"> | |||
<classes dir="." includes="web.xml"/> | |||
</mkwar> | |||
<expandwar/> | |||
@@ -91,11 +124,26 @@ | |||
<au:assertFalse> | |||
<available file="${webxml.generated}" /> | |||
</au:assertFalse> | |||
<au:assertLogContains text="This WAR file is only valid on Java EE 5+ runtimes"/> | |||
</target> | |||
<target name="testWebXmlOptionalFailure" depends="init"> | |||
<au:expectfailure> | |||
<mkwar > | |||
<classes dir="." includes="web.xml"/> | |||
</mkwar> | |||
</au:expectfailure> | |||
</target> | |||
<target name="testWebXmlOptionalFailure2" depends="init"> | |||
<au:expectfailure> | |||
<mkwar needxmlfile="true"> | |||
<classes dir="." includes="web.xml"/> | |||
</mkwar> | |||
</au:expectfailure> | |||
</target> | |||
<target name="testClassesElement" depends="init"> | |||
<mkwar > | |||
<mkwar needxmlfile="false"> | |||
<classes dir="." includes="web.xml"/> | |||
</mkwar> | |||
<expandwar/> | |||
@@ -103,7 +151,7 @@ | |||
</target> | |||
<target name="testLibElement" depends="init"> | |||
<mkwar > | |||
<mkwar needxmlfile="false"> | |||
<lib dir="." includes="web.xml"/> | |||
</mkwar> | |||
<expandwar/> | |||