Methods Summary |
---|
public void | add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)A nested filenamemapper
createMapper().add(fileNameMapper);
|
private void | convert(java.lang.String srcName, java.lang.String destName)Convert a single file.
File srcFile; // File to convert
File destFile; // where to put the results
// Build the full file names
srcFile = new File(srcDir, srcName);
destFile = new File(destDir, destName);
// Make sure we're not about to clobber something
if (srcFile.equals(destFile)) {
throw new BuildException("file " + srcFile
+ " would overwrite its self");
}
// Make intermediate directories if needed
// XXX JDK 1.1 doesn't have File.getParentFile,
String parentName = destFile.getParent();
if (parentName != null) {
File parentFile = new File(parentName);
if ((!parentFile.exists()) && (!parentFile.mkdirs())) {
throw new BuildException("cannot create parent directory "
+ parentName);
}
}
log("converting " + srcName, Project.MSG_VERBOSE);
Native2AsciiAdapter ad =
Native2AsciiAdapterFactory.getAdapter(facade.getImplementation(),
this);
if (!ad.convert(this, srcFile, destFile)) {
throw new BuildException("conversion failed");
}
|
public org.apache.tools.ant.util.facade.ImplementationSpecificArgument | createArg()Adds an implementation specific command-line argument.
ImplementationSpecificArgument arg =
new ImplementationSpecificArgument();
facade.addImplementationArgument(arg);
return arg;
|
public org.apache.tools.ant.types.Mapper | createMapper()Defines the FileNameMapper to use (nested mapper element).
if (mapper != null) {
throw new BuildException("Cannot define more than one mapper",
getLocation());
}
mapper = new Mapper(getProject());
return mapper;
|
public void | execute()Execute the task
DirectoryScanner scanner = null; // Scanner to find our inputs
String[] files; // list of files to process
// default srcDir to basedir
if (srcDir == null) {
srcDir = getProject().resolveFile(".");
}
// Require destDir
if (destDir == null) {
throw new BuildException("The dest attribute must be set.");
}
// if src and dest dirs are the same, require the extension
// to be set, so we don't stomp every file. One could still
// include a file with the same extension, but ....
if (srcDir.equals(destDir) && extension == null && mapper == null) {
throw new BuildException("The ext attribute or a mapper must be set if"
+ " src and dest dirs are the same.");
}
FileNameMapper m = null;
if (mapper == null) {
if (extension == null) {
m = new IdentityMapper();
} else {
m = new ExtMapper();
}
} else {
m = mapper.getImplementation();
}
scanner = getDirectoryScanner(srcDir);
files = scanner.getIncludedFiles();
SourceFileScanner sfs = new SourceFileScanner(this);
files = sfs.restrict(files, srcDir, destDir, m);
int count = files.length;
if (count == 0) {
return;
}
String message = "Converting " + count + " file"
+ (count != 1 ? "s" : "") + " from ";
log(message + srcDir + " to " + destDir);
for (int i = 0; i < files.length; i++) {
convert(files[i], m.mapFileName(files[i])[0]);
}
|
public java.lang.String[] | getCurrentArgs()Returns the (implementation specific) settings given as nested
arg elements.
return facade.getArgs();
|
public java.lang.String | getEncoding()The value of the encoding attribute.
return encoding;
|
public boolean | getReverse()The value of the reverse attribute.
return reverse;
|
public void | setDest(java.io.File destDir)Set the destination directory to place converted files into.
this.destDir = destDir;
|
public void | setEncoding(java.lang.String encoding)Set the encoding to translate to/from.
If unset, the default encoding for the JVM is used.
this.encoding = encoding;
|
public void | setExt(java.lang.String ext)Set the extension which converted files should have.
If unset, files will not be renamed.
this.extension = ext;
|
public void | setImplementation(java.lang.String impl)Choose the implementation for this particular task.
if ("default".equals(impl)) {
facade.setImplementation(Native2AsciiAdapterFactory.getDefault());
} else {
facade.setImplementation(impl);
}
|
public void | setReverse(boolean reverse)Flag the conversion to run in the reverse sense,
that is Ascii to Native encoding.
this.reverse = reverse;
|
public void | setSrc(java.io.File srcDir)Set the source directory in which to find files to convert.
this.srcDir = srcDir;
|