git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273409 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,182 +0,0 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.tasks; | |||||
import org.apache.tools.ant.*; | |||||
import org.apache.tools.ant.helper.*; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.FileNotFoundException; | |||||
import java.io.IOException; | |||||
import java.io.UnsupportedEncodingException; | |||||
import java.util.Hashtable; | |||||
import java.util.Vector; | |||||
import java.util.Enumeration; | |||||
import java.util.Locale; | |||||
import java.util.Stack; | |||||
import org.xml.sax.Locator; | |||||
import org.xml.sax.InputSource; | |||||
import org.xml.sax.SAXParseException; | |||||
import org.xml.sax.XMLReader; | |||||
import org.xml.sax.SAXException; | |||||
import org.xml.sax.DocumentHandler; | |||||
import org.xml.sax.Attributes; | |||||
import org.xml.sax.AttributeList; | |||||
import org.xml.sax.helpers.XMLReaderAdapter; | |||||
import org.xml.sax.helpers.DefaultHandler; | |||||
import org.xml.sax.helpers.AttributeListImpl; | |||||
import org.apache.tools.ant.util.JAXPUtils; | |||||
/** | |||||
* Import task. | |||||
* | |||||
* It must be 'top level'. On execution it'll read another file | |||||
* into the same Project. | |||||
* | |||||
* @author Nicola Ken Barozzi nicolaken@apache.org | |||||
* @author Dominique Devienne DDevienne@lgc.com | |||||
* @author Costin Manolache | |||||
*/ | |||||
public class Import extends Task { | |||||
String file; | |||||
public void setFile( String file ) { | |||||
// I don't think we can use File - different rules | |||||
// for relative paths. | |||||
this.file=file; | |||||
} | |||||
/** | |||||
* Initialisation routine called after handler creation | |||||
* with the element name and attributes. The attributes which | |||||
* this handler can deal with are: <code>"default"</code>, | |||||
* <code>"name"</code>, <code>"id"</code> and <code>"basedir"</code>. | |||||
* | |||||
* @param tag Name of the element which caused this handler | |||||
* to be created. Should not be <code>null</code>. | |||||
* Ignored in this implementation. | |||||
* @param attrs Attributes of the element which caused this | |||||
* handler to be created. Must not be <code>null</code>. | |||||
* | |||||
* @exception SAXParseException if an unexpected attribute is | |||||
* encountered or if the <code>"default"</code> attribute | |||||
* is missing. | |||||
*/ | |||||
public void execute() throws BuildException | |||||
{ | |||||
if (file == null) { | |||||
throw new BuildException("import element appears without a file attribute"); | |||||
} | |||||
ProjectHelperImpl2.AntXmlContext context; | |||||
context=(ProjectHelperImpl2.AntXmlContext)project.getReference("ant.parsing.context"); | |||||
context.importlevel++; | |||||
project.log("importlevel: "+(context.importlevel-1)+" -> "+(context.importlevel), | |||||
Project.MSG_DEBUG); | |||||
project.log("Importing file "+file+" from "+ | |||||
context.buildFile.getAbsolutePath(), | |||||
Project.MSG_VERBOSE); | |||||
// Paths are relative to the build file they're imported from, | |||||
// *not* the current directory (same as entity includes). | |||||
File importedFile = new File(file); | |||||
if (!importedFile.isAbsolute()) { | |||||
importedFile = new File(context.buildFileParent, file); | |||||
} | |||||
if (!importedFile.exists()) { | |||||
throw new BuildException("Cannot find "+file+" imported from "+ | |||||
context.buildFile.getAbsolutePath()); | |||||
} | |||||
// Add parent build file to the map to avoid cycles... | |||||
String parentFilename = getPath(context.buildFile); | |||||
if (!context.importedFiles.containsKey(parentFilename)) { | |||||
context.importedFiles.put(parentFilename, context.buildFile); | |||||
} | |||||
// Make sure we import the file only once | |||||
String importedFilename = getPath(importedFile); | |||||
if (context.importedFiles.containsKey(importedFilename)) { | |||||
project.log("\nSkipped already imported file:\n "+importedFilename+"\n", | |||||
Project.MSG_WARN); | |||||
context.importlevel--; | |||||
project.log("importlevel: "+context.importlevel+" <- "+ | |||||
(context.importlevel+1) ,Project.MSG_DEBUG); | |||||
return; | |||||
} else { | |||||
context.importedFiles.put(importedFilename, importedFile); | |||||
} | |||||
context.ignoreProjectTag=true; | |||||
context.helper.parse(project, importedFile, new ProjectHelperImpl2.RootHandler(context)); | |||||
context.importlevel--; | |||||
project.log("importlevel: "+context.importlevel+" <- "+ | |||||
(context.importlevel+1) ,Project.MSG_DEBUG); | |||||
} | |||||
private static String getPath(File file) { | |||||
try { | |||||
return file.getCanonicalPath(); | |||||
} | |||||
catch (IOException e) { | |||||
return file.getAbsolutePath(); | |||||
} | |||||
} | |||||
} |
@@ -1,219 +0,0 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant; | |||||
import org.apache.tools.ant.helper.*; | |||||
import java.util.Enumeration; | |||||
import java.util.Locale; | |||||
import java.util.Vector; | |||||
import java.util.Hashtable; | |||||
import org.xml.sax.AttributeList; | |||||
import org.xml.sax.Attributes; | |||||
import org.xml.sax.helpers.AttributeListImpl; | |||||
import org.xml.sax.helpers.AttributesImpl; | |||||
/** | |||||
* Deals with properties - substitution, dynamic properties, etc. | |||||
* | |||||
* Eventually the static methods from ProjectHelper should be | |||||
* moved here ( with a wrapper for backward compat ). | |||||
* | |||||
* Also the property store ( Hashtable ) and all property manipulation | |||||
* logic could be moved here. | |||||
* | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
* @author Costin Manolache | |||||
*/ | |||||
public class PropertyHelper { | |||||
Project project; | |||||
Vector propertyInterceptors=new Vector(); | |||||
protected PropertyHelper() { | |||||
} | |||||
public void setProject(Project p ) { | |||||
this.project=p; | |||||
} | |||||
/** Factory method to create a property processor. | |||||
* Right now returns the singleton instance of PropertyHelper, | |||||
* in future it may use discovery of config to return a | |||||
* customized version, for integration in other apps. | |||||
*/ | |||||
public static PropertyHelper getPropertyHelper(Project project) { | |||||
PropertyHelper ph=(PropertyHelper)project.getReference( "ant.PropertyHelper" ); | |||||
if( ph!=null ) return ph; | |||||
ph=new PropertyHelper(); | |||||
ph.setProject( project ); | |||||
project.addReference( "ant.PropertyHelper",ph ); | |||||
return ph; | |||||
} | |||||
public void addPropertyInterceptor( PropertyInterceptor pi ) { | |||||
propertyInterceptors.addElement( pi ); | |||||
} | |||||
// public Vector getPropertyInterceptors() { | |||||
// return propertyInterceptors; | |||||
// } | |||||
/** Process an value, doing the replacements. | |||||
*/ | |||||
public String replaceProperties( String value ) { | |||||
if (value == null) { | |||||
return null; | |||||
} | |||||
Vector fragments = new Vector(); | |||||
Vector propertyRefs = new Vector(); | |||||
// XXX Move the static method here - if this is accepted in the main | |||||
// branch. | |||||
ProjectHelper.parsePropertyString(value, fragments, propertyRefs); | |||||
StringBuffer sb = new StringBuffer(); | |||||
Enumeration i = fragments.elements(); | |||||
Enumeration j = propertyRefs.elements(); | |||||
while (i.hasMoreElements()) { | |||||
String fragment = (String) i.nextElement(); | |||||
if (fragment == null) { | |||||
String propertyName = (String) j.nextElement(); | |||||
Object repl=processDynamic( project, propertyName); | |||||
if( repl==null) { | |||||
// default to the static property. | |||||
repl=project.getProperty( propertyName ); | |||||
} | |||||
if (repl==null ) { | |||||
project.log("Property ${" + propertyName | |||||
+ "} has not been set", Project.MSG_VERBOSE); | |||||
fragment="${" + propertyName + "}"; | |||||
} else { | |||||
fragment = (String) repl; | |||||
} | |||||
} | |||||
sb.append(fragment); | |||||
} | |||||
return sb.toString(); | |||||
} | |||||
/** Use the reference table to generate values for ${} substitution. | |||||
* To preserve backward compat ( as much as possible ) we'll only process | |||||
* ids with a 'namespace-like' syntax. | |||||
* | |||||
* Currently we support: | |||||
* dom:idName:/xpath/like/syntax - the referenced node must be a DOM, we'll use | |||||
* XPath to extract a node. ( a simplified syntax is handled | |||||
* directly, XXX used for 'real' xpaths ). | |||||
* toString:idName - we use toString on the referenced object | |||||
* bean:idName.propertyName - we get the idName and call the getter for the property. | |||||
*/ | |||||
Object processDynamic( Project project, String name ) { | |||||
for(int i=0; i<propertyInterceptors.size(); i++ ) { | |||||
PropertyInterceptor pi=(PropertyInterceptor)propertyInterceptors.elementAt( i ); | |||||
Object o=pi.getProperty( project, null, name ); | |||||
if( o!=null ) | |||||
return o; | |||||
} | |||||
// experimental - will be removed. | |||||
if( name.startsWith( "toString:" )) { | |||||
name=name.substring( "toString:".length()); | |||||
Object v=project.getReference( name ); | |||||
if( v==null ) return null; | |||||
return v.toString(); | |||||
} | |||||
return null; | |||||
} | |||||
/** Configure a component using SAX2 attributes. | |||||
*/ | |||||
public void configure( Object target, Attributes attrs, Project project ) | |||||
throws BuildException | |||||
{ | |||||
if (target instanceof TaskAdapter) { | |||||
target = ((TaskAdapter) target).getProxy(); | |||||
} | |||||
IntrospectionHelper ih = | |||||
IntrospectionHelper.getHelper(target.getClass()); | |||||
project.addBuildListener(ih); | |||||
for (int i = 0; i < attrs.getLength(); i++) { | |||||
// reflect these into the target | |||||
String value = replaceProperties(attrs.getValue(i)); | |||||
try { | |||||
ih.setAttribute(project, target, | |||||
attrs.getQName(i).toLowerCase(Locale.US), value); | |||||
} catch (BuildException be) { | |||||
// id attribute must be set externally | |||||
if (!attrs.getQName(i).equals("id")) { | |||||
throw be; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -1,95 +0,0 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant; | |||||
import org.apache.tools.ant.helper.*; | |||||
import java.util.Enumeration; | |||||
import java.util.Locale; | |||||
import java.util.Vector; | |||||
import java.util.Hashtable; | |||||
import org.xml.sax.AttributeList; | |||||
import org.xml.sax.Attributes; | |||||
import org.xml.sax.helpers.AttributeListImpl; | |||||
import org.xml.sax.helpers.AttributesImpl; | |||||
/** | |||||
* The new XML processor will use this interface to support | |||||
* dynamic properties. | |||||
* | |||||
* Any task/type that implements this interface will be registered | |||||
* and will receive notification of each property get operations | |||||
* executed by the processor. | |||||
* | |||||
* XXX In ant1.6+, tasks implementing the interface will also | |||||
* receive notification when a property is set. | |||||
* | |||||
* @author Costin Manolache | |||||
*/ | |||||
public interface PropertyInterceptor { | |||||
/** | |||||
* Called for each ${} property. If the result is null the | |||||
* next PropertyInterceptor will be called. If all interceptors | |||||
* return null, the properties stored in Project are used. | |||||
*/ | |||||
public Object getProperty( Project p, String ns, String name ); | |||||
/** | |||||
* Called when a property/reference is recorded. | |||||
* XXX Not implemented yet. | |||||
*/ | |||||
// public boolean setProperty( String ns, String name, Object value ); | |||||
} |
@@ -1,28 +0,0 @@ | |||||
Features | |||||
- SAX2 support | |||||
- namespaces ( not used - pending decision on semantics of ns ) | |||||
- import ( with package.target, not super.target ) | |||||
- classloader hack for optional | |||||
- dynamic properties ( only interface + hooks, no real binding ) | |||||
Todo | |||||
- start the JMX support, MBeans for Project, Target and Tasks ( using the dynamic | |||||
mbean tool in tomcat ). | |||||
- add JmxTaskAdapter that will wrap mbeans ( similar with the Beans wrapped by task adapter ) | |||||
- add support for Jmx attributes as dynamic properties. | |||||
Build | |||||
The build.xml file will copy the files in the main tree and compile | |||||
a package - ant-sax2.jar. | |||||
Install | |||||
Copy ant-sax2.jar to jakarta-ant-1.5/lib. | |||||
@@ -1,270 +0,0 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant; | |||||
import org.apache.tools.ant.helper.*; | |||||
import java.util.Enumeration; | |||||
import java.util.Locale; | |||||
import java.util.Vector; | |||||
import java.util.Hashtable; | |||||
import org.xml.sax.AttributeList; | |||||
import org.xml.sax.Attributes; | |||||
import org.xml.sax.helpers.AttributeListImpl; | |||||
import org.xml.sax.helpers.AttributesImpl; | |||||
/** | |||||
* Wrapper class that holds the attributes of an element, its children, and | |||||
* any text within it. It then takes care of configuring that element at | |||||
* runtime. | |||||
* | |||||
* This uses SAX2 and a more flexible substitution mechansim, based on | |||||
* o.a.tomcat.util.IntrospectionUtil. | |||||
* | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
* @author Costin Manolache | |||||
*/ | |||||
public class RuntimeConfigurable2 extends RuntimeConfigurable { | |||||
/** Name of the element to configure. */ | |||||
private String elementTag = null; | |||||
/** List of child element wrappers. */ | |||||
private Vector children = new Vector(); | |||||
/** The element to configure. */ | |||||
private Object wrappedObject = null; | |||||
/** XML attributes for the element. */ | |||||
private Attributes attributes; | |||||
/** Text appearing within the element. */ | |||||
private StringBuffer characters = new StringBuffer(); | |||||
/** | |||||
* Sole constructor creating a wrapper for the specified object. | |||||
* | |||||
* @param proxy The element to configure. Must not be <code>null</code>. | |||||
* @param elementTag The tag name generating this element. | |||||
* Should not be <code>null</code>. | |||||
*/ | |||||
public RuntimeConfigurable2(Object proxy, String elementTag) { | |||||
super( proxy, elementTag ); | |||||
wrappedObject = proxy; | |||||
this.elementTag = elementTag; | |||||
if( proxy instanceof Task ) | |||||
((Task)proxy).setRuntimeConfigurableWrapper( this ); | |||||
} | |||||
/** | |||||
* Sets the element to configure. This is used when the real type of | |||||
* an element isn't known at the time of wrapper creation. | |||||
* | |||||
* @param proxy The element to configure. Must not be <code>null</code>. | |||||
*/ | |||||
public void setProxy(Object proxy) { | |||||
wrappedObject = proxy; | |||||
} | |||||
public Object getProxy() { | |||||
return wrappedObject; | |||||
} | |||||
/** | |||||
* Sets the attributes for the wrapped element. | |||||
* | |||||
* @param attributes List of attributes defined in the XML for this | |||||
* element. May be <code>null</code>. | |||||
* @deprecated It shouldn't be called by anyone except ProjectHelper | |||||
*/ | |||||
public void setAttributes(AttributeList attributes) { | |||||
// this.attributes = new AttributeListImpl(attributes); | |||||
} | |||||
public void setAttributes2(Attributes attributes) { | |||||
this.attributes=new AttributesImpl( attributes ); | |||||
} | |||||
/** | |||||
* Returns the list of attributes for the wrapped element. | |||||
* | |||||
* @return An AttributeList representing the attributes defined in the | |||||
* XML for this element. May be <code>null</code>. | |||||
* @deprecated only for bkwd compatibility | |||||
*/ | |||||
public AttributeList getAttributes() { | |||||
return sax1Attributes( attributes ); | |||||
} | |||||
public Attributes getAttributes2() { | |||||
return attributes; | |||||
} | |||||
public static AttributeList sax1Attributes( Attributes sax2Att ) { | |||||
AttributeListImpl sax1Att=new AttributeListImpl(); | |||||
int length = sax2Att.getLength(); | |||||
if (length > 0) { | |||||
for (int i = 0; i < length; i++) { | |||||
// System.out.println("Attributes: " + sax2Att.getQName(i) + " " + | |||||
// sax2Att.getValue(i)); | |||||
sax1Att.addAttribute( sax2Att.getQName(i), | |||||
sax2Att.getType(i), | |||||
sax2Att.getValue(i)); | |||||
} | |||||
} | |||||
return sax1Att; | |||||
} | |||||
/** | |||||
* Adds a child element to the wrapped element. | |||||
* | |||||
* @param child The child element wrapper to add to this one. | |||||
* Must not be <code>null</code>. | |||||
*/ | |||||
public void addChild(RuntimeConfigurable child) { | |||||
children.addElement(child); | |||||
} | |||||
/** | |||||
* Returns the child wrapper at the specified position within the list. | |||||
* | |||||
* @param index The index of the child to return. | |||||
* | |||||
* @return The child wrapper at position <code>index</code> within the | |||||
* list. | |||||
*/ | |||||
public RuntimeConfigurable getChild(int index) { | |||||
return (RuntimeConfigurable) children.elementAt(index); | |||||
} | |||||
/** | |||||
* Adds characters from #PCDATA areas to the wrapped element. | |||||
* | |||||
* @param data Text to add to the wrapped element. | |||||
* Should not be <code>null</code>. | |||||
*/ | |||||
public void addText(String data) { | |||||
characters.append(data); | |||||
} | |||||
/** | |||||
* Adds characters from #PCDATA areas to the wrapped element. | |||||
* | |||||
* @param buf A character array of the text within the element. | |||||
* Must not be <code>null</code>. | |||||
* @param start The start element in the array. | |||||
* @param count The number of characters to read from the array. | |||||
* | |||||
*/ | |||||
public void addText(char[] buf, int start, int count) { | |||||
addText(new String(buf, start, count)); | |||||
} | |||||
/** | |||||
* Returns the tag name of the wrapped element. | |||||
* | |||||
* @return The tag name of the wrapped element. This is unlikely | |||||
* to be <code>null</code>, but may be. | |||||
*/ | |||||
public String getElementTag() { | |||||
return elementTag; | |||||
} | |||||
/** | |||||
* Configures the wrapped element and all its children. | |||||
* The attributes and text for the wrapped element are configured, | |||||
* and then each child is configured and added. Each time the | |||||
* wrapper is configured, the attributes and text for it are | |||||
* reset. | |||||
* | |||||
* If the element has an <code>id</code> attribute, a reference | |||||
* is added to the project as well. | |||||
* | |||||
* @param p The project containing the wrapped element. | |||||
* Must not be <code>null</code>. | |||||
* | |||||
* @exception BuildException if the configuration fails, for instance due | |||||
* to invalid attributes or children, or text being added to | |||||
* an element which doesn't accept it. | |||||
*/ | |||||
public void maybeConfigure(Project p) throws BuildException { | |||||
String id = null; | |||||
if (attributes != null) { | |||||
PropertyHelper ph=PropertyHelper.getPropertyHelper(p); | |||||
ph.configure(wrappedObject, attributes, p); | |||||
id = attributes.getValue("id"); | |||||
attributes = null; | |||||
} | |||||
if (characters.length() != 0) { | |||||
ProjectHelper.addText(p, wrappedObject, characters.toString()); | |||||
characters.setLength(0); | |||||
} | |||||
Enumeration enum = children.elements(); | |||||
while (enum.hasMoreElements()) { | |||||
RuntimeConfigurable2 child | |||||
= (RuntimeConfigurable2) enum.nextElement(); | |||||
if (child.wrappedObject instanceof Task) { | |||||
Task childTask = (Task) child.wrappedObject; | |||||
childTask.setRuntimeConfigurableWrapper(child); | |||||
childTask.maybeConfigure(); | |||||
} else { | |||||
child.maybeConfigure(p); | |||||
} | |||||
ProjectHelper.storeChild(p, wrappedObject, child.wrappedObject, | |||||
child.getElementTag().toLowerCase(Locale.US)); | |||||
} | |||||
if (id != null) { | |||||
p.addReference(id, wrappedObject); | |||||
} | |||||
} | |||||
} |
@@ -1,191 +0,0 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.types; | |||||
import org.apache.tools.ant.*; | |||||
import java.io.*; | |||||
import java.util.*; | |||||
import org.xml.sax.Locator; | |||||
import org.xml.sax.InputSource; | |||||
//import org.xml.sax.HandlerBase; | |||||
import org.xml.sax.SAXParseException; | |||||
import org.xml.sax.XMLReader; | |||||
import org.xml.sax.SAXException; | |||||
import org.xml.sax.DocumentHandler; | |||||
import org.xml.sax.Attributes; | |||||
import org.xml.sax.AttributeList; | |||||
import org.xml.sax.helpers.XMLReaderAdapter; | |||||
import org.xml.sax.helpers.DefaultHandler; | |||||
import org.xml.sax.helpers.AttributeListImpl; | |||||
import javax.xml.parsers.SAXParserFactory; | |||||
import javax.xml.parsers.SAXParser; | |||||
import javax.xml.parsers.ParserConfigurationException; | |||||
/** | |||||
* Specify a system path, to be used to load optional.jar and all | |||||
* related libraries. | |||||
* | |||||
* Using the specified path it'll try to load or reload all optional | |||||
* tasks. The typical use is: | |||||
* <pre> | |||||
* <path id="ant.deps" > | |||||
* <fileset ... /> | |||||
* </path> | |||||
* | |||||
* <systemPath pathRef="ant.deps" /> | |||||
* | |||||
* <junit ... /> | |||||
* </pre> | |||||
* | |||||
* This requires that ant-sax2.jar is included in ant/lib. | |||||
* | |||||
* It has a single property, a reference to a <path> containing all | |||||
* the jars that you need. It'll automatically reload optional.jar | |||||
* tasks in a different (non-delegating) loader. | |||||
* | |||||
* @author Costin Manolache | |||||
*/ | |||||
public class SystemPath extends DataType { | |||||
public static final String SYSTEM_LOADER_REF="ant.system.loader"; | |||||
public SystemPath() { | |||||
} | |||||
/** Specify which path will be used. | |||||
*/ | |||||
public void setPathRef( Reference pathRef ) throws BuildException { | |||||
Path path=(Path)pathRef.getReferencedObject(project); | |||||
initSystemLoader(path); | |||||
} | |||||
/** Will prepare the class loader to allow dynamic modifications | |||||
* of the classpath. Optional tasks are loaded in a different loader. | |||||
*/ | |||||
private void initSystemLoader(Path path) { | |||||
try { | |||||
if( project.getReference( SYSTEM_LOADER_REF ) != null ) | |||||
return; // already done that. | |||||
// reverse loader | |||||
AntClassLoader acl=new AntClassLoader( this.getClass().getClassLoader(), true ); | |||||
acl.addLoaderPackageRoot( "org.apache.tools.ant.taskdefs.optional"); | |||||
project.addReference( SYSTEM_LOADER_REF, acl ); | |||||
String list[]=path.list(); | |||||
for( int i=0; i<list.length; i++ ) { | |||||
File f= new File( list[i] ); | |||||
if( f.exists() ) { | |||||
acl.addPathElement(f.getAbsolutePath()); | |||||
} | |||||
} | |||||
// XXX find the classpath | |||||
String antHome=project.getProperty( "ant.home" ); | |||||
File optionalJar=new File( antHome + "/lib/optional.jar" ); | |||||
if( optionalJar.exists() ) | |||||
acl.addPathElement(optionalJar.getAbsolutePath() ); | |||||
// reinit the loader for optional, if they were in /lib/ | |||||
Hashtable tasks=project.getTaskDefinitions(); | |||||
//System.out.println("Replacing jars" ); | |||||
// reload all optional tasks in this loader. | |||||
// Some tasks weren't defined by the normal init(), since deps were missing. | |||||
String defs = "/org/apache/tools/ant/taskdefs/defaults.properties"; | |||||
try { | |||||
Properties props = new Properties(); | |||||
InputStream in = this.getClass().getResourceAsStream(defs); | |||||
if (in == null) { | |||||
throw new BuildException("Can't load default task list"); | |||||
} | |||||
props.load(in); | |||||
in.close(); | |||||
Enumeration enum = props.propertyNames(); | |||||
while (enum.hasMoreElements()) { | |||||
String key = (String) enum.nextElement(); | |||||
String value = props.getProperty(key); | |||||
if( ! value.startsWith( "org.apache.tools.ant.taskdefs.optional" )) | |||||
continue; | |||||
// other classes that needs to be replaced ?? | |||||
try { | |||||
Class taskClass = acl.loadClass(value); | |||||
project.addTaskDefinition(key, taskClass); | |||||
//System.out.println("Loaded " + key + " " + taskClass.getClassLoader() ); | |||||
} catch (NoClassDefFoundError ncdfe) { | |||||
log("Could not load a dependent class (" | |||||
+ ncdfe.getMessage() + ") for task " + key, Project.MSG_DEBUG); | |||||
} catch (ClassNotFoundException cnfe) { | |||||
log("Could not load class (" + value | |||||
+ ") for task " + key, Project.MSG_DEBUG); | |||||
} catch (Exception ex) { | |||||
ex.printStackTrace(); | |||||
} | |||||
} | |||||
} catch (IOException ioe) { | |||||
throw new BuildException("Can't load default task list"); | |||||
} | |||||
} catch( Exception ex ) { | |||||
ex.printStackTrace(); | |||||
} | |||||
} | |||||
} |
@@ -1,61 +0,0 @@ | |||||
<project name="helper2" default="main" > | |||||
<property name="ant.src" location="../../.." /> | |||||
<property name="ant.build" location="${ant.src}/build" /> | |||||
<property name="debug" value="true"/> | |||||
<target name="main"> | |||||
<copy file="ProjectHelperImpl2.java" | |||||
todir="${ant.src}/src/main/org/apache/tools/ant/helper" /> | |||||
<copy file="RuntimeConfigurable2.java" | |||||
todir="${ant.src}/src/main/org/apache/tools/ant" /> | |||||
<copy file="RuntimeConfigurable2.java" | |||||
todir="${ant.src}/src/main/org/apache/tools/ant" /> | |||||
<copy file="Import.java" | |||||
todir="${ant.src}/src/main/org/apache/tools/ant/tasks" /> | |||||
<copy file="RuntimeConfigurable2.java" | |||||
todir="${ant.src}/src/main/org/apache/tools/ant" /> | |||||
<copy file="PropertyInterceptor.java" | |||||
todir="${ant.src}/src/main/org/apache/tools/ant" /> | |||||
<copy file="SystemPath.java" | |||||
todir="${ant.src}/src/main/org/apache/tools/ant/types" /> | |||||
<copy id="test" file="PropertyHelper.java" | |||||
todir="${ant.src}/src/main/org/apache/tools/ant" /> | |||||
<echo message="${toString:test}" /> | |||||
<javac srcdir="${ant.src}/src" | |||||
debug="${debug}" | |||||
destdir="${ant.build}/classes" > | |||||
<classpath location="${ant.build}/classes" /> | |||||
<include name="**/ProjectHelperImpl2.java" /> | |||||
<include name="**/PropertyHelper.java" /> | |||||
<include name="**/PropertyInterceptor.java" /> | |||||
<include name="**/RuntimeConfigurable2.java" /> | |||||
<include name="**/Import.java" /> | |||||
<include name="**/SystemPath.java" /> | |||||
</javac> | |||||
<mkdir dir="${ant.build}/classes/META-INF/services" /> | |||||
<copy file="org.apache.tools.ant.ProjectHelper" | |||||
tofile="${ant.build}/classes/META-INF/services/org.apache.tools.ant.ProjectHelper" /> | |||||
<jar file="ant-sax2.jar" basedir="${ant.build}/classes" > | |||||
<include name="META-INF/**" /> | |||||
<include name="org/apache/tools/ant/helper/ProjectHelperImpl2*" /> | |||||
<include name="org/apache/tools/ant/RuntimeConfigurable2*" /> | |||||
<include name="org/apache/tools/ant/PropertyHelper*" /> | |||||
<include name="org/apache/tools/ant/PropertyInterceptor*" /> | |||||
<include name="org/apache/tools/ant/types/SystemPath*" /> | |||||
<include name="org/apache/tools/ant/tasks/Import*" /> | |||||
</jar> | |||||
<copy file="ant-sax2.jar" todir="${ant.home}/lib" /> | |||||
</target> | |||||
<target name="clean"> | |||||
<delete file="${ant.src}/src/main/org/apache/tools/ant/RuntimeConfigurable2.java" /> | |||||
<delete file="${ant.src}/src/main/org/apache/tools/ant/helper/ProjectHelperImpl2.java" /> | |||||
</target> | |||||
</project> |
@@ -1 +0,0 @@ | |||||
org.apache.tools.ant.helper.ProjectHelperImpl2 |