You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

war-test.xml 6.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <project name="war-test" basedir="." default="antunit"
  17. xmlns:au="antlib:org.apache.ant.antunit">
  18. <property name="working.dir" value="working"/>
  19. <import file="../antunit-base.xml" />
  20. <target name="init">
  21. <delete dir="${working.dir}"/>
  22. <mkdir dir="${working.dir}"/>
  23. <property name="warfile" location="${working.dir}/test.war"/>
  24. <property name="web.xml" location="web.xml"/>
  25. <property name="webxml.generated" location="${working.dir}/WEB-INF/web.xml"/>
  26. <!--failing on duplicates is half our testing-->
  27. <presetdef name="mkwar">
  28. <war destfile="${warfile}" duplicate="fail"/>
  29. </presetdef>
  30. <presetdef name="expandwar">
  31. <unzip src="${working.dir}/test.war" dest="${working.dir}"/>
  32. </presetdef>
  33. </target>
  34. <target name="tearDown">
  35. <delete dir="${working.dir}"/>
  36. </target>
  37. <!--test that you can patch a fileset reference into a lib element-->
  38. <target name="testlibrefs" depends="init">
  39. <mkwar webxml="${web.xml}">
  40. <fileset id="test" dir="." includes="web.xml"/>
  41. <lib refid="test"/>
  42. </mkwar>
  43. <expandwar/>
  44. <au:assertFileExists file="${webxml.generated}" />
  45. </target>
  46. <!--
  47. This checks that as of Java EE 5, the web.xml attr is optional.
  48. Here there is a web.xml, in the webinf fileset, rather than a fileset
  49. -->
  50. <target name="testWebXmlInWebinf" depends="init">
  51. <mkwar>
  52. <webinf dir="." includes="web.xml"/>
  53. </mkwar>
  54. <expandwar/>
  55. <au:assertFileExists file="${webxml.generated}" />
  56. </target>
  57. <target name="testWebXmlMissingFromUpdate" depends="init">
  58. <mkwar webxml="${web.xml}" />
  59. <!-- there is no web.xml file, but that is ok, as
  60. we are updating -->
  61. <mkwar update="true">
  62. <classes dir="." includes="web.xml"/>
  63. </mkwar>
  64. <expandwar/>
  65. <au:assertFileExists file="${webxml.generated}" />
  66. </target>
  67. <target name="testWebXmlInImplicitUpdate" depends="init">
  68. <mkwar webxml="${web.xml}" />
  69. <!-- when we are implicitly updating, the web.xml file does not get
  70. pulled in, but the command still succeeds.-->
  71. <mkwar webxml="${web.xml}" >
  72. <classes dir="." includes="web.xml"/>
  73. </mkwar>
  74. <expandwar/>
  75. <au:assertFileExists file="${webxml.generated}" />
  76. </target>
  77. <target name="NotestWebXmlFilesetInImplicitUpdate" depends="init">
  78. <mkwar webxml="${web.xml}" />
  79. <!-- when we are implicitly updating, the web.xml file does not get
  80. pulled in, but the command still succeeds.-->
  81. <mkwar >
  82. <webinf dir="." includes="web.xml"/>
  83. </mkwar>
  84. <expandwar/>
  85. <au:assertFileExists file="${webxml.generated}" />
  86. </target>
  87. <target name="testDuplicateWebXml" depends="init">
  88. <mkwar webxml="${web.xml}" >
  89. <webinf dir="." includes="web.xml"/>
  90. <webinf file="${web.xml}"/>
  91. <zipfileset file="${web.xml}" prefix="WEB-INF"/>
  92. </mkwar>
  93. <expandwar/>
  94. <au:assertFileExists file="${webxml.generated}" />
  95. </target>
  96. <target name="testDifferentDuplicateWebXml" depends="init">
  97. <copy file="${web.xml}" todir="${working.dir}" />
  98. <mkwar webxml="${web.xml}" >
  99. <webinf dir="${working.dir}" includes="web.xml"/>
  100. <webinf file="${web.xml}"/>
  101. <zipfileset file="${web.xml}" prefix="WEB-INF"/>
  102. </mkwar>
  103. <expandwar/>
  104. <au:assertFileExists file="${webxml.generated}" />
  105. <au:assertLogContains text="The duplicate entry is"/>
  106. </target>
  107. <!--
  108. this target does not have a web.xml file.
  109. Instead it pulls in
  110. -->
  111. <target name="testWebXmlOptional" depends="init">
  112. <mkwar needxmlfile="false">
  113. <classes dir="." includes="web.xml"/>
  114. </mkwar>
  115. <expandwar/>
  116. <au:assertFileExists file="${working.dir}/WEB-INF/classes/web.xml" />
  117. <au:assertFalse>
  118. <available file="${webxml.generated}" />
  119. </au:assertFalse>
  120. </target>
  121. <target name="testWebXmlOptionalFailure" depends="init">
  122. <au:expectfailure>
  123. <mkwar >
  124. <classes dir="." includes="web.xml"/>
  125. </mkwar>
  126. </au:expectfailure>
  127. </target>
  128. <target name="testWebXmlOptionalFailure2" depends="init">
  129. <au:expectfailure>
  130. <mkwar needxmlfile="true">
  131. <classes dir="." includes="web.xml"/>
  132. </mkwar>
  133. </au:expectfailure>
  134. </target>
  135. <target name="testClassesElement" depends="init">
  136. <mkwar needxmlfile="false">
  137. <classes dir="." includes="web.xml"/>
  138. </mkwar>
  139. <expandwar/>
  140. <au:assertFileExists file="${working.dir}/WEB-INF/classes/web.xml" />
  141. </target>
  142. <target name="testLibElement" depends="init">
  143. <mkwar needxmlfile="false">
  144. <lib dir="." includes="web.xml"/>
  145. </mkwar>
  146. <expandwar/>
  147. <au:assertFileExists file="${working.dir}/WEB-INF/lib/web.xml" />
  148. </target>
  149. <target name="testMappedClasspathFromManual">
  150. <mkdir dir="${input}"/>
  151. <mkdir dir="${output}/out"/>
  152. <war destfile="${output}/test.war" webxml="${ant.file}">
  153. <mappedresources>
  154. <restrict>
  155. <path path="${java.class.path}"/>
  156. <type type="file"/>
  157. </restrict>
  158. <chainedmapper>
  159. <flattenmapper/>
  160. <globmapper from="*" to="WEB-INF/lib/*"/>
  161. </chainedmapper>
  162. </mappedresources>
  163. </war>
  164. <unzip src="${output}/test.war" dest="${output}/out"/>
  165. <au:assertFileExists file="${output}/out/WEB-INF/lib/ant.jar"/>
  166. </target>
  167. </project>