Fields Summary |
---|
private static boolean | onWindowsSet if we're running on windows |
private org.apache.tools.ant.types.resources.Union | pathPath to be converted |
private org.apache.tools.ant.types.Reference | refidReference to path/fileset to convert |
private String | targetOSThe target OS type |
private boolean | targetWindowsSet when targetOS is set to windows |
private boolean | setonemptySet if we should create a new property even if the result is empty |
private String | propertyThe property to receive the conversion |
private Vector | prefixMapPath prefix map |
private String | pathSepUser override on path sep char |
private String | dirSepUser override on directory sep char |
private org.apache.tools.ant.types.Mapper | mapperFilename mapper |
Methods Summary |
---|
public void | add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)Add a nested filenamemapper.
Mapper m = new Mapper(getProject());
m.add(fileNameMapper);
addMapper(m);
|
public void | add(org.apache.tools.ant.types.ResourceCollection rc)Add an arbitrary ResourceCollection.
if (isReference()) {
throw noChildrenAllowed();
}
getPath().add(rc);
|
public void | addMapper(org.apache.tools.ant.types.Mapper mapper)Add a mapper to convert the file names.
if (this.mapper != null) {
throw new BuildException(
"Cannot define more than one mapper");
}
this.mapper = mapper;
|
public org.apache.tools.ant.taskdefs.PathConvert$MapEntry | createMap()Create a nested MAP element.
MapEntry entry = new MapEntry();
prefixMap.addElement(entry);
return entry;
|
public org.apache.tools.ant.types.Path | createPath()Create a nested path element.
if (isReference()) {
throw noChildrenAllowed();
}
Path result = new Path(getProject());
add(result);
return result;
|
public void | execute()Do the execution.
Union savedPath = path;
String savedPathSep = pathSep; // may be altered in validateSetup
String savedDirSep = dirSep; // may be altered in validateSetup
try {
// If we are a reference, create a Path from the reference
if (isReference()) {
Object o = refid.getReferencedObject(getProject());
if (!(o instanceof ResourceCollection)) {
throw new BuildException("refid '" + refid.getRefId()
+ "' does not refer to a resource collection.");
}
getPath().add((ResourceCollection) o);
}
validateSetup(); // validate our setup
// Currently, we deal with only two path formats: Unix and Windows
// And Unix is everything that is not Windows
// (with the exception for NetWare and OS/2 below)
// for NetWare and OS/2, piggy-back on Windows, since here and
// in the apply code, the same assumptions can be made as with
// windows - that \\ is an OK separator, and do comparisons
// case-insensitive.
String fromDirSep = onWindows ? "\\" : "/";
StringBuffer rslt = new StringBuffer();
// Get the list of path components in canonical form
String[] elems = path.list();
if (mapper != null) {
FileNameMapper impl = mapper.getImplementation();
List ret = new ArrayList();
for (int i = 0; i < elems.length; ++i) {
String[] mapped = impl.mapFileName(elems[i]);
for (int m = 0; mapped != null && m < mapped.length; ++m) {
ret.add(mapped[m]);
}
}
elems = (String[]) ret.toArray(new String[ret.size()]);
}
for (int i = 0; i < elems.length; i++) {
String elem = mapElement(elems[i]); // Apply the path prefix map
// Now convert the path and file separator characters from the
// current os to the target os.
if (i != 0) {
rslt.append(pathSep);
}
StringTokenizer stDirectory =
new StringTokenizer(elem, fromDirSep, true);
while (stDirectory.hasMoreTokens()) {
String token = stDirectory.nextToken();
rslt.append(fromDirSep.equals(token) ? dirSep : token);
}
}
// Place the result into the specified property,
// unless setonempty == false
if (setonempty || rslt.length() > 0) {
String value = rslt.toString();
if (property == null) {
log(value);
} else {
log("Set property " + property + " = " + value,
Project.MSG_VERBOSE);
getProject().setNewProperty(property, value);
}
}
} finally {
path = savedPath;
dirSep = savedDirSep;
pathSep = savedPathSep;
}
|
private synchronized org.apache.tools.ant.types.resources.Union | getPath()
if (path == null) {
path = new Union();
path.setProject(getProject());
}
return path;
|
public boolean | isReference()Learn whether the refid attribute of this element been set.
return refid != null;
|
private java.lang.String | mapElement(java.lang.String elem)Apply the configured map to a path element. The map is used to convert
between Windows drive letters and Unix paths. If no map is configured,
then the input string is returned unchanged.
int size = prefixMap.size();
if (size != 0) {
// Iterate over the map entries and apply each one.
// Stop when one of the entries actually changes the element.
for (int i = 0; i < size; i++) {
MapEntry entry = (MapEntry) prefixMap.elementAt(i);
String newElem = entry.apply(elem);
// Note I'm using "!=" to see if we got a new object back from
// the apply method.
if (newElem != elem) {
elem = newElem;
break; // We applied one, so we're done
}
}
}
return elem;
|
private org.apache.tools.ant.BuildException | noChildrenAllowed()Creates an exception that indicates that this XML element must not have
child elements if the refid attribute is set.
return new BuildException("You must not specify nested "
+ "elements when using the refid attribute.");
|
public void | setDirSep(java.lang.String sep)Set the default directory separator string;
defaults to current JVM {@link java.io.File#separator File.separator}.
dirSep = sep;
|
public void | setPathSep(java.lang.String sep)Set the default path separator string; defaults to current JVM
{@link java.io.File#pathSeparator File.pathSeparator}.
pathSep = sep;
|
public void | setProperty(java.lang.String p)Set the name of the property into which the converted path will be placed.
property = p;
|
public void | setRefid(org.apache.tools.ant.types.Reference r)Add a reference to a Path, FileSet, DirSet, or FileList defined elsewhere.
if (path != null) {
throw noChildrenAllowed();
}
refid = r;
|
public void | setSetonempty(boolean setonempty)Set whether the specified property will be set if the result
is the empty string.
this.setonempty = setonempty;
|
public void | setTargetos(java.lang.String target)Set targetos to a platform to one of
"windows", "unix", "netware", or "os/2";
current platform settings are used by default.
TargetOs to = new TargetOs();
to.setValue(target);
setTargetos(to);
|
public void | setTargetos(org.apache.tools.ant.taskdefs.PathConvert$TargetOs target)Set targetos to a platform to one of
"windows", "unix", "netware", or "os/2";
current platform settings are used by default.
targetOS = target.getValue();
// Currently, we deal with only two path formats: Unix and Windows
// And Unix is everything that is not Windows
// for NetWare and OS/2, piggy-back on Windows, since in the
// validateSetup code, the same assumptions can be made as
// with windows - that ; is the path separator
targetWindows = !targetOS.equals("unix") && !targetOS.equals("tandem");
|
private void | validateSetup()Validate that all our parameters have been properly initialized.
if (path == null) {
throw new BuildException("You must specify a path to convert");
}
// Determine the separator strings. The dirsep and pathsep attributes
// override the targetOS settings.
String dsep = File.separator;
String psep = File.pathSeparator;
if (targetOS != null) {
psep = targetWindows ? ";" : ":";
dsep = targetWindows ? "\\" : "/";
}
if (pathSep != null) {
// override with pathsep=
psep = pathSep;
}
if (dirSep != null) {
// override with dirsep=
dsep = dirSep;
}
pathSep = psep;
dirSep = dsep;
|