Converts path and classpath information to a specific target OS
format. The resulting formatted path is placed into the specified property.
| Method from org.apache.tools.ant.taskdefs.PathConvert Detail: |
public void add(ResourceCollection rc) {
if (isReference()) {
throw noChildrenAllowed();
}
getPath().add(rc);
}
Add an arbitrary ResourceCollection. |
public void add(FileNameMapper fileNameMapper) {
Mapper m = new Mapper(getProject());
m.add(fileNameMapper);
addMapper(m);
}
Add a nested filenamemapper. |
public void addMapper(Mapper mapper) {
if (this.mapper != null) {
throw new BuildException(
"Cannot define more than one mapper");
}
this.mapper = mapper;
}
Add a mapper to convert the file names. |
public PathConvert.MapEntry createMap() {
MapEntry entry = new MapEntry();
prefixMap.addElement(entry);
return entry;
}
Create a nested MAP element. |
public Path createPath() {
if (isReference()) {
throw noChildrenAllowed();
}
Path result = new Path(getProject());
add(result);
return result;
}
Create a nested path element. |
public void execute() throws BuildException {
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;
}
}
|
public boolean isReference() {
return refid != null;
}
Learn whether the refid attribute of this element been set. |
public void setDirSep(String sep) {
dirSep = sep;
}
Set the default directory separator string;
defaults to current JVM File.separator . |
public void setPathSep(String sep) {
pathSep = sep;
}
|
public void setProperty(String p) {
property = p;
}
Set the name of the property into which the converted path will be placed. |
public void setRefid(Reference r) {
if (path != null) {
throw noChildrenAllowed();
}
refid = r;
}
Add a reference to a Path, FileSet, DirSet, or FileList defined elsewhere. |
public void setSetonempty(boolean setonempty) {
this.setonempty = setonempty;
}
Set whether the specified property will be set if the result
is the empty string. |
public void setTargetos(String target) {
TargetOs to = new TargetOs();
to.setValue(target);
setTargetos(to);
} Deprecated! since - 1.5.x.
Use the method taking a TargetOs argument instead.
Set targetos to a platform to one of
"windows", "unix", "netware", or "os/2";
current platform settings are used by default. |
public void setTargetos(PathConvert.TargetOs target) {
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");
}
Set targetos to a platform to one of
"windows", "unix", "netware", or "os/2";
current platform settings are used by default. |