@@ -63,30 +63,31 @@ import org.apache.ant.antcore.antlib.AntLibrary;
import org.apache.ant.antcore.antlib.ComponentLibrary;
import org.apache.ant.antcore.antlib.ComponentLibrary;
import org.apache.ant.antcore.config.AntConfig;
import org.apache.ant.antcore.config.AntConfig;
import org.apache.ant.common.antlib.AntLibFactory;
import org.apache.ant.common.antlib.AntLibFactory;
import org.apache.ant.common.antlib.DeferredTask;
import org.apache.ant.common.antlib.ExecutionComponent;
import org.apache.ant.common.antlib.ExecutionComponent;
import org.apache.ant.common.antlib.Task;
import org.apache.ant.common.antlib.Task;
import org.apache.ant.common.antlib.TaskContainer;
import org.apache.ant.common.antlib.TaskContainer;
import org.apache.ant.common.event.BuildListener;
import org.apache.ant.common.event.BuildListener;
import org.apache.ant.common.event.MessageLevel;
import org.apache.ant.common.model.BuildElement;
import org.apache.ant.common.model.BuildElement;
import org.apache.ant.common.model.Project;
import org.apache.ant.common.model.Project;
import org.apache.ant.common.model.Target;
import org.apache.ant.common.model.Target;
import org.apache.ant.common.service.ComponentService;
import org.apache.ant.common.service.ComponentService;
import org.apache.ant.common.service.DataService;
import org.apache.ant.common.service.DataService;
import org.apache.ant.common.service.FileService;
import org.apache.ant.common.service.EventService;
import org.apache.ant.common.service.EventService;
import org.apache.ant.common.service.ExecService;
import org.apache.ant.common.service.FileService;
import org.apache.ant.common.service.MagicProperties;
import org.apache.ant.common.service.MagicProperties;
import org.apache.ant.common.util.AntException;
import org.apache.ant.common.util.AntException;
import org.apache.ant.common.util.ConfigException;
import org.apache.ant.common.util.ConfigException;
import org.apache.ant.common.util.ExecutionException;
import org.apache.ant.common.util.ExecutionException;
import org.apache.ant.common.util.FileUtils;
import org.apache.ant.common.util.FileUtils;
import org.apache.ant.common.util.MessageLevel;
import org.apache.ant.init.InitConfig;
import org.apache.ant.init.InitConfig;
import org.apache.ant.common.service.ExecService;
/**
/**
* An Frame maintains the state of a project during an execution.
* The Frame contains the data values set by Ant tasks as they are
* executed, including task definitions, property values, etc.
* An Frame maintains the state of a project during an execution. The Frame
* contains the data values set by Ant tasks as they are executed, including
* task definitions, property values, etc.
*
*
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
* @created 14 January 2002
* @created 14 January 2002
@@ -105,7 +106,7 @@ public class Frame {
private Map referencedFrames = new HashMap();
private Map referencedFrames = new HashMap();
/** Reflector objects used to configure Tasks from the Task models. */
/** Reflector objects used to configure Tasks from the Task models. */
private Map reflecto rs = new HashMap();
private Map sette rs = new HashMap();
/**
/**
* The context of this execution. This contains all data object's
* The context of this execution. This contains all data object's
@@ -165,7 +166,7 @@ public class Frame {
* imported
* imported
*/
*/
protected Frame(Map standardLibs, InitConfig initConfig,
protected Frame(Map standardLibs, InitConfig initConfig,
AntConfig config) throws ExecutionException {
AntConfig config) throws ExecutionException {
this.standardLibs = standardLibs;
this.standardLibs = standardLibs;
this.config = config;
this.config = config;
this.initConfig = initConfig;
this.initConfig = initConfig;
@@ -202,7 +203,6 @@ public class Frame {
= project.getReferencedProject(referenceName);
= project.getReferencedProject(referenceName);
Frame referencedFrame = createFrame(referencedProject);
Frame referencedFrame = createFrame(referencedProject);
referencedFrames.put(referenceName, referencedFrame);
referencedFrames.put(referenceName, referencedFrame);
}
}
configureServices();
configureServices();
@@ -359,8 +359,8 @@ public class Frame {
* Get a referenced frame by its reference name
* Get a referenced frame by its reference name
*
*
* @param referenceName the name under which the frame was imported.
* @param referenceName the name under which the frame was imported.
* @return the Frame asscociated with the given reference name
* or null if there is no such project.
* @return the Frame asscociated with the given reference name or null
* if there is no such project.
*/
*/
protected Frame getReferencedFrame(String referenceName) {
protected Frame getReferencedFrame(String referenceName) {
return (Frame)referencedFrames.get(referenceName);
return (Frame)referencedFrames.get(referenceName);
@@ -672,20 +672,26 @@ public class Frame {
/**
/**
* Gets the reflecto r for the given class
* Gets the sette r for the given class
*
*
* @param c the class for which the reflector is desired
* @param c the class for which the reflector is desired
* @return the reflector
* @return the reflector
*/
*/
private Reflector getReflecto r(Class c) {
if (reflecto rs.containsKey(c)) {
return (Reflector)reflecto rs.get(c);
private Setter getSette r(Class c) {
if (sette rs.containsKey(c)) {
return (Setter)sette rs.get(c);
}
}
ClassIntrospector introspector
= new ClassIntrospector(c, componentManager.getConverters());
Reflector reflector = introspector.getReflector();
reflectors.put(c, reflector);
return reflector;
Setter setter = null;
if (DeferredTask.class.isAssignableFrom(c)) {
setter = new DeferredSetter();
} else {
ClassIntrospector introspector
= new ClassIntrospector(c, componentManager.getConverters());
setter = introspector.getReflector();
}
setters.put(c, setter);
return setter;
}
}
@@ -759,15 +765,15 @@ public class Frame {
private void configureServices() {
private void configureServices() {
// create services and make them available in our services map
// create services and make them available in our services map
fileService = new CoreFileService(this);
fileService = new CoreFileService(this);
componentManager
= new ComponentManager(this, config.isRemoteLibAllowed());
componentManager = new ComponentManager(this,
config.isRemoteLibAllowed(), config.getLibraryPathsMap ());
dataService = new CoreDataService(this,
dataService = new CoreDataService(this,
config.isUnsetPropertiesAllowed());
config.isUnsetPropertiesAllowed());
services.put(FileService.class, fileService);
services.put(FileService.class, fileService);
services.put(ComponentService.class, componentManager);
services.put(ComponentService.class, componentManager);
services.put(DataService.class, dataService);
services.put(DataService.class, dataService);
services.put(EventService.class, new CoreEventService(this));
services.put(EventService.class, new CoreEventService(this));
services.put(ExecService.class, new CoreExecService(this));
services.put(ExecService.class, new CoreExecService(this));
}
}
@@ -784,27 +790,27 @@ public class Frame {
BuildElement model)
BuildElement model)
throws ExecutionException {
throws ExecutionException {
Reflector reflector = getReflecto r(element.getClass());
Setter setter = getSette r(element.getClass());
// start by setting the attributes of this element
// start by setting the attributes of this element
for (Iterator i = model.getAttributeNames(); i.hasNext(); ) {
for (Iterator i = model.getAttributeNames(); i.hasNext(); ) {
String attributeName = (String)i.next();
String attributeName = (String)i.next();
String attributeValue = model.getAttributeValue(attributeName);
String attributeValue = model.getAttributeValue(attributeName);
if (!reflecto r.supportsAttribute(attributeName)) {
if (!sette r.supportsAttribute(attributeName)) {
throw new ExecutionException(model.getType()
throw new ExecutionException(model.getType()
+ " does not support the \"" + attributeName
+ " does not support the \"" + attributeName
+ "\" attribute", model.getLocation());
+ "\" attribute", model.getLocation());
}
}
reflecto r.setAttribute(element, attributeName,
sette r.setAttribute(element, attributeName,
dataService.replacePropertyRefs(attributeValue));
dataService.replacePropertyRefs(attributeValue));
}
}
String modelText = model.getText().trim();
String modelText = model.getText().trim();
if (modelText.length() != 0) {
if (modelText.length() != 0) {
if (!reflecto r.supportsText()) {
if (!sette r.supportsText()) {
throw new ExecutionException(model.getType()
throw new ExecutionException(model.getType()
+ " does not support content", model.getLocation());
+ " does not support content", model.getLocation());
}
}
reflecto r.addText(element,
sette r.addText(element,
dataService.replacePropertyRefs(modelText));
dataService.replacePropertyRefs(modelText));
}
}
@@ -817,7 +823,7 @@ public class Frame {
if (element instanceof TaskContainer
if (element instanceof TaskContainer
&& info != null
&& info != null
&& info.getDefinitionType() == AntLibrary.TASKDEF
&& info.getDefinitionType() == AntLibrary.TASKDEF
&& !reflecto r.supportsNestedElement(nestedElementName)) {
&& !sette r.supportsNestedElement(nestedElementName)) {
// it is a nested task
// it is a nested task
TaskContext nestedContext
TaskContext nestedContext
= configureTask(nestedElementModel);
= configureTask(nestedElementModel);
@@ -826,11 +832,11 @@ public class Frame {
// method of executing tasks
// method of executing tasks
container.addTask(nestedContext.getTask());
container.addTask(nestedContext.getTask());
} else {
} else {
if (reflecto r.supportsNestedAdder(nestedElementName)) {
addNestedElement(factory, reflecto r, element,
if (sette r.supportsNestedAdder(nestedElementName)) {
addNestedElement(factory, sette r, element,
nestedElementModel);
nestedElementModel);
} else if (reflecto r.supportsNestedCreator(nestedElementName)) {
createNestedElement(factory, reflecto r, element,
} else if (sette r.supportsNestedCreator(nestedElementName)) {
createNestedElement(factory, sette r, element,
nestedElementModel);
nestedElementModel);
} else {
} else {
throw new ExecutionException(model.getType()
throw new ExecutionException(model.getType()
@@ -846,7 +852,7 @@ public class Frame {
/**
/**
* Create a nested element for the given object according to the model.
* Create a nested element for the given object according to the model.
*
*
* @param reflector the reflecto r instance of the container object
* @param setter the Sette r instance of the container object
* @param element the container object for which a nested element is
* @param element the container object for which a nested element is
* required.
* required.
* @param model the build model for the nestd element
* @param model the build model for the nestd element
@@ -855,7 +861,7 @@ public class Frame {
* @exception ExecutionException if the nested element cannot be
* @exception ExecutionException if the nested element cannot be
* created.
* created.
*/
*/
private void createNestedElement(AntLibFactory factory, Reflector reflecto r,
private void createNestedElement(AntLibFactory factory, Setter sette r,
Object element, BuildElement model)
Object element, BuildElement model)
throws ExecutionException {
throws ExecutionException {
log("The use of create methods is deprecated - class: "
log("The use of create methods is deprecated - class: "
@@ -864,7 +870,7 @@ public class Frame {
String nestedElementName = model.getType();
String nestedElementName = model.getType();
try {
try {
Object nestedElement
Object nestedElement
= reflecto r.createElement(element, nestedElementName);
= sette r.createElement(element, nestedElementName);
factory.registerCreatedElement(nestedElement);
factory.registerCreatedElement(nestedElement);
if (nestedElement instanceof ExecutionComponent) {
if (nestedElement instanceof ExecutionComponent) {
ExecutionComponent component
ExecutionComponent component
@@ -891,7 +897,7 @@ public class Frame {
/**
/**
* Create and add a nested element
* Create and add a nested element
*
*
* @param reflector The reflecto r instance for the container element
* @param setter The Sette r instance for the container element
* @param element the container element in which the nested element will
* @param element the container element in which the nested element will
* be created
* be created
* @param model the model of the nested element
* @param model the model of the nested element
@@ -899,12 +905,12 @@ public class Frame {
* which the attribute is to be added.
* which the attribute is to be added.
* @exception ExecutionException if the nested element cannot be created
* @exception ExecutionException if the nested element cannot be created
*/
*/
private void addNestedElement(AntLibFactory factory, Reflector reflecto r,
private void addNestedElement(AntLibFactory factory, Setter sette r,
Object element, BuildElement model)
Object element, BuildElement model)
throws ExecutionException {
throws ExecutionException {
String nestedElementName = model.getType();
String nestedElementName = model.getType();
Class nestedType = reflecto r.getType(nestedElementName);
Class nestedType = sette r.getType(nestedElementName);
// is there a polymorph indicator - look in Ant aspects
// is there a polymorph indicator - look in Ant aspects
String typeName = model.getAspectValue(ANT_ASPECT, "type");
String typeName = model.getAspectValue(ANT_ASPECT, "type");
@@ -947,7 +953,7 @@ public class Frame {
model.getLocation());
model.getLocation());
}
}
typeInstance = createTypeInstance(nestedType, factory, model);
typeInstance = createTypeInstance(nestedType, factory, model, null );
}
}
// is the typeInstance compatible with the type expected
// is the typeInstance compatible with the type expected
@@ -965,7 +971,7 @@ public class Frame {
model.getLocation());
model.getLocation());
}
}
}
}
reflecto r.addElement(element, nestedElementName, typeInstance);
sette r.addElement(element, nestedElementName, typeInstance);
}
}
@@ -989,8 +995,9 @@ public class Frame {
}
}
String className = taskDefInfo.getClassName();
String className = taskDefInfo.getClassName();
ComponentLibrary componentLibrary
= taskDefInfo.getComponentLibrary();
ComponentLibrary componentLibrary
= taskDefInfo.getComponentLibrary();
String localName = taskDefInfo.getLocalName();
try {
try {
ClassLoader taskClassLoader = componentLibrary.getClassLoader();
ClassLoader taskClassLoader = componentLibrary.getClassLoader();
@@ -998,7 +1005,8 @@ public class Frame {
= Class.forName(className, true, taskClassLoader);
= Class.forName(className, true, taskClassLoader);
AntLibFactory libFactory
AntLibFactory libFactory
= componentManager.getLibFactory(componentLibrary);
= componentManager.getLibFactory(componentLibrary);
Object element = libFactory.createTaskInstance(elementClass);
Object element
= libFactory.createTaskInstance(elementClass, localName);
Task task = null;
Task task = null;
if (element instanceof Task) {
if (element instanceof Task) {
@@ -1062,8 +1070,9 @@ public class Frame {
}
}
String className = typeDefInfo.getClassName();
String className = typeDefInfo.getClassName();
ComponentLibrary componentLibrary
= typeDefInfo.getComponentLibrary();
ComponentLibrary componentLibrary
= typeDefInfo.getComponentLibrary();
String localName = typeDefInfo.getLocalName();
try {
try {
ClassLoader typeClassLoader = componentLibrary.getClassLoader();
ClassLoader typeClassLoader = componentLibrary.getClassLoader();
@@ -1074,7 +1083,7 @@ public class Frame {
AntLibFactory libFactory
AntLibFactory libFactory
= componentManager.getLibFactory(componentLibrary);
= componentManager.getLibFactory(componentLibrary);
Object typeInstance
Object typeInstance
= createTypeInstance(typeClass, libFactory, model);
= createTypeInstance(typeClass, libFactory, model, localName );
setContextLoader(currentLoader);
setContextLoader(currentLoader);
return typeInstance;
return typeInstance;
@@ -1095,15 +1104,17 @@ public class Frame {
* @param model the model describing the required configuration of the
* @param model the model describing the required configuration of the
* instance
* instance
* @param libFactory the factory object of the typeClass's Ant library
* @param libFactory the factory object of the typeClass's Ant library
* @param localName the name of the type within its Ant library
* @return an instance of the given class appropriately configured
* @return an instance of the given class appropriately configured
* @exception ExecutionException if there is a problem creating the type
* @exception ExecutionException if there is a problem creating the type
* instance
* instance
*/
*/
private Object createTypeInstance(Class typeClass, AntLibFactory libFactory,
private Object createTypeInstance(Class typeClass, AntLibFactory libFactory,
BuildElement model)
BuildElement model, String localName )
throws ExecutionException {
throws ExecutionException {
try {
try {
Object typeInstance = libFactory.createTypeInstance(typeClass);
Object typeInstance
= libFactory.createTypeInstance(typeClass, localName);
if (typeInstance instanceof ExecutionComponent) {
if (typeInstance instanceof ExecutionComponent) {
ExecutionComponent component = (ExecutionComponent)typeInstance;
ExecutionComponent component = (ExecutionComponent)typeInstance;