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; 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) { public void setName(String name) {
this.name = 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() { public String getName() {
return name; 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) { public void setClass(Class clazz) {
this.clazz = clazz; this.clazz = clazz;
if (clazz == null) { if (clazz == null) {
return; 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) { public void setClassName(String className) {
this.className = 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() { public String getClassName() {
return className; 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. * required.
* @param adapterClass the adapterClass
* @param adapterClass the adapterClass.
*/ */
public void setAdapterClass(Class adapterClass) { public void setAdapterClass(Class adapterClass) {
this.adapterClass = 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) { 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) { public void setClassLoader(ClassLoader classLoader) {
this.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() { public ClassLoader getClassLoader() {
return classLoader; return classLoader;
} }


/** /**
* get the exposed class for this
* Get the exposed class for this
* definition. This will be a proxy class * definition. This will be a proxy class
* (adapted class) if there is an adapter * (adapted class) if there is an adapter
* class and the definition class is not * class and the definition class is not
* assignable from the assignable class. * 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) { public Class getExposedClass(Project project) {
if (adaptToClass != null) { if (adaptToClass != null) {
Class z = getTypeClass(project); Class z = getTypeClass(project);
if (z == null) {
return null;
}
if (adaptToClass.isAssignableFrom(z)) {
if (z == null || adaptToClass.isAssignableFrom(z)) {
return 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) { public Class getTypeClass(Project project) {
if (clazz != null) { if (clazz != null) {
return clazz; return clazz;
} }

try { try {
if (classLoader == null) { if (classLoader == null) {
clazz = Class.forName(className); 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. * 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) { public Object create(Project project) {
return icreate(project); return icreate(project);
@@ -185,31 +175,28 @@ public class AntTypeDefinition {


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

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

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

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

adapterObject.setProxy(o); adapterObject.setProxy(o);
return adapterObject; return adapterObject;
} }
@@ -222,7 +209,7 @@ public class AntTypeDefinition {
* <li>if the type is assignable from adapto</li> * <li>if the type is assignable from adapto</li>
* <li>if the type can be used with the adapter class</li> * <li>if the type can be used with the adapter class</li>
* </dl> * </dl>
* @param project the current project
* @param project the current project.
*/ */
public void checkClass(Project project) { public void checkClass(Project project) {
if (clazz == null) { if (clazz == null) {
@@ -233,26 +220,21 @@ public class AntTypeDefinition {
} }
} }
// check adapter // 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. * and invoke it.
* @return the instantiated <code>Object</code>.
*/ */
private Object createAndSet(Project project, Class c) { private Object createAndSet(Project project, Class c) {
try { try {
@@ -267,13 +249,9 @@ public class AntTypeDefinition {
ctor = c.getConstructor(new Class[] {Project.class}); ctor = c.getConstructor(new Class[] {Project.class});
noArg = false; 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); project.setProjectReference(o);
return o; return o;
} catch (java.lang.reflect.InvocationTargetException ex) { } 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) { 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 * used to compare two definitions defined twice with the same
* name and the same types. * 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 * path so #sameDefinition cannot
* be used. * 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) { 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; return false;
} }
// all the names are the same: check if the class path of the loader // all the names are the same: check if the class path of the loader
// is the same // is the same
ClassLoader oldLoader = other.getClassLoader(); 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 && newLoader instanceof AntClassLoader
&& ((AntClassLoader) oldLoader).getClasspath() && ((AntClassLoader) oldLoader).getClasspath()
.equals(((AntClassLoader) newLoader).getClasspath());
.equals(((AntClassLoader) newLoader).getClasspath()));
} }


private String extractClassname(Class c) { 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. * This should be called by UnknownElement.
* *
@@ -173,10 +174,6 @@ public class ComponentHelper {
String componentType) String componentType)
throws BuildException { throws BuildException {
Object component = createComponent(componentType); Object component = createComponent(componentType);
if (component == null) {
return null;
}

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

return component; return component;
} }


@@ -213,10 +209,7 @@ public class ComponentHelper {
*/ */
public Class getComponentClass(String componentName) { public Class getComponentClass(String componentName) {
AntTypeDefinition def = getDefinition(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.setName(typeName);
def.setClass(typeClass); def.setClass(typeClass);
updateDataTypeDefinition(def); 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); org.apache.tools.ant.taskdefs.Property.class);
task = createNewTask(taskType); task = createNewTask(taskType);
} }

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

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


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


@@ -520,8 +509,7 @@ public class ComponentHelper {
if (v != null) { if (v != null) {
Enumeration taskEnum = v.elements(); Enumeration taskEnum = v.elements();
while (taskEnum.hasMoreElements()) { while (taskEnum.hasMoreElements()) {
WeakReference ref =
(WeakReference) taskEnum.nextElement();
WeakReference ref = (WeakReference) taskEnum.nextElement();
Task t = (Task) ref.get(); Task t = (Task) ref.get();
//being a weak ref, it may be null by this point //being a weak ref, it may be null by this point
if (t != null) { if (t != null) {
@@ -558,7 +546,7 @@ public class ComponentHelper {
* @param element The element to describe. * @param element The element to describe.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* *
* @return a description of the element type
* @return a description of the element type.
* *
* @since Ant 1.6 * @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 * 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) { 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( private boolean sameDefinition(
AntTypeDefinition def, AntTypeDefinition old) { 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. * modified definition.
* @param def the definition to update or insert
* @param def the definition to update or insert.
*/ */
private void updateDataTypeDefinition(AntTypeDefinition def) { private void updateDataTypeDefinition(AntTypeDefinition def) {
String name = def.getName(); 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) { public void enterAntLib(String uri) {
antLibCurrentUri = uri; antLibCurrentUri = uri;
@@ -653,26 +636,23 @@ public class ComponentHelper {
} }


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


/** /**
* Called at the end of processing an antlib
* Called at the end of processing an antlib.
*/ */
public void exitAntLib() { public void exitAntLib() {
antLibStack.pop(); 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() { private void initTasks() {
ClassLoader classLoader = null; ClassLoader classLoader = null;
@@ -717,7 +697,7 @@ public class ComponentHelper {
} }


/** /**
* load ant's datatypes
* Load ant's datatypes.
*/ */
private void initTypes() { private void initTypes() {
ClassLoader classLoader = null; 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. * associated URI has been examined for antlibs.
*/ */
private synchronized void checkNamespace(String componentName) { 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 static class AntTypeTable extends Hashtable {
private Project project; 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 * 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) { void setCreator(IntrospectionHelper.Creator creator) {
this.creator = creator; this.creator = creator;
@@ -123,7 +123,7 @@ public class RuntimeConfigurable implements Serializable {


/** /**
* Get the object for which this RuntimeConfigurable holds the configuration * Get the object for which this RuntimeConfigurable holds the configuration
* information
* information.
* *
* @return the object whose configure is held by this instance. * @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() { public String getPolyType() {
return polyType; 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) { public void setPolyType(String polyType) {
this.polyType = 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 name the name of the attribute.
* @param value the attribute's value. * @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 * @since Ant 1.6
*/ */
public Hashtable getAttributeMap() { public Hashtable getAttributeMap() {
@@ -264,7 +265,8 @@ public class RuntimeConfigurable implements Serializable {
characters.append(buf, start, count); 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 * concatenated, there is no way ( currently ) of keeping track of
* multiple fragments. * multiple fragments.
* *


Loading…
Cancel
Save