| Method from org.apache.tools.ant.taskdefs.Touch Detail: |
public void add(FileNameMapper fileNameMapper) throws BuildException {
if (this.fileNameMapper != null) {
throw new BuildException("Only one mapper may be added to the "
+ getTaskName() + " task.");
}
this.fileNameMapper = fileNameMapper;
}
|
public synchronized void add(ResourceCollection rc) {
resources = resources == null ? new Union() : resources;
resources.add(rc);
}
Add a collection of resources to touch. |
public void addConfiguredMapper(Mapper mapper) {
add(mapper.getImplementation());
}
|
public void addFilelist(FileList list) {
add(list);
}
|
public void addFileset(FileSet set) {
filesets.add(set);
add(set);
}
Add a set of files to touch. |
protected synchronized void checkConfiguration() throws BuildException {
if (file == null && resources == null) {
throw new BuildException("Specify at least one source"
+ "--a file or resource collection.");
}
if (file != null && file.exists() && file.isDirectory()) {
throw new BuildException("Use a resource collection to touch directories.");
}
if (dateTime != null && !dateTimeConfigured) {
long workmillis = millis;
if ("now".equalsIgnoreCase(dateTime)) {
workmillis = System.currentTimeMillis();
} else {
DateFormat df = dfFactory.getPrimaryFormat();
ParseException pe = null;
try {
workmillis = df.parse(dateTime).getTime();
} catch (ParseException peOne) {
df = dfFactory.getFallbackFormat();
if (df == null) {
pe = peOne;
} else {
try {
workmillis = df.parse(dateTime).getTime();
} catch (ParseException peTwo) {
pe = peTwo;
}
}
}
if (pe != null) {
throw new BuildException(pe.getMessage(), pe, getLocation());
}
if (workmillis < 0) {
throw new BuildException("Date of " + dateTime
+ " results in negative " + "milliseconds value "
+ "relative to epoch " + "(January 1, 1970, "
+ "00:00:00 GMT).");
}
}
log("Setting millis to " + workmillis + " from datetime attribute",
((millis < 0) ? Project.MSG_DEBUG : Project.MSG_VERBOSE));
setMillis(workmillis);
// only set if successful to this point:
dateTimeConfigured = true;
}
}
Check that this task has been configured properly. |
public void execute() throws BuildException {
checkConfiguration();
touch();
}
Execute the touch operation. |
public void setDatetime(String dateTime) {
if (this.dateTime != null) {
log("Resetting datetime attribute to " + dateTime, Project.MSG_VERBOSE);
}
this.dateTime = dateTime;
dateTimeConfigured = false;
}
Set the new modification time of file(s) touched
in the format "MM/DD/YYYY HH:MM AM or PM"
or "MM/DD/YYYY HH:MM:SS AM or PM".
Optional, default=now. |
public void setFile(File file) {
this.file = file;
}
Sets a single source file to touch. If the file does not exist
an empty file will be created. |
public void setMillis(long millis) {
this.millis = millis;
}
Set the new modification time of file(s) touched
in milliseconds since midnight Jan 1 1970. Optional, default=now. |
public void setMkdirs(boolean mkdirs) {
this.mkdirs = mkdirs;
}
Set whether nonexistent parent directories should be created
when touching new files. |
public void setPattern(String pattern) {
dfFactory = new DateFormatFactory() {
public DateFormat getPrimaryFormat() {
return new SimpleDateFormat(pattern);
}
public DateFormat getFallbackFormat() {
return null;
}
};
}
Set the format of the datetime attribute. |
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
Set whether the touch task will report every file it creates;
defaults to true. |
protected void touch() throws BuildException {
long defaultTimestamp = getTimestamp();
if (file != null) {
touch(new FileResource(file.getParentFile(), file.getName()),
defaultTimestamp);
}
if (resources == null) {
return;
}
// deal with the resource collections
Iterator iter = resources.iterator();
while (iter.hasNext()) {
Resource r = (Resource) iter.next();
Touchable t = (Touchable) r.as(Touchable.class);
if (t == null) {
throw new BuildException("Can't touch " + r);
}
touch(r, defaultTimestamp);
}
// deal with filesets in a special way since the task
// originally also used the directories and Union won't return
// them.
for (int i = 0; i < filesets.size(); i++) {
FileSet fs = (FileSet) filesets.elementAt(i);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
File fromDir = fs.getDir(getProject());
String[] srcDirs = ds.getIncludedDirectories();
for (int j = 0; j < srcDirs.length; j++) {
touch(new FileResource(fromDir, srcDirs[j]), defaultTimestamp);
}
}
}
Does the actual work; assumes everything has been checked by now. |
protected void touch(File file) {
touch(file, getTimestamp());
} Deprecated! since - 1.6.x.
Touch a single file with the current timestamp (this.millis). This method
does not interact with any nested mappers and remains for reasons of
backwards-compatibility only. |