Browse Source

allow more path 'views' of a file as elements inside <checksum>s pattern. PR 50114

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1027103 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 14 years ago
parent
commit
b4b082c568
4 changed files with 58 additions and 3 deletions
  1. +4
    -0
      WHATSNEW
  2. +9
    -3
      docs/manual/Tasks/checksum.html
  3. +10
    -0
      src/main/org/apache/tools/ant/taskdefs/Checksum.java
  4. +35
    -0
      src/tests/antunit/taskdefs/checksum-test.xml

+ 4
- 0
WHATSNEW View File

@@ -232,6 +232,10 @@ Other changes:
* <javah> now supports the GNU project's gcjh compiler.
Bugzilla Report 50149.

* <checksum> supports additional views of a file's path as elements
for a custom pattern.
Bugzilla Report 50114.

Changes from Ant 1.8.0 TO Ant 1.8.1
===================================



+ 9
- 3
docs/manual/Tasks/checksum.html View File

@@ -113,10 +113,16 @@ or set the <tt>fileext</tt> attribute.
<tr>
<td valign="top">pattern</td>
<td valign="top">Specifies the pattern to use as a pattern
suitable for <a
href="http://download.oracle.com/javase/6/docs/api/java/text/MessageFormat.html">MessageFormat</a>
suitable
for <a href="http://download.oracle.com/javase/6/docs/api/java/text/MessageFormat.html">MessageFormat</a>
where <code>{0}</code> is replaced with the checksum and
<code>{1}</code> with the file name. <em>Since Ant 1.7.0</em></td>
<code>{1}</code> with the file name. <em>Since Ant
1.7.0</em><br/>
<em>starting with Ant 1.8.2</em> <code>{2}</code> is replaced by
the path of the file relative to the checksum file being
written, <code>{3}</code> with tha path of the file relative to
the project's basedir and <code>{4}</code> with the absolute
path of the file.</td>
<td valign="top" align="center">No - default is &quot;{0}&quot;.</td>
</tr>
<tr>


+ 10
- 0
src/main/org/apache/tools/ant/taskdefs/Checksum.java View File

@@ -61,6 +61,7 @@ import org.apache.tools.ant.util.StringUtils;
*/
public class Checksum extends MatchingTask implements Condition {

private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static final int NIBBLE = 4;
private static final int WORD = 16;
private static final int BUFFER_SIZE = 8 * 1024;
@@ -531,6 +532,15 @@ public class Checksum extends MatchingTask implements Condition {
fos.write(format.format(new Object[] {
checksum,
src.getName(),
FILE_UTILS
.getRelativePath(dest
.getParentFile(),
src),
FILE_UTILS
.getRelativePath(getProject()
.getBaseDir(),
src),
src.getAbsolutePath()
}).getBytes());
fos.write(StringUtils.LINE_SEP.getBytes());
fos.close();


+ 35
- 0
src/tests/antunit/taskdefs/checksum-test.xml View File

@@ -45,4 +45,39 @@
value="f4d688789d32e6ca6bc93c504dbc6b46"/>
</target>

<target name="testChecksumPattern2">
<mkdir dir="${output}"/>
<mkdir dir="${input}"/>
<echo file="${input}/a.txt">abc</echo>
<checksum todir="${output}" pattern="{2}">
<fileset dir="${input}"/>
</checksum>
<au:assertResourceContains
resource="${output}/a.txt.MD5"
value="../testinput/a.txt"/>
</target>

<target name="testChecksumPattern3">
<mkdir dir="${output}"/>
<checksum todir="${output}" pattern="{3}">
<fileset dir=".." includes="types/fileset-test.xml"/>
</checksum>
<au:assertResourceContains
resource="${output}/types/fileset-test.xml.MD5"
value="../types/fileset-test.xml"/>
</target>

<target name="testChecksumPattern4">
<mkdir dir="${output}"/>
<mkdir dir="${input}"/>
<property name="a" location="${input}/a.txt"/>
<echo file="${a}">abc</echo>
<checksum todir="${output}" pattern="{4}">
<fileset dir="${input}"/>
</checksum>
<au:assertResourceContains
resource="${output}/a.txt.MD5"
value="${a}"/>
</target>

</project>

Loading…
Cancel
Save