ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r468568 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/war.html src/main/org/apache/tools/ant/taskdefs/War.java src/tests/antunit/taskdefs/war-test.xml
Date Fri, 27 Oct 2006 22:33:43 GMT
Author: stevel
Date: Fri Oct 27 15:33:42 2006
New Revision: 468568

URL: http://svn.apache.org/viewvc?view=rev&rev=468568
Log:
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.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/war.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java
    ant/core/trunk/src/tests/antunit/taskdefs/war-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=468568&r1=468567&r2=468568
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Oct 27 15:33:42 2006
@@ -28,9 +28,8 @@
   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.
 

Modified: ant/core/trunk/docs/manual/CoreTasks/war.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/war.html?view=diff&rev=468568&r1=468567&r2=468568
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/war.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/war.html Fri Oct 27 15:33:42 2006
@@ -41,14 +41,17 @@
 <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 @@
   </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>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java?view=diff&rev=468568&r1=468567&r2=468568
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java Fri Oct 27 15:33:42 2006
@@ -55,11 +55,15 @@
     /**
      * 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 @@
         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 @@
         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 @@
                 //there is no web.xml file, so add it
                 addFile = true;
                 //and remember that we did
-                descriptorAdded = true;
                 deploymentDescriptor = file;
             }
         }
@@ -204,10 +216,9 @@
      * 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();

Modified: ant/core/trunk/src/tests/antunit/taskdefs/war-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/war-test.xml?view=diff&rev=468568&r1=468567&r2=468568
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/war-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/war-test.xml Fri Oct 27 15:33:42 2006
@@ -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/>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message