Apache Ant Task: zip |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Creates a zipfile.
The basedir attribute is the reference directory from where to zip. Note that file permissions will not be stored in the resulting zipfile. It is possible to refine the set of files that are being zipped. This can be done with the includes, includesfile, excludes, excludesfile and defaultexcludes attributes. With the includes or includesfile attribute you specify the files you want to have included by using patterns. The exclude or excludesfile attribute is used to specify the files you want to have excluded. This is also done with patterns. And finally with the defaultexcludes attribute, you can specify whether you want to use default exclusions or not. See the section on directory based tasks, on how the inclusion/exclusion of files works, and how to write patterns. This task forms an implicit FileSet and supports all attributes of (dir becomes basedir) as well as the nested , and elements. Or, you may place within it nested file sets, or references to file sets. In this case basedir is optional; the implicit file set is only used if basedir is set. You may use any mixture of the implicit file set (with basedir set, and optional attributes like includes and optional subelements like ); explicit nested elements so long as at least one fileset total is specified. The ZIP file will only reflect the relative paths of files within each fileset. The Zip task and its derivatives know a special form of a fileset named zipfileset that has additional attributes (described below). The Zip task also supports the merging of multiple zip files into the zip file. This is possible through either the src attribute of any nested filesets or by using the special nested fileset zipgroupfileset. The update parameter controls what happens if the ZIP file already exists. When set to yes, the ZIP file is updated with the files specified. (New files are added; old files are replaced with the new versions.) When set to no (the default) the ZIP file is overwritten if any of the files that would be added to the archive are newer than the entries inside the archive. Please note that ZIP files store file modification times with a granularity of two seconds. If a file is less than two seconds newer than the entry in the archive, Ant will not consider it newer. The whenempty parameter controls what happens when no files match. If skip (the default), the ZIP is not created and a warning is issued. If fail, the ZIP is not created and the build is halted with an error. If create, an empty ZIP file (explicitly zero entries) is created, which should be recognized as such by compliant ZIP manipulation tools. This task will now use the platform’s default character encoding for filenames – this is consistent with the command line ZIP tools, but causes problems if you try to open them from within Java and your filenames contain non US-ASCII characters. Use the encoding attribute and set it to UTF8 to create zip files that can safely be read by Java. Starting with Ant 1.5.2, can store Unix permissions inside the archive (see description of the filemode and dirmode attributes for ). Unfortunately there is no portable way to store these permissions. Ant uses the algorithm used by Info-Zip’s implementation of the zip and unzip commands – these are the default versions of zip and unzip for many Unix and Unix-like systems. 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 to a value other than its default, “add”. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Example: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Zips all files in the htdocs/manual directory into a file called manual.zip in the ${dist} directory. | zips all files in the htdocs/manual directory into a file called manual.zip in the ${dist} directory. If manual.zip doesn’t exist, it is created; otherwise it is updated with the new/changed files. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code:
basedir=”htdocs/manual” |
Code:
basedir=”htdocs/manual” |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Zips all files in the htdocs/manual directory. Files in the directory mydocs, or files with the name todo.html are excluded. | Zips all files in the htdocs/manual directory. Only html files under the directory api are zipped, and files with the name todo.html are excluded. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code:
basedir=”htdocs/manual” |
Code:
basedir=”htdocs/manual” |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Zips all files in the htdocs/manual directory, and also adds the file ChangeLog.txt in the current directory. ChangeLog.txt will be added to the top of the ZIP file, just as if it had been located at htdocs/manual/ChangeLog.txt. | zips all files in the htdocs/manual directory into the docs/user-guide directory in the archive, adds the file ChangeLog27.txt in the current directory as docs/ChangeLog.txt, and includes all the html files in exampleszip under docs/examples. The archive might end up containing the files: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code:
|
Code:: docs/user-guide/html/index.html docs/ChangeLog.txt docs/examples/index.html
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zips all files in the htdocs/manual directory into the docs/user-guide directory in the archive and includes all the files in any file that maches examples*.zip, such as all files within examples1.zip or examples_for_brian.zip. | Re-packages a TAR archive as a ZIP archive. If Unix file permissions have been stored as part of the TAR file, they will be retained in the resulting ZIP archive. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code:
|
Code::
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Debugging |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Apache Ant Task: Concat |
||||||||||||||||||||||||||||
Description: |
||||||||||||||||||||||||||||
Concatenates one or more resources to a single file or to the console. The destination file will be created if it does not exist. Since Ant 1.7.1, this task can be used as a Resource Collection that will return exactly one resource. | ||||||||||||||||||||||||||||
Parameters: |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
Example: |
||||||||||||||||||||||||||||
Concatenate a string to a file: | Concatenate a series of files to the console: | |||||||||||||||||||||||||||
Code:
Hello, World! |
Code:
|
|||||||||||||||||||||||||||
Concatenate a single file, appending if the destination file exists: | Concatenate a series of files, update the destination file only if is older that all the source files: | |||||||||||||||||||||||||||
Code:
|
Code:
force=”no”> files=”introduction.xml,overview.xml”/> includes=”sections/*.xml” |
|||||||||||||||||||||||||||
Concatenate a series of files, expanding ant properties | Filter the lines containing project from build.xml and output them to report.output, prepending with a header | |||||||||||||||||||||||||||
Code:
|
Code::
==========================
|
|||||||||||||||||||||||||||
Concatenate a number of binary files. | ||||||||||||||||||||||||||||
Code:
|
Code::
|
|||||||||||||||||||||||||||
Debugging |
||||||||||||||||||||||||||||
Apache Ant Task: ReplaceRegExp |
||||||||||||||||||||||
Description: |
||||||||||||||||||||||
ReplaceRegExp is a directory based task for replacing the occurrence of a given regular expression with a substitution pattern in a selected file or set of files.The output file is only written if it differs from the existing file. This prevents spurious rebuilds based on unchanged files which have been regenerated by this task. | ||||||||||||||||||||||
Parameters: |
||||||||||||||||||||||
|
||||||||||||||||||||||
Example: |
||||||||||||||||||||||
Replaces occurrences of the property name “OldProperty” with “NewProperty” in a properties file, preserving the existing value, in the file ${src}/build.properties | This task supports a nested Regexp element to specify the regular expression. You can use this element to refer to a previously defined regular expression datatype instance. | |||||||||||||||||||||
Code:
match=”OldProperty=(.*)” |
Code:
|
|||||||||||||||||||||
This task supports a nested Substitution element to specify the substitution pattern. You can use this element to refer to a previously defined substitution pattern datatype instance. | Replaces occurrences of the property name “OldProperty” with “NewProperty” in a properties file, preserving the existing value, in all files ending in .properties in the current directory | |||||||||||||||||||||
Code:
|
Code:
|
|||||||||||||||||||||
Replaces all whitespaces (blanks, tabs, etc) by one blank remaining the line separator. So with input | Check that both files one.txt and two.txt are present otherwise the build will fail. | |||||||||||||||||||||
Code:
replaces all whitespaces (blanks, tabs, etc) by one blank remaining the line separator. So with input <> T E S T<> would converted to
T E S T
|
Code::
|
|||||||||||||||||||||
Debugging |
||||||||||||||||||||||
Apache Ant Task: Checksum |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
Generates checksum for files. This task can also be used to perform checksum verifications.
Note that many popular message digest functions – including MD5 and SHA-1 – have been broken recently. If you are going to use the task to create checksums used in an environment where security is important, please take some time to investigate the algorithms offered by your JCE provider. Note also that some JCE providers like the one by The Legion of the Bouncy Castle, the GNU project or the Technical University Graz offer more digest algorithms than those built-in into your JDK. Warning: the case of the extension is that of the algorithm used. If you ask for “SHA1”, you get a .SHA1 extension; if you ask for “sha1”, you get a file ending in .sha1. The Java Crypto Engines are case-insensitive in matching algorithms, so choose a name to match your desired output extension, or set the fileext attribute. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
Example: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
Generates a MD5 checksum for foo.bar and stores the checksum in the destination file foo.bar.MD5. foo.bar.MD5 is overwritten only if foo.bar is newer than itself. | Generates a MD5 checksum for foo.bar and stores the checksum in foo.bar.MD5. If foo.bar.MD5 already exists, it is overwritten. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code:
|
Code:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Generates a MD5 checksum for foo.bar and stores it in the Project Property foobarMD5. | Generates a MD5 checksum for foo.bar, compares it against foo.bar.MD5 and sets isMD5ok to either true or false, depending upon the result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code:
|
Code:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Generates a SHA checksum for foo.bar and stores the checksum in the destination file foo.bar.asc. foo.bar.asc is overwritten only if foo.bar is newer than itself. | Generates a MD5 checksum for foo.bar, compares it against the value of the property md5, and sets isEqual to either true or false, depending upon the result. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code:
|
Code::
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Works just like Example 1, but generates a .MD5 file for every file that begins with the name foo. | Works like Example 4, but only sets isChecksumEqual to true, if the checksum matches – it will never be set to false. This example demonstrates use with the Condition task. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code:
|
Code::
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Debugging |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
Apache Ant Task: Fail |
||||||||||||||||
Description: |
||||||||||||||||
Exits the current build (just throwing a BuildException), optionally printing additional information.The message of the Exception can be set via the message attribute or character data nested into the element. | ||||||||||||||||
Parameters: |
||||||||||||||||
|
||||||||||||||||
Example: |
||||||||||||||||
Exit the current build with no further information given. | Exit the current build and print something like the following to wherever your output goes: | |||||||||||||||
Code:
|
Code:
|
|||||||||||||||
BUILD FAILED build.xml:4: No message |
BUILD FAILED build.xml:4: Something wrong here. |
|||||||||||||||
Exit the current build and print something like the following to wherever your output goes: | Exit the current build and print something like the following to wherever your output goes: | |||||||||||||||
Code:
Something wrong here. |
Code:
|
|||||||||||||||
BUILD FAILED build.xml:4: Something wrong here. |
BUILD FAILED build.xml:2: unless=thisdoesnotexist |
|||||||||||||||
Using a condition to achieve the same effect | Check that both files one.txt and two.txt are present otherwise the build will fail. | |||||||||||||||
Code:
|
Code::
|
|||||||||||||||
BUILD FAILED build.xml:2: condition satisfied |
Output: | |||||||||||||||
Debugging |
||||||||||||||||
- How to Choose Wireless Access Points for Office - December 13, 2024
- Online Real Estate Courses: Navigating the Shift to Digital Education - December 13, 2024
- From Concept to Implementation: IoT Services Redefining Modern Solutions - December 13, 2024