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.java 8.1 kB

Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
Addition of ZipFileset facilities. Descibed by the author --- With these patches, Zip (and derivative tasks such as Jar and War) can merge the entries of multiple zip files into a single output zip file. The contents of an input zip file may be selectively extracted based on include/exclude patterns. An included zip file is specified using a <fileset> with a "src" attribute, as in: <target name="jartest"> <jar jarfile="utils.jar"> <fileset src="weblogic.jar" includes="weblogic/utils/" excludes="weblogic/utils/jars/,**/reflect/" /> </jar> </target> In this example, a subset of the "weblogic/utils" directory is extracted from weblogic.jar, into utils.jar. The fileset may also contain "prefix" and "fullpath" attributes (the functionality of PrefixedFileSet has been retained in the new class ZipFileSet). Prefixes apply to directory-based and zip-based filesets. The fullpath attributes applies only to a single file in a directory-based fileset. The War task may extract entries from a zip file for all of its filesets (including the files in "classes" and "lib"). The motivation for this change is: 1) There is significant overlap between "jlink" and "zip", and it seemed better to combine them. 2) "jlink" does not support include/exclude patterns which are extremely useful for writing packaging-type tasks such as Zip/Jar/War. This was my main motivation. 3) By adding this functionality to the base task, it can also be used in derivative tasks such as Jar and War. --- Submitted By: Don Ferguson <don@bea.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268458 13f79535-47bb-0310-9956-ffa450edef68
25 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant.taskdefs;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import java.util.Locale;
  22. import org.apache.tools.ant.BuildException;
  23. import org.apache.tools.ant.Project;
  24. import org.apache.tools.ant.types.ZipFileSet;
  25. import org.apache.tools.ant.util.FileUtils;
  26. import org.apache.tools.zip.ZipOutputStream;
  27. /**
  28. * An extension of &lt;jar&gt; to create a WAR archive.
  29. * Contains special treatment for files that should end up in the
  30. * <code>WEB-INF/lib</code>, <code>WEB-INF/classes</code> or
  31. * <code>WEB-INF</code> directories of the Web Application Archive.</p>
  32. * <p>(The War task is a shortcut for specifying the particular layout of a WAR file.
  33. * The same thing can be accomplished by using the <i>prefix</i> and <i>fullpath</i>
  34. * attributes of zipfilesets in a Zip or Jar task.)</p>
  35. * <p>The extended zipfileset element from the zip task
  36. * (with attributes <i>prefix</i>, <i>fullpath</i>, and <i>src</i>)
  37. * is available in the War task.</p>
  38. *
  39. * @since Ant 1.2
  40. *
  41. * @ant.task category="packaging"
  42. * @see Jar
  43. */
  44. public class War extends Jar {
  45. /**
  46. * our web.xml deployment descriptor
  47. */
  48. private File deploymentDescriptor;
  49. /**
  50. * flag set if the descriptor is added
  51. */
  52. private boolean needxmlfile = true;
  53. private File addedWebXmlFile;
  54. private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
  55. /** path to web.xml file */
  56. private static final String XML_DESCRIPTOR_PATH = "WEB-INF/web.xml";
  57. /** lower case version for comparisons */
  58. private static final String XML_DESCRIPTOR_PATH_LC =
  59. XML_DESCRIPTOR_PATH.toLowerCase(Locale.ENGLISH);
  60. /** Constructor for the War Task. */
  61. public War() {
  62. super();
  63. archiveType = "war";
  64. emptyBehavior = "create";
  65. }
  66. /**
  67. * <i>Deprecated<i> name of the file to create
  68. * -use <tt>destfile</tt> instead.
  69. * @param warFile the destination file
  70. * @deprecated since 1.5.x.
  71. * Use setDestFile(File) instead
  72. * @ant.attribute ignore="true"
  73. */
  74. public void setWarfile(File warFile) {
  75. setDestFile(warFile);
  76. }
  77. /**
  78. * set the deployment descriptor to use (WEB-INF/web.xml);
  79. * required unless <tt>update=true</tt>
  80. * @param descr the deployment descriptor file
  81. */
  82. public void setWebxml(File descr) {
  83. deploymentDescriptor = descr;
  84. if (!deploymentDescriptor.exists()) {
  85. throw new BuildException("Deployment descriptor: "
  86. + deploymentDescriptor
  87. + " does not exist.");
  88. }
  89. // Create a ZipFileSet for this file, and pass it up.
  90. ZipFileSet fs = new ZipFileSet();
  91. fs.setFile(deploymentDescriptor);
  92. fs.setFullpath(XML_DESCRIPTOR_PATH);
  93. super.addFileset(fs);
  94. }
  95. /**
  96. * Set the policy on the web.xml file, that is, whether or not it is needed
  97. * @param needxmlfile whether a web.xml file is needed. Default: true
  98. */
  99. public void setNeedxmlfile(boolean needxmlfile) {
  100. this.needxmlfile = needxmlfile;
  101. }
  102. /**
  103. * add files under WEB-INF/lib/
  104. * @param fs the zip file set to add
  105. */
  106. public void addLib(ZipFileSet fs) {
  107. // We just set the prefix for this fileset, and pass it up.
  108. fs.setPrefix("WEB-INF/lib/");
  109. super.addFileset(fs);
  110. }
  111. /**
  112. * add files under WEB-INF/classes
  113. * @param fs the zip file set to add
  114. */
  115. public void addClasses(ZipFileSet fs) {
  116. // We just set the prefix for this fileset, and pass it up.
  117. fs.setPrefix("WEB-INF/classes/");
  118. super.addFileset(fs);
  119. }
  120. /**
  121. * files to add under WEB-INF;
  122. * @param fs the zip file set to add
  123. */
  124. public void addWebinf(ZipFileSet fs) {
  125. // We just set the prefix for this fileset, and pass it up.
  126. fs.setPrefix("WEB-INF/");
  127. super.addFileset(fs);
  128. }
  129. /**
  130. * override of parent; validates configuration
  131. * before initializing the output stream.
  132. * @param zOut the zip output stream
  133. * @throws IOException on output error
  134. * @throws BuildException if invalid configuration
  135. */
  136. protected void initZipOutputStream(ZipOutputStream zOut)
  137. throws IOException, BuildException {
  138. super.initZipOutputStream(zOut);
  139. }
  140. /**
  141. * Overridden from Zip class to deal with web.xml
  142. *
  143. * Here are cases that can arise
  144. * -not a web.xml file : add
  145. * -first web.xml : add, remember we added it
  146. * -same web.xml again: skip
  147. * -alternate web.xml : warn and skip
  148. *
  149. * @param file the file to add to the archive
  150. * @param zOut the stream to write to
  151. * @param vPath the name this entry shall have in the archive
  152. * @param mode the Unix permissions to set.
  153. * @throws IOException on output error
  154. */
  155. protected void zipFile(File file, ZipOutputStream zOut, String vPath,
  156. int mode)
  157. throws IOException {
  158. // If the file being added is WEB-INF/web.xml, we warn if it's
  159. // not the one specified in the "webxml" attribute - or if
  160. // it's being added twice, meaning the same file is specified
  161. // by the "webxml" attribute and in a <fileset> element.
  162. String vPathLowerCase = vPath.toLowerCase(Locale.ENGLISH);
  163. //by default, we add the file.
  164. boolean addFile = true;
  165. if (XML_DESCRIPTOR_PATH_LC.equals(vPathLowerCase)) {
  166. //a web.xml file was found. See if it is a duplicate or not
  167. if (addedWebXmlFile != null) {
  168. //a second web.xml file, so skip it
  169. addFile = false;
  170. //check to see if we warn or not
  171. if (!FILE_UTILS.fileNameEquals(addedWebXmlFile, file)) {
  172. logWhenWriting("Warning: selected " + archiveType
  173. + " files include a second "
  174. + XML_DESCRIPTOR_PATH
  175. + " which will be ignored.\n"
  176. + "The duplicate entry is at " + file + '\n'
  177. + "The file that will be used is "
  178. + addedWebXmlFile,
  179. Project.MSG_WARN);
  180. }
  181. } else {
  182. //no added file, yet
  183. addedWebXmlFile = file;
  184. //there is no web.xml file, so add it
  185. addFile = true;
  186. //and remember that we did
  187. deploymentDescriptor = file;
  188. }
  189. }
  190. if (addFile) {
  191. super.zipFile(file, zOut, vPath, mode);
  192. }
  193. }
  194. /**
  195. * Make sure we don't think we already have a web.xml next time this task
  196. * gets executed.
  197. */
  198. protected void cleanUp() {
  199. if (addedWebXmlFile == null
  200. && deploymentDescriptor == null
  201. && needxmlfile
  202. && !isInUpdateMode()
  203. && hasUpdatedFile()) {
  204. throw new BuildException("No WEB-INF/web.xml file was added.\n"
  205. + "If this is your intent, set needxmlfile='false' ");
  206. }
  207. addedWebXmlFile = null;
  208. super.cleanUp();
  209. }
  210. }