Methods Summary |
---|
private boolean | checkClass(java.lang.String classname)Check if a given class can be loaded.
try {
if (ignoreSystemclasses) {
loader = getProject().createClassLoader(classpath);
loader.setParentFirst(false);
loader.addJavaLibraries();
if (loader != null) {
try {
loader.findClass(classname);
} catch (SecurityException se) {
// class found but restricted name; this is
// actually the case we're looking for in JDK 1.3+,
// so catch the exception and return
return true;
}
} else {
return false;
}
} else if (loader != null) {
loader.loadClass(classname);
} else {
ClassLoader l = this.getClass().getClassLoader();
// Can return null to represent the bootstrap class loader.
// see API docs of Class.getClassLoader.
if (l != null) {
Class.forName(classname, true, l);
} else {
Class.forName(classname);
}
}
return true;
} catch (ClassNotFoundException e) {
log("class \"" + classname + "\" was not found",
Project.MSG_DEBUG);
return false;
} catch (NoClassDefFoundError e) {
log("Could not load dependent class \"" + e.getMessage()
+ "\" for class \"" + classname + "\"",
Project.MSG_DEBUG);
return false;
}
|
private boolean | checkFile()Search for file/directory either relative to project's
basedir or in the path given as filepath.
filepath can be a list of directory and/or file names (gen'd
via )
look for:
- full-pathname specified == path in list
- full-pathname specified == parent dir of path in list
- simple name specified == path in list
- simple name specified == path in list + name
- simple name specified == parent dir + name
- simple name specified == parent of parent dir + name
if (filepath == null) {
return checkFile(file, filename);
} else {
String[] paths = filepath.list();
for (int i = 0; i < paths.length; ++i) {
log("Searching " + paths[i], Project.MSG_DEBUG);
File path = new File(paths[i]);
// ** full-pathname specified == path in list
// ** simple name specified == path in list
if (path.exists() && filename.equals(paths[i])) {
if (type == null) {
log("Found: " + path, Project.MSG_VERBOSE);
return true;
} else if (type.isDir()
&& path.isDirectory()) {
log("Found directory: " + path, Project.MSG_VERBOSE);
return true;
} else if (type.isFile()
&& path.isFile()) {
log("Found file: " + path, Project.MSG_VERBOSE);
return true;
}
// not the requested type
return false;
}
File parent = path.getParentFile();
// ** full-pathname specified == parent dir of path in list
if (parent != null && parent.exists()
&& filename.equals(parent.getAbsolutePath())) {
if (type == null) {
log("Found: " + parent, Project.MSG_VERBOSE);
return true;
} else if (type.isDir()) {
log("Found directory: " + parent, Project.MSG_VERBOSE);
return true;
}
// not the requested type
return false;
}
// ** simple name specified == path in list + name
if (path.exists() && path.isDirectory()) {
if (checkFile(new File(path, filename),
filename + " in " + path)) {
return true;
}
}
// ** simple name specified == parent dir + name
while (searchParents && parent != null && parent.exists()) {
if (checkFile(new File(parent, filename),
filename + " in " + parent)) {
return true;
}
parent = parent.getParentFile();
}
}
}
return false;
|
private boolean | checkFile(java.io.File f, java.lang.String text)Check if a given file exists and matches the required type.
if (type != null) {
if (type.isDir()) {
if (f.isDirectory()) {
log("Found directory: " + text, Project.MSG_VERBOSE);
}
return f.isDirectory();
} else if (type.isFile()) {
if (f.isFile()) {
log("Found file: " + text, Project.MSG_VERBOSE);
}
return f.isFile();
}
}
if (f.exists()) {
log("Found: " + text, Project.MSG_VERBOSE);
}
return f.exists();
|
private boolean | checkResource(java.lang.String resource)Check if a given resource can be loaded.
if (loader != null) {
return (loader.getResourceAsStream(resource) != null);
} else {
ClassLoader cL = this.getClass().getClassLoader();
if (cL != null) {
return (cL.getResourceAsStream(resource) != null);
} else {
return
(ClassLoader.getSystemResourceAsStream(resource) != null);
}
}
|
public org.apache.tools.ant.types.Path | createClasspath()Classpath to be used when searching for classes and resources.
if (this.classpath == null) {
this.classpath = new Path(getProject());
}
return this.classpath.createPath();
|
public org.apache.tools.ant.types.Path | createFilepath()Path to search for file resources.
if (this.filepath == null) {
this.filepath = new Path(getProject());
}
return this.filepath.createPath();
|
public boolean | eval()Evaluate the availability of a resource.
try {
if (classname == null && file == null && resource == null) {
throw new BuildException("At least one of (classname|file|"
+ "resource) is required", getLocation());
}
if (type != null) {
if (file == null) {
throw new BuildException("The type attribute is only valid "
+ "when specifying the file "
+ "attribute.", getLocation());
}
}
if (classpath != null) {
classpath.setProject(getProject());
this.loader = getProject().createClassLoader(classpath);
}
String appendix = "";
if (isTask) {
appendix = " to set property " + property;
} else {
setTaskName("available");
}
if ((classname != null) && !checkClass(classname)) {
log("Unable to load class " + classname + appendix,
Project.MSG_VERBOSE);
return false;
}
if ((file != null) && !checkFile()) {
StringBuffer buf = new StringBuffer("Unable to find ");
if (type != null) {
buf.append(type).append(' ");
}
buf.append(filename).append(appendix);
log(buf.toString(), Project.MSG_VERBOSE);
return false;
}
if ((resource != null) && !checkResource(resource)) {
log("Unable to load resource " + resource + appendix,
Project.MSG_VERBOSE);
return false;
}
} finally {
if (loader != null) {
loader.cleanup();
loader = null;
}
if (!isTask) {
setTaskName(null);
}
}
return true;
|
public void | execute()Entry point when operating as a task.
if (property == null) {
throw new BuildException("property attribute is required",
getLocation());
}
isTask = true;
try {
if (eval()) {
String oldvalue = getProject().getProperty(property);
if (null != oldvalue && !oldvalue.equals(value)) {
log("DEPRECATED - <available> used to override an existing"
+ " property."
+ StringUtils.LINE_SEP
+ " Build file should not reuse the same property"
+ " name for different values.",
Project.MSG_WARN);
}
// NB: this makes use of Project#setProperty rather than Project#setNewProperty
// due to backwards compatiblity reasons
getProject().setProperty(property, value);
}
} finally {
isTask = false;
}
|
public void | setClassname(java.lang.String classname)Set a classname of a class which must be available to set the given
property.
if (!"".equals(classname)) {
this.classname = classname;
}
|
public void | setClasspath(org.apache.tools.ant.types.Path classpath)Set the classpath to be used when searching for classes and resources.
createClasspath().append(classpath);
|
public void | setClasspathRef(org.apache.tools.ant.types.Reference r)Set the classpath by reference.
createClasspath().setRefid(r);
|
public void | setFile(java.io.File file)Set the file which must be present in the file system to set the given
property.
this.file = file;
this.filename = FILE_UTILS.removeLeadingPath(getProject().getBaseDir(), file);
|
public void | setFilepath(org.apache.tools.ant.types.Path filepath)Set the path to use when looking for a file.
createFilepath().append(filepath);
|
public void | setIgnoresystemclasses(boolean ignore)Set whether the search for classes should ignore the runtime classes and
just use the given classpath.
this.ignoreSystemclasses = ignore;
|
public void | setProperty(java.lang.String property)Set the name of the property which will be set if the particular resource
is available.
this.property = property;
|
public void | setResource(java.lang.String resource)Set the name of a Java resource which is required to set the property.
this.resource = resource;
|
public void | setSearchParents(boolean searchParents)Set the searchParents attribute.
This controls the behaviour of the the "file" type.
If true, the path, parent path and grandparent path are
searched for the file. If false, only the path is seached.
The default value is false.
this.searchParents = searchParents;
|
public void | setType(java.lang.String type)
log("DEPRECATED - The setType(String) method has been deprecated."
+ " Use setType(Available.FileDir) instead.",
Project.MSG_WARN);
this.type = new FileDir();
this.type.setValue(type);
|
public void | setType(org.apache.tools.ant.taskdefs.Available$FileDir type)Set what type of file is required - either directory or file.
this.type = type;
|
public void | setValue(java.lang.String value)Set the value to be given to the property if the desired resource is
available.
this.value = value;
|