PR: 21296 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274761 13f79535-47bb-0310-9956-ffa450edef68master
@@ -65,7 +65,6 @@ package org.apache.tools.ant; | |||
* @author Peter Reilly | |||
*/ | |||
public class AntTypeDefinition { | |||
private Project project; | |||
private String name; | |||
private Class clazz; | |||
private Class adapterClass; | |||
@@ -74,13 +73,11 @@ public class AntTypeDefinition { | |||
private ClassLoader classLoader; | |||
/** | |||
* Clone this definiton and changed the cloned definitions' project. | |||
* @param p the project the cloned definition lives in | |||
* Clone this definition and changed the cloned definitions' project. | |||
* @return the cloned definition | |||
*/ | |||
public AntTypeDefinition copy(Project p) { | |||
public AntTypeDefinition copy() { | |||
AntTypeDefinition copy = new AntTypeDefinition(); | |||
copy.project = p; | |||
copy.name = name; | |||
copy.clazz = clazz; | |||
copy.adapterClass = adapterClass; | |||
@@ -90,14 +87,6 @@ public class AntTypeDefinition { | |||
return copy; | |||
} | |||
/** | |||
* set the project on the definition | |||
* @param project the project this definition belongs in | |||
*/ | |||
public void setProject(Project project) { | |||
this.project = project; | |||
} | |||
/** | |||
* set the definition's name | |||
* @param name the name of the definition | |||
@@ -190,11 +179,12 @@ public class AntTypeDefinition { | |||
* (adapted class) if there is an adpater | |||
* class and the definition class is not | |||
* assignable from the assignable class. | |||
* @param project the current project | |||
* @return the exposed class | |||
*/ | |||
public Class getExposedClass() { | |||
public Class getExposedClass(Project project) { | |||
if (adaptToClass != null) { | |||
Class z = getTypeClass(); | |||
Class z = getTypeClass(project); | |||
if (z == null) { | |||
return null; | |||
} | |||
@@ -205,14 +195,15 @@ public class AntTypeDefinition { | |||
if (adapterClass != null) { | |||
return adapterClass; | |||
} | |||
return getTypeClass(); | |||
return getTypeClass(project); | |||
} | |||
/** | |||
* get the definition class | |||
* @param project the current project | |||
* @return the type of the definition | |||
*/ | |||
public Class getTypeClass() { | |||
public Class getTypeClass(Project project) { | |||
if (clazz != null) { | |||
return clazz; | |||
} | |||
@@ -237,23 +228,24 @@ public class AntTypeDefinition { | |||
/** | |||
* create an instance of the definition. | |||
* The instance may be wrapped in a proxy class. | |||
* @param project the current project | |||
* @return the created object | |||
*/ | |||
public Object create() { | |||
return icreate(); | |||
public Object create(Project project) { | |||
return icreate(project); | |||
} | |||
/** | |||
* Create a component object based on | |||
* its definition | |||
*/ | |||
private Object icreate() { | |||
Class c = getTypeClass(); | |||
private Object icreate(Project project) { | |||
Class c = getTypeClass(project); | |||
if (c == null) { | |||
return null; | |||
} | |||
Object o = createAndSet(c); | |||
Object o = createAndSet(project, c); | |||
if (o == null || adapterClass == null) { | |||
return o; | |||
} | |||
@@ -264,7 +256,8 @@ public class AntTypeDefinition { | |||
} | |||
} | |||
TypeAdapter adapterObject = (TypeAdapter) createAndSet(adapterClass); | |||
TypeAdapter adapterObject = (TypeAdapter) createAndSet( | |||
project, adapterClass); | |||
if (adapterObject == null) { | |||
return null; | |||
} | |||
@@ -281,10 +274,11 @@ 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 | |||
*/ | |||
public void checkClass() { | |||
public void checkClass(Project project) { | |||
if (clazz == null) { | |||
clazz = getTypeClass(); | |||
clazz = getTypeClass(project); | |||
if (clazz == null) { | |||
throw new BuildException( | |||
"Unable to create class for " + getName()); | |||
@@ -298,7 +292,8 @@ public class AntTypeDefinition { | |||
needToCheck = false; | |||
} | |||
if (needToCheck) { | |||
TypeAdapter adapter = (TypeAdapter) createAndSet(adapterClass); | |||
TypeAdapter adapter = (TypeAdapter) createAndSet( | |||
project, adapterClass); | |||
if (adapter == null) { | |||
throw new BuildException("Unable to create adapter object"); | |||
} | |||
@@ -311,7 +306,7 @@ public class AntTypeDefinition { | |||
* get the constructor of the defintion | |||
* and invoke it. | |||
*/ | |||
private Object createAndSet(Class c) { | |||
private Object createAndSet(Project project, Class c) { | |||
try { | |||
java.lang.reflect.Constructor ctor = null; | |||
boolean noArg = false; | |||
@@ -154,7 +154,6 @@ public class ComponentHelper { | |||
AntTypeTable typeTable = helper.antTypeTable; | |||
for (Iterator i = typeTable.values().iterator(); i.hasNext();) { | |||
AntTypeDefinition def = (AntTypeDefinition) i.next(); | |||
def = def.copy(project); | |||
antTypeTable.put(def.getName(), def); | |||
} | |||
} | |||
@@ -256,7 +255,6 @@ public class ComponentHelper { | |||
public void addTaskDefinition(String taskName, Class taskClass) { | |||
checkTaskClass(taskClass); | |||
AntTypeDefinition def = new AntTypeDefinition(); | |||
def.setProject(project); | |||
def.setName(taskName); | |||
def.setClassLoader(taskClass.getClassLoader()); | |||
def.setClass(taskClass); | |||
@@ -386,7 +384,6 @@ public class ComponentHelper { | |||
*/ | |||
public void addDataTypeDefinition(String typeName, Class typeClass) { | |||
AntTypeDefinition def = new AntTypeDefinition(); | |||
def.setProject(project); | |||
def.setName(typeName); | |||
def.setClass(typeClass); | |||
updateDataTypeDefinition(def); | |||
@@ -567,7 +564,7 @@ public class ComponentHelper { | |||
Class elementClass = element.getClass(); | |||
for (Iterator i = antTypeTable.values().iterator(); i.hasNext();) { | |||
AntTypeDefinition def = (AntTypeDefinition) i.next(); | |||
if (elementClass == def.getExposedClass()) { | |||
if (elementClass == def.getExposedClass(project)) { | |||
return "The <" + def.getName() + "> type"; | |||
} | |||
} | |||
@@ -578,10 +575,11 @@ public class ComponentHelper { | |||
/** return true if the two definitions are the same */ | |||
private boolean sameDefinition( | |||
AntTypeDefinition def, AntTypeDefinition old) { | |||
if (! (old.getTypeClass().equals(def.getTypeClass()))) { | |||
if (! (old.getTypeClass(project).equals(def.getTypeClass(project)))) { | |||
return false; | |||
} | |||
if (! (old.getExposedClass().equals(def.getExposedClass()))) { | |||
if (! (old.getExposedClass(project).equals( | |||
def.getExposedClass(project)))) { | |||
return false; | |||
} | |||
return true; | |||
@@ -649,7 +647,6 @@ public class ComponentHelper { | |||
String name = (String) enum.nextElement(); | |||
String className = props.getProperty(name); | |||
AntTypeDefinition def = new AntTypeDefinition(); | |||
def.setProject(project); | |||
def.setName(name); | |||
def.setClassName(className); | |||
def.setClassLoader(classLoader); | |||
@@ -692,7 +689,6 @@ public class ComponentHelper { | |||
String name = (String) enum.nextElement(); | |||
String className = props.getProperty(name); | |||
AntTypeDefinition def = new AntTypeDefinition(); | |||
def.setProject(project); | |||
def.setName(name); | |||
def.setClassName(className); | |||
def.setClassLoader(classLoader); | |||
@@ -733,7 +729,7 @@ public class ComponentHelper { | |||
if (def == null) { | |||
return null; | |||
} | |||
return def.create(); | |||
return def.create(project); | |||
} | |||
public Class getTypeClass(String name) { | |||
@@ -741,7 +737,7 @@ public class ComponentHelper { | |||
if (def == null) { | |||
return null; | |||
} | |||
return def.getTypeClass(); | |||
return def.getTypeClass(project); | |||
} | |||
public Class getExposedClass(String name) { | |||
@@ -749,13 +745,13 @@ public class ComponentHelper { | |||
if (def == null) { | |||
return null; | |||
} | |||
return def.getExposedClass(); | |||
return def.getExposedClass(project); | |||
} | |||
public boolean contains(Object clazz) { | |||
for (Iterator i = values().iterator(); i.hasNext();) { | |||
AntTypeDefinition def = (AntTypeDefinition) i.next(); | |||
Class c = def.getExposedClass(); | |||
Class c = def.getExposedClass(project); | |||
if (c == clazz) | |||
return true; | |||
} | |||
@@ -528,14 +528,13 @@ public abstract class Definer extends Task { | |||
AntTypeDefinition def = new AntTypeDefinition(); | |||
def.setName(name); | |||
def.setProject(getProject()); | |||
def.setClassName(classname); | |||
def.setClass(cl); | |||
def.setAdapterClass(adapterClass); | |||
def.setAdaptToClass(adaptToClass); | |||
def.setClassLoader(al); | |||
if (cl != null) { | |||
def.checkClass(); | |||
def.checkClass(project); | |||
} | |||
ComponentHelper.getComponentHelper(getProject()) | |||
.addDataTypeDefinition(def); | |||