You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2005/09/30 18:27:42 UTC
svn commit: r292804 - in /ant/core/trunk:
docs/manual/CoreTasks/checksum.html src/etc/testcases/taskdefs/checksum.xml
src/main/org/apache/tools/ant/taskdefs/Checksum.java
src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java
Author: mbenson
Date: Fri Sep 30 09:27:31 2005
New Revision: 292804
URL: http://svn.apache.org/viewcvs?rev=292804&view=rev
Log:
Support filesystem-only resource collections in checksum.
Modified:
ant/core/trunk/docs/manual/CoreTasks/checksum.html
ant/core/trunk/src/etc/testcases/taskdefs/checksum.xml
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Checksum.java
ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java
Modified: ant/core/trunk/docs/manual/CoreTasks/checksum.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/checksum.html?rev=292804&r1=292803&r2=292804&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/checksum.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/checksum.html Fri Sep 30 09:27:31 2005
@@ -46,7 +46,7 @@
<td valign="top">file</td>
<td valign="top">The file to generate checksum for.</td>
<td valign="top" align="center">One of either <var>file</var> or
- at least one nested fileset element.</td>
+ at least one nested (filesystem-only) resource collection.</td>
</tr>
<tr>
<td valign="top">todir</td>
@@ -116,8 +116,8 @@
<td valign="top">totalproperty</td>
<td valign="top">If specified, this attribute specifies the name of
the property that will hold a checksum of all the checksums and
- file paths. The individual checksums and the relative paths to
- the files within the filesets they are defined in will be used to
+ file paths. The individual checksums and the relative paths to the files
+ within the resource collections in which they are defined will be used to
compute this checksum. (The file separators in the paths will be
converted to '/' before computation to ensure platform portability).
<em>since Ant 1.6</em>
@@ -150,10 +150,10 @@
</table>
<h3>Parameters specified as nested elements</h3>
-<h4>fileset</h4>
+<h4>resource collection</h4>
<p>
- <a href="../CoreTypes/fileset.html">FileSets</a> are used to select files to
- generate checksums for.
+ <a href="../CoreTypes/resources.html#collection">Resource collections</a> are
+ used to select files for which checksums should be generated.
</p>
<h3>Examples</h3>
Modified: ant/core/trunk/src/etc/testcases/taskdefs/checksum.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/checksum.xml?rev=292804&r1=292803&r2=292804&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/checksum.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/checksum.xml Fri Sep 30 09:27:31 2005
@@ -188,6 +188,23 @@
</fail>
</target>
+ <target name="verifyTotalRC">
+ <checksum totalproperty="total">
+ <resources>
+ <fileset dir="${basedir}/checksum">
+ <exclude name="**/*.MD5"/>
+ </fileset>
+ </resources>
+ </checksum>
+ <fail>
+ <condition>
+ <not>
+ <equals arg1="ef8f1477fcc9bf93832c1a74f629c626" arg2="${total}" />
+ </not>
+ </condition>
+ </fail>
+ </target>
+
<target name="verifyChecksumdir">
<checksum totalproperty="total" todir="${basedir}/checksum/checksums">
<fileset dir="${basedir}/checksum">
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Checksum.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Checksum.java?rev=292804&r1=292803&r2=292804&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Checksum.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Checksum.java Fri Sep 30 09:27:31 2005
@@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
+import java.util.Iterator;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Set;
@@ -42,6 +43,12 @@
import org.apache.tools.ant.taskdefs.condition.Condition;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.Union;
+import org.apache.tools.ant.types.resources.Restrict;
+import org.apache.tools.ant.types.resources.FileResource;
+import org.apache.tools.ant.types.resources.selectors.Type;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;
@@ -53,6 +60,17 @@
* @ant.task category="control"
*/
public class Checksum extends MatchingTask implements Condition {
+ private static class FileUnion extends Restrict {
+ Union u;
+ FileUnion() {
+ u = new Union();
+ super.add(u);
+ super.add(Type.FILE);
+ }
+ public void add(ResourceCollection rc) {
+ u.add(rc);
+ }
+ }
/**
* File for which checksum is to be calculated.
@@ -110,9 +128,9 @@
*/
private String verifyProperty;
/**
- * Vector to hold source file sets.
+ * Resource Collection.
*/
- private Vector filesets = new Vector();
+ private FileUnion resources = null;
/**
* Stores SourceFile, DestFile pairs and SourceFile, Property String pairs.
*/
@@ -253,7 +271,19 @@
* @param set a fileset of files to generate checksums for.
*/
public void addFileset(FileSet set) {
- filesets.addElement(set);
+ add(set);
+ }
+
+ /**
+ * Add a resource collection.
+ * @param rc the ResourceCollection to add.
+ */
+ public void add(ResourceCollection rc) {
+ if (rc == null) {
+ return;
+ }
+ resources = (resources == null) ? new FileUnion() : resources;
+ resources.add(rc);
}
/**
@@ -288,60 +318,49 @@
private boolean validateAndExecute() throws BuildException {
String savedFileExt = fileext;
- if (file == null && filesets.size() == 0) {
+ if (file == null && (resources == null || resources.size() == 0)) {
throw new BuildException(
- "Specify at least one source - a file or a fileset.");
+ "Specify at least one source - a file or a resource collection.");
+ }
+ if (!(resources == null || resources.isFilesystemOnly())) {
+ throw new BuildException("Can only calculate checksums for file-based resources.");
}
-
if (file != null && file.exists() && file.isDirectory()) {
- throw new BuildException(
- "Checksum cannot be generated for directories");
+ throw new BuildException("Checksum cannot be generated for directories");
}
-
if (file != null && totalproperty != null) {
- throw new BuildException(
- "File and Totalproperty cannot co-exist.");
+ throw new BuildException("File and Totalproperty cannot co-exist.");
}
-
if (property != null && fileext != null) {
- throw new BuildException(
- "Property and FileExt cannot co-exist.");
+ throw new BuildException("Property and FileExt cannot co-exist.");
}
-
if (property != null) {
if (forceOverwrite) {
throw new BuildException(
"ForceOverwrite cannot be used when Property is specified");
}
-
+ int ct = 0;
+ if (resources != null) {
+ ct += resources.size();
+ }
if (file != null) {
- if (filesets.size() > 0) {
- throw new BuildException("Multiple files cannot be used "
- + "when Property is specified");
- }
- } else {
- if (filesets.size() > 1
- || ((FileSet) filesets.get(0)).size() > 1) {
- throw new BuildException("Multiple files cannot be used "
- + "when Property is specified");
- }
+ ct++;
+ }
+ if (ct > 1) {
+ throw new BuildException(
+ "Multiple files cannot be used when Property is specified");
}
}
-
if (verifyProperty != null) {
isCondition = true;
}
-
if (verifyProperty != null && forceOverwrite) {
- throw new BuildException(
- "VerifyProperty and ForceOverwrite cannot co-exist.");
+ throw new BuildException("VerifyProperty and ForceOverwrite cannot co-exist.");
}
-
if (isCondition && forceOverwrite) {
- throw new BuildException("ForceOverwrite cannot be used when "
- + "conditions are being used.");
+ throw new BuildException(
+ "ForceOverwrite cannot be used when conditions are being used.");
}
-
messageDigest = null;
if (provider != null) {
try {
@@ -358,40 +377,31 @@
throw new BuildException(noalgo, getLocation());
}
}
-
if (messageDigest == null) {
- throw new BuildException("Unable to create Message Digest",
- getLocation());
+ throw new BuildException("Unable to create Message Digest", getLocation());
}
-
if (fileext == null) {
fileext = "." + algorithm;
} else if (fileext.trim().length() == 0) {
- throw new BuildException(
- "File extension when specified must not be an empty string");
+ throw new BuildException("File extension when specified must not be an empty string");
}
-
try {
- int sizeofFileSet = filesets.size();
- for (int i = 0; i < sizeofFileSet; i++) {
- FileSet fs = (FileSet) filesets.elementAt(i);
- DirectoryScanner ds = fs.getDirectoryScanner(getProject());
- String[] srcFiles = ds.getIncludedFiles();
- for (int j = 0; j < srcFiles.length; j++) {
- File src = new File(fs.getDir(getProject()), srcFiles[j]);
+ if (resources != null) {
+ for (Iterator i = resources.iterator(); i.hasNext();) {
+ FileResource fr = (FileResource) i.next();
+ File src = fr.getFile();
if (totalproperty != null || todir != null) {
// Use '/' to calculate digest based on file name.
// This is required in order to get the same result
// on different platforms.
- String relativePath = srcFiles[j].replace(File.separatorChar, '/');
- relativeFilePaths.put(src, relativePath);
+ relativeFilePaths.put(src, fr.getName().replace(File.separatorChar, '/'));
}
addToIncludeFileMap(src);
}
}
-
- addToIncludeFileMap(file);
-
+ if (file != null) {
+ addToIncludeFileMap(file);
+ }
return generateChecksums();
} finally {
fileext = savedFileExt;
@@ -404,33 +414,31 @@
* to later operate upon.
*/
private void addToIncludeFileMap(File file) throws BuildException {
- if (file != null) {
- if (file.exists()) {
- if (property == null) {
- File checksumFile = getChecksumFile(file);
- if (forceOverwrite || isCondition
- || (file.lastModified() > checksumFile.lastModified())) {
- includeFileMap.put(file, checksumFile);
- } else {
- log(file + " omitted as " + checksumFile + " is up to date.",
- Project.MSG_VERBOSE);
- if (totalproperty != null) {
- // Read the checksum from disk.
- String checksum = readChecksum(checksumFile);
- byte[] digest = decodeHex(checksum.toCharArray());
- allDigests.put(file, digest);
- }
- }
+ if (file.exists()) {
+ if (property == null) {
+ File checksumFile = getChecksumFile(file);
+ if (forceOverwrite || isCondition
+ || (file.lastModified() > checksumFile.lastModified())) {
+ includeFileMap.put(file, checksumFile);
} else {
- includeFileMap.put(file, property);
+ log(file + " omitted as " + checksumFile + " is up to date.",
+ Project.MSG_VERBOSE);
+ if (totalproperty != null) {
+ // Read the checksum from disk.
+ String checksum = readChecksum(checksumFile);
+ byte[] digest = decodeHex(checksum.toCharArray());
+ allDigests.put(file, digest);
+ }
}
} else {
- String message = "Could not find file "
- + file.getAbsolutePath()
- + " to generate checksum for.";
- log(message);
- throw new BuildException(message, getLocation());
+ includeFileMap.put(file, property);
}
+ } else {
+ String message = "Could not find file "
+ + file.getAbsolutePath()
+ + " to generate checksum for.";
+ log(message);
+ throw new BuildException(message, getLocation());
}
}
Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java?rev=292804&r1=292803&r2=292804&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ChecksumTest.java Fri Sep 30 09:27:31 2005
@@ -62,6 +62,10 @@
executeTarget("verifyTotal");
}
+ public void testVerifyTotalRC() {
+ executeTarget("verifyTotalRC");
+ }
+
public void testVerifyChecksumdir() {
executeTarget("verifyChecksumdir");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org