source: release-kits/lirk3/ant-scripts/tasks/antelope/docs/manual/bk03ch23.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 7.3 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 23. Split Task</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="index.html" title="Antelope Users Guide"><link rel="up" href="bk03.html" title="Additional Ant Tasks"><link rel="prev" href="bk03ch22.html" title="Chapter 22. Grep Task"><link rel="next" href="bk03ch24.html" title="Chapter 24. Repeat Task"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 23. Split Task</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03ch22.html">Prev</a> </td><th width="60%" align="center">Additional Ant Tasks</th><td width="20%" align="right"> <a accesskey="n" href="bk03ch24.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="Split"></a>Chapter 23. Split Task</h2></div></div></div>
2<STYLE TYPE="text/css"> <!-- @import url(./style.css); --> </STYLE>
3 <p>
4This task splits a property or file into pieces. This is similar to the "split" utility found on most Unix and Linux distributions.
5</p><p>
6To use this task in your build files, include a task definition like this:
7</p><p>
8</p><pre class="programlisting">
9
10 &lt;taskdef name="split" classname="ise.antelope.tasks.SplitTask"/&gt;
11
12</pre><p>
13</p><p>
14Once a file has been split into smaller pieces, it can be rejoined with the "concat" task that is part of the standard Ant core tasks.
15</p><p>
16</p><div class="table"><a name="id2525260"></a><p class="title"><b>Table 23.1. Split Task Attributes</b></p><table summary="Split Task Attributes" border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>prefix</td><td>The start of the filename(s) to write the parts to.</td><td>x</td><td>No</td></tr><tr><td>bytes</td><td>How big, in bytes, to make the individual pieces. In general, use lines for text files, bytes or size for binary files.</td><td>None</td><td>No</td></tr><tr><td>size</td><td>How big to make the individual pieces. Like the Unix/Linux split utility, this attribute allows modifiers: b for 512, k for 1K, m for 1 Meg, so 100k is the same as passing 102400 in the bytes attribute. In general, use lines for text files, bytes or size for binary files.</td><td>None</td><td>No</td></tr><tr><td>lines</td><td>How big to make the individual pieces in lines. In general, use lines for text files, bytes or size for binary files.</td><td>1000</td><td>No</td></tr><tr><td>property</td><td>Split the value of the property into several files.</td><td>None</td><td>No</td></tr><tr><td>string</td><td>Split this string into several files.</td><td>None</td><td>No</td></tr><tr><td>file</td><td>Split this file into several files.</td><td>None</td><td>No</td></tr><tr><td>outputdir</td><td>Destination for the output files.</td><td>None</td><td>Maybe. If file is given and output dir is not, will write to the same directory as file, otherwise, this is a required attribute.</td></tr><tr><td>failonerror</td><td>Should the build stop if this task fails?</td><td>Yes</td><td>No</td></tr></tbody></table></div><p>
17</p><p>
18Examples
19</p><p>
20Split the value of a property into several files:
21</p><pre class="programlisting">
22
23 &lt;target name="test1" depends="clean"&gt;
24 &lt;property name="prop1" value="ABCDE"/&gt;
25 &lt;a:split property="prop1" bytes="1" outputdir="${out_dir}"/&gt;
26 &lt;a:fileutil file="${out_dir}" property="file_count"&gt;
27 &lt;a:filecount/&gt;
28 &lt;/a:fileutil&gt;
29 &lt;a:assert message="Expected 5 files, got ${file_count}"&gt;
30 &lt;bool&gt;
31 &lt;a:mathequals arg1="5" arg2="${file_count}"/&gt;
32 &lt;/bool&gt;
33 &lt;/a:assert&gt;
34 &lt;/target&gt;
35
36</pre><p>
37This will result in 5 files named x.0, x.1, x.2, x.3, and x.4, each containing a single character.
38</p><p>
39This more involved example shows how to split ant.jar into several files each 100000 bytes in size. The files will be names ant.jar.0, ant.jar.1, ..., ant.jar.10. Then the parts are put back together with concat.
40</p><pre class="programlisting">
41
42 &lt;target name="test2" depends="clean"&gt;
43 &lt;!-- make sure ant.jar is available --&gt;
44 &lt;property name="ant.jar" value="${ant.library.dir}/ant.jar"/&gt;
45 &lt;available property="ant.jar.available" file="${ant.jar}"/&gt;
46
47 &lt;a:if name="ant.jar.available" value="true"&gt;
48 &lt;!-- ant.jar generally runs around 1MB in size, so split into 100000 byte pieces --&gt;
49 &lt;a:unset name="piece_size"/&gt;
50 &lt;property name="piece_size" value="100000"/&gt;
51 &lt;a:split file="${ant.jar}" bytes="${piece_size}" outputdir="${out_dir}" prefix="ant.jar"/&gt;
52
53 &lt;!-- count the parts --&gt;
54 &lt;a:fileutil file="${out_dir}" property="file_count"&gt;
55 &lt;a:filecount/&gt;
56 &lt;/a:fileutil&gt;
57
58 &lt;!-- calculate how many parts there should be --&gt;
59 &lt;a:fileutil file="${ant.jar}" property="ant_size"&gt;
60 &lt;a:filelength/&gt;
61 &lt;/a:fileutil&gt;
62 &lt;a:math result="split_size"&gt;
63 &lt;a:op op="ceil"&gt;
64 &lt;a:op op="/"&gt;
65 &lt;a:num value="${ant_size}"/&gt;
66 &lt;a:num value="${piece_size}"/&gt;
67 &lt;/a:op&gt;
68 &lt;/a:op&gt;
69 &lt;/a:math&gt;
70
71 &lt;!-- make sure there are the right number of parts --&gt;
72 &lt;a:assert message="Expected ${split_size} files, got ${file_count}"&gt;
73 &lt;bool&gt;
74 &lt;a:mathequals arg1="${split_size}" arg2="${file_count}"/&gt;
75 &lt;/bool&gt;
76 &lt;/a:assert&gt;
77
78 &lt;!-- sort the filenames of the parts so concat puts them together in
79 the right order--&gt;
80 &lt;a:fileutil file="${out_dir}" property="file_list"&gt;
81 &lt;a:listfiles includepath="no"/&gt;
82 &lt;/a:fileutil&gt;
83 &lt;a:stringutil string="${file_list}" property="file_list"&gt;
84 &lt;a:sort/&gt;
85 &lt;/a:stringutil&gt;
86
87 &lt;!-- put them back together --&gt;
88 &lt;concat destfile="${out_dir}/ant.jar" binary="true"&gt;
89 &lt;filelist dir="${out_dir}" files="${file_list}"/&gt;
90 &lt;/concat&gt;
91
92 &lt;!-- make sure the new file is the identical to the original --&gt;
93 &lt;a:assert message="concat did not produce identical file"&gt;
94 &lt;bool&gt;
95 &lt;filesmatch file1="${ant.jar}" file2="${out_dir}/ant.jar"/&gt;
96 &lt;/bool&gt;
97 &lt;/a:assert&gt;
98 &lt;/a:if&gt;
99 &lt;/target&gt;
100
101</pre><p>
102</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03ch22.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk03ch24.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 22. Grep Task </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 24. Repeat Task</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.