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