Browse Source

More javadoc work and LOC bumming.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277215 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
960cd2a711
3 changed files with 121 additions and 192 deletions
  1. +75
    -128
      src/main/org/apache/tools/ant/AntTypeDefinition.java
  2. +33
    -53
      src/main/org/apache/tools/ant/ComponentHelper.java
  3. +13
    -11
      src/main/org/apache/tools/ant/RuntimeConfigurable.java

+ 75
- 128
src/main/org/apache/tools/ant/AntTypeDefinition.java View File

@@ -36,68 +36,65 @@ public class AntTypeDefinition {
private ClassLoader classLoader;

/**
* set the definition's name
* @param name the name of the definition
* Set the definition's name.
* @param name the name of the definition.
*/
public void setName(String name) {
this.name = name;
}

/**
* return the definition's name
* @return the name of the definition
* Return the definition's name.
* @return the name of the definition.
*/
public String getName() {
return name;
}

/**
* set the class of the definition.
* as a side-effect may set the classloader and classname
* @param clazz the class of this definition
* Set the class of the definition.
* As a side-effect may set the classloader and classname.
* @param clazz the class of this definition.
*/
public void setClass(Class clazz) {
this.clazz = clazz;
if (clazz == null) {
return;
}
if (classLoader == null) {
this.classLoader = clazz.getClassLoader();
}
if (className == null) {
this.className = clazz.getName();
}
this.classLoader = (classLoader == null)
? clazz.getClassLoader() : classLoader;
this.className = (className == null) ? clazz.getName() : className;
}

/**
* set the classname of the definition
* @param className the classname of this definition
* Set the classname of the definition.
* @param className the classname of this definition.
*/
public void setClassName(String className) {
this.className = className;
}

/**
* get the classname of the definition
* @return the name of the class of this definition
* Get the classname of the definition.
* @return the name of the class of this definition.
*/
public String getClassName() {
return className;
}

/**
* set the adapter class for this definition.
* this class is used to adapt the definitions class if
* Set the adapter class for this definition.
* This class is used to adapt the definitions class if
* required.
* @param adapterClass the adapterClass
* @param adapterClass the adapterClass.
*/
public void setAdapterClass(Class adapterClass) {
this.adapterClass = adapterClass;
}

/**
* set the assignable class for this definition.
* @param adaptToClass the assignable class
* Set the assignable class for this definition.
* @param adaptToClass the assignable class.
*/

public void setAdaptToClass(Class adaptToClass) {
@@ -105,57 +102,50 @@ public class AntTypeDefinition {
}

/**
* set the classloader to use to create an instance
* of the definition
* @param classLoader the classLoader
* Set the classloader to use to create an instance
* of the definition.
* @param classLoader the ClassLoader.
*/
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}

/**
* get the classloader for this definition
* @return the classloader for this definition
* Get the classloader for this definition.
* @return the classloader for this definition.
*/
public ClassLoader getClassLoader() {
return classLoader;
}

/**
* get the exposed class for this
* Get the exposed class for this
* definition. This will be a proxy class
* (adapted class) if there is an adapter
* class and the definition class is not
* assignable from the assignable class.
* @param project the current project
* @return the exposed class
* @param project the current project.
* @return the exposed class.
*/
public Class getExposedClass(Project project) {
if (adaptToClass != null) {
Class z = getTypeClass(project);
if (z == null) {
return null;
}
if (adaptToClass.isAssignableFrom(z)) {
if (z == null || adaptToClass.isAssignableFrom(z)) {
return z;
}
}
if (adapterClass != null) {
return adapterClass;
}
return getTypeClass(project);
return (adapterClass == null) ? getTypeClass(project) : adapterClass;
}

/**
* get the definition class
* @param project the current project
* @return the type of the definition
* Get the definition class.
* @param project the current project.
* @return the type of the definition.
*/
public Class getTypeClass(Project project) {
if (clazz != null) {
return clazz;
}

try {
if (classLoader == null) {
clazz = Class.forName(className);
@@ -174,10 +164,10 @@ public class AntTypeDefinition {
}

/**
* create an instance of the definition.
* Create an instance of the definition.
* The instance may be wrapped in a proxy class.
* @param project the current project
* @return the created object
* @param project the current project.
* @return the created object.
*/
public Object create(Project project) {
return icreate(project);
@@ -185,31 +175,28 @@ public class AntTypeDefinition {

/**
* Create a component object based on
* its definition
* its definition.
* @return the component as an <code>Object</code>.
*/
private Object icreate(Project project) {
Class c = getTypeClass(project);
if (c == null) {
return null;
}

Object o = createAndSet(project, c);
if (o == null || adapterClass == null) {
return o;
}

if (adaptToClass != null) {
if (adaptToClass.isAssignableFrom(o.getClass())) {
return o;
}
}

TypeAdapter adapterObject = (TypeAdapter) createAndSet(
project, adapterClass);
if (adapterObject == null) {
return null;
}

adapterObject.setProxy(o);
return adapterObject;
}
@@ -222,7 +209,7 @@ public class AntTypeDefinition {
* <li>if the type is assignable from adapto</li>
* <li>if the type can be used with the adapter class</li>
* </dl>
* @param project the current project
* @param project the current project.
*/
public void checkClass(Project project) {
if (clazz == null) {
@@ -233,26 +220,21 @@ public class AntTypeDefinition {
}
}
// check adapter
if (adapterClass != null) {
boolean needToCheck = true;
if (adaptToClass != null
&& adaptToClass.isAssignableFrom(clazz)) {
needToCheck = false;
}
if (needToCheck) {
TypeAdapter adapter = (TypeAdapter) createAndSet(
project, adapterClass);
if (adapter == null) {
throw new BuildException("Unable to create adapter object");
}
adapter.checkProxyClass(clazz);
if (adapterClass != null && (adaptToClass == null
|| !adaptToClass.isAssignableFrom(clazz))) {
TypeAdapter adapter = (TypeAdapter) createAndSet(
project, adapterClass);
if (adapter == null) {
throw new BuildException("Unable to create adapter object");
}
adapter.checkProxyClass(clazz);
}
}

/**
* get the constructor of the definition
* Get the constructor of the definition
* and invoke it.
* @return the instantiated <code>Object</code>.
*/
private Object createAndSet(Project project, Class c) {
try {
@@ -267,13 +249,9 @@ public class AntTypeDefinition {
ctor = c.getConstructor(new Class[] {Project.class});
noArg = false;
}
Object o = ctor.newInstance(
((noArg) ? new Object[0] : new Object[] {project}));

Object o = null;
if (noArg) {
o = ctor.newInstance(new Object[0]);
} else {
o = ctor.newInstance(new Object[] {project});
}
project.setProjectReference(o);
return o;
} catch (java.lang.reflect.InvocationTargetException ex) {
@@ -291,84 +269,53 @@ public class AntTypeDefinition {
}

/**
* Equality method for this definition (assumes the names are the same)
* Equality method for this definition (assumes the names are the same).
*
* @param other another definition
* @param project the project the definition
* @return true if the definitions are the same
* @param other another definition.
* @param project the project the definition.
* @return true if the definitions are the same.
*/
public boolean sameDefinition(AntTypeDefinition other, Project project) {
if (other == null) {
return false;
}
if (other.getClass() != this.getClass()) {
return false;
}
if (!(other.getTypeClass(project).equals(getTypeClass(project)))) {
return false;
}
if (!other.getExposedClass(project).equals(getExposedClass(project))) {
return false;
}
if (other.adapterClass != adapterClass) {
return false;
}
if (other.adaptToClass != adaptToClass) {
return false;
}
return true;
return (other != null && other.getClass() == getClass()
&& other.getTypeClass(project).equals(getTypeClass(project))
&& other.getExposedClass(project).equals(getExposedClass(project))
&& other.adapterClass == adapterClass
&& other.adaptToClass == adaptToClass);
}

/**
* Similar definition
* Similar definition;
* used to compare two definitions defined twice with the same
* name and the same types.
* the classloader may be different but have the same
* The classloader may be different but have the same
* path so #sameDefinition cannot
* be used.
* @param other the definition to compare to
* @param project the current project
* @return true if the definitions are the same
* @param other the definition to compare to.
* @param project the current project.
* @return true if the definitions are the same.
*/
public boolean similarDefinition(AntTypeDefinition other, Project project) {
if (other == null) {
return false;
}
if (getClass() != other.getClass()) {
return false;
}
if (!getClassName().equals(other.getClassName())) {
return false;
}
if (!extractClassname(adapterClass).equals(
extractClassname(other.adapterClass))) {
return false;
}
if (!extractClassname(adaptToClass).equals(
extractClassname(other.adaptToClass))) {
if (other == null
|| getClass() != other.getClass()
|| !getClassName().equals(other.getClassName())
|| !extractClassname(adapterClass).equals(
extractClassname(other.adapterClass))
|| !extractClassname(adaptToClass).equals(
extractClassname(other.adaptToClass))) {
return false;
}
// all the names are the same: check if the class path of the loader
// is the same
ClassLoader oldLoader = other.getClassLoader();
ClassLoader newLoader = this.getClassLoader();
if (oldLoader == newLoader) {
return true;
}
return
newLoader != null
&& oldLoader != null
&& oldLoader instanceof AntClassLoader
ClassLoader newLoader = getClassLoader();
return oldLoader == newLoader
|| (oldLoader instanceof AntClassLoader
&& newLoader instanceof AntClassLoader
&& ((AntClassLoader) oldLoader).getClasspath()
.equals(((AntClassLoader) newLoader).getClasspath());
.equals(((AntClassLoader) newLoader).getClasspath()));
}

private String extractClassname(Class c) {
if (c == null) {
return "<null>";
} else {
return c.getClass().getName();
}
return (c == null) ? "<null>" : c.getClass().getName();
}
}

+ 33
- 53
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -157,7 +157,8 @@ public class ComponentHelper {
}
}

/** Factory method to create the components.
/**
* Factory method to create the components.
*
* This should be called by UnknownElement.
*
@@ -173,10 +174,6 @@ public class ComponentHelper {
String componentType)
throws BuildException {
Object component = createComponent(componentType);
if (component == null) {
return null;
}

if (component instanceof Task) {
Task task = (Task) component;
task.setLocation(ue.getLocation());
@@ -186,7 +183,6 @@ public class ComponentHelper {
task.init();
addCreatedTask(componentType, task);
}

return component;
}

@@ -213,10 +209,7 @@ public class ComponentHelper {
*/
public Class getComponentClass(String componentName) {
AntTypeDefinition def = getDefinition(componentName);
if (def == null) {
return null;
}
return def.getExposedClass(project);
return (def == null) ? null : def.getExposedClass(project);
}

/**
@@ -392,9 +385,8 @@ public class ComponentHelper {
def.setName(typeName);
def.setClass(typeClass);
updateDataTypeDefinition(def);
String msg = " +User datatype: " + typeName + " "
+ typeClass.getName();
project.log(msg, Project.MSG_DEBUG);
project.log(" +User datatype: " + typeName + " "
+ typeClass.getName(), Project.MSG_DEBUG);
}

/**
@@ -443,7 +435,6 @@ public class ComponentHelper {
org.apache.tools.ant.taskdefs.Property.class);
task = createNewTask(taskType);
}

if (task != null) {
addCreatedTask(taskType, task);
}
@@ -468,7 +459,6 @@ public class ComponentHelper {
if (c == null) {
return null;
}

if (!(Task.class.isAssignableFrom(c))) {
return null;
}
@@ -481,8 +471,7 @@ public class ComponentHelper {
// set default value, can be changed by the user
task.setTaskName(taskType);

String msg = " +Task: " + taskType;
project.log (msg, Project.MSG_DEBUG);
project.log(" +Task: " + taskType, Project.MSG_DEBUG);
return task;
}

@@ -520,8 +509,7 @@ public class ComponentHelper {
if (v != null) {
Enumeration taskEnum = v.elements();
while (taskEnum.hasMoreElements()) {
WeakReference ref =
(WeakReference) taskEnum.nextElement();
WeakReference ref = (WeakReference) taskEnum.nextElement();
Task t = (Task) ref.get();
//being a weak ref, it may be null by this point
if (t != null) {
@@ -558,7 +546,7 @@ public class ComponentHelper {
* @param element The element to describe.
* Must not be <code>null</code>.
*
* @return a description of the element type
* @return a description of the element type.
*
* @since Ant 1.6
*/
@@ -578,39 +566,34 @@ public class ComponentHelper {


/**
* check if definition is a valid definition - it
* Check if definition is a valid definition - it
* may be a definition of an optional task that
* does not exist
* @param def the definition to test
* @return true if exposed type of definition is present
* does not exist.
* @param def the definition to test.
* @return true if exposed type of definition is present.
*/
private boolean validDefinition(AntTypeDefinition def) {
if (def.getTypeClass(project) == null
|| def.getExposedClass(project) == null) {
return false;
}
return true;
return !(def.getTypeClass(project) == null
|| def.getExposedClass(project) == null);
}

/**
* check if two definitions are the same
* @param def the new definition
* @param old the old definition
* @return true if the two definitions are the same
* Check if two definitions are the same.
* @param def the new definition.
* @param old the old definition.
* @return true if the two definitions are the same.
*/
private boolean sameDefinition(
AntTypeDefinition def, AntTypeDefinition old) {
if (!validDefinition(def) || !validDefinition(old)) {
return validDefinition(def) == validDefinition(old);
}
return def.sameDefinition(old, project);
return ((validDefinition(def) && validDefinition(old)
&& def.sameDefinition(old, project))
|| !(validDefinition(def) | validDefinition(old)));
}


/**
* update the component definition table with a new or
* Update the component definition table with a new or
* modified definition.
* @param def the definition to update or insert
* @param def the definition to update or insert.
*/
private void updateDataTypeDefinition(AntTypeDefinition def) {
String name = def.getName();
@@ -644,8 +627,8 @@ public class ComponentHelper {
}

/**
* Called at the start of processing an antlib
* @param uri the uri that is associated with this antlib
* Called at the start of processing an antlib.
* @param uri the uri that is associated with this antlib.
*/
public void enterAntLib(String uri) {
antLibCurrentUri = uri;
@@ -653,26 +636,23 @@ public class ComponentHelper {
}

/**
* @return the current antlib uri
* @return the current antlib uri.
*/
public String getCurrentAntlibUri() {
return antLibCurrentUri;
}

/**
* Called at the end of processing an antlib
* Called at the end of processing an antlib.
*/
public void exitAntLib() {
antLibStack.pop();
if (antLibStack.size() != 0) {
antLibCurrentUri = (String) antLibStack.peek();
} else {
antLibCurrentUri = null;
}
antLibCurrentUri = (antLibStack.size() == 0)
? null : (String)antLibStack.peek();
}

/**
* load ant's tasks
* Load ant's tasks.
*/
private void initTasks() {
ClassLoader classLoader = null;
@@ -717,7 +697,7 @@ public class ComponentHelper {
}

/**
* load ant's datatypes
* Load ant's datatypes.
*/
private void initTypes() {
ClassLoader classLoader = null;
@@ -760,7 +740,7 @@ public class ComponentHelper {
}

/**
* called for each component name, check if the
* Called for each component name, check if the
* associated URI has been examined for antlibs.
*/
private synchronized void checkNamespace(String componentName) {
@@ -788,7 +768,7 @@ public class ComponentHelper {
}

/**
* map that contains the component definitions
* Map that contains the component definitions.
*/
private static class AntTypeTable extends Hashtable {
private Project project;


+ 13
- 11
src/main/org/apache/tools/ant/RuntimeConfigurable.java View File

@@ -113,9 +113,9 @@ public class RuntimeConfigurable implements Serializable {

/**
* Sets the creator of the element to be configured
* used to store the element in the parent;
* used to store the element in the parent.
*
* @param creator the creator object
* @param creator the creator object.
*/
void setCreator(IntrospectionHelper.Creator creator) {
this.creator = creator;
@@ -123,7 +123,7 @@ public class RuntimeConfigurable implements Serializable {

/**
* Get the object for which this RuntimeConfigurable holds the configuration
* information
* information.
*
* @return the object whose configure is held by this instance.
*/
@@ -132,16 +132,16 @@ public class RuntimeConfigurable implements Serializable {
}

/**
* get the polymorphic type for this element
* @return the ant component type name, null if not set
* Get the polymorphic type for this element.
* @return the ant component type name, null if not set.
*/
public String getPolyType() {
return polyType;
}

/**
* set the polymorphic type for this element
* @param polyType the ant component type name, null if not set
* Set the polymorphic type for this element.
* @param polyType the ant component type name, null if not set.
*/
public void setPolyType(String polyType) {
this.polyType = polyType;
@@ -162,7 +162,7 @@ public class RuntimeConfigurable implements Serializable {
}

/**
* Set an attribute to a given value
* Set an attribute to a given value.
*
* @param name the name of the attribute.
* @param value the attribute's value.
@@ -180,9 +180,10 @@ public class RuntimeConfigurable implements Serializable {
}
}

/** Return the attribute map.
/**
* Return the attribute map.
*
* @return Attribute name to attribute value map
* @return Attribute name to attribute value map.
* @since Ant 1.6
*/
public Hashtable getAttributeMap() {
@@ -264,7 +265,8 @@ public class RuntimeConfigurable implements Serializable {
characters.append(buf, start, count);
}

/** Get the text content of this element. Various text chunks are
/**
* Get the text content of this element. Various text chunks are
* concatenated, there is no way ( currently ) of keeping track of
* multiple fragments.
*


Loading…
Cancel
Save