Aslak and others - here is the commit message from ant-dev for the patch I
just applied, test case and all.
Have a look at the build file below to see the example from the top-down.
Essentially all you have to do is implement DynamicConfigurator with its two
setDynamicAttrribute and createDynamicElement methods. If we need to make a
helper base class that provides null implementations then no problem.
All your dynamic subtask lookup would happen in createDynamicElement. Let
me know ASAP how this works for you - I would highly encourage someone to
give it a shot within the next day or so in case any changes are needed to
satisfy your use-case.
Erik
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, April 27, 2002 8:51 AM
Subject: cvs commit: jakarta-ant/src/etc/testcases/taskdefs dynamictask.xml
> ehatcher 02/04/27 05:51:03
>
> Modified: src/main/org/apache/tools/ant IntrospectionHelper.java
> Added: src/main/org/apache/tools/ant DynamicConfigurator.java
> src/testcases/org/apache/tools/ant/taskdefs
DynamicTask.java
> DynamicTest.java
> src/etc/testcases/taskdefs dynamictask.xml
> Log:
> DynamicConfigurator - allows tasks themselves to handle unknown elements
and attributes rather than being constrained by the IntrospectionHelper
rules.
>
> Revision Changes Path
> 1.41 +23 -8
jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
>
> Index: IntrospectionHelper.java
> ===================================================================
> RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
,v
> retrieving revision 1.40
> retrieving revision 1.41
> diff -u -r1.40 -r1.41
> --- IntrospectionHelper.java 12 Apr 2002 14:46:44 -0000 1.40
> +++ IntrospectionHelper.java 27 Apr 2002 12:51:02 -0000 1.41
> @@ -54,6 +54,7 @@
>
> package org.apache.tools.ant;
>
> +import org.apache.tools.ant.DynamicConfigurator;
> import org.apache.tools.ant.types.Path;
> import org.apache.tools.ant.types.EnumeratedAttribute;
>
> @@ -405,15 +406,19 @@
> * method fails.
> */
> public void setAttribute(Project p, Object element, String
attributeName,
> - String value)
> - throws BuildException {
> - AttributeSetter as
> - = (AttributeSetter) attributeSetters.get(attributeName);
> + String value) throws BuildException {
> + AttributeSetter as = (AttributeSetter)
attributeSetters.get(attributeName);
> if (as == null) {
> - String msg = p.getElementName(element) +
> - //String msg = "Class " + element.getClass().getName() +
> - " doesn't support the \"" + attributeName + "\"
attribute.";
> - throw new BuildException(msg);
> + if (element instanceof DynamicConfigurator) {
> + DynamicConfigurator dc = (DynamicConfigurator) element;
> + dc.setDynamicAttribute(attributeName, value);
> + return;
> + }
> + else {
> + String msg = getElementName(p, element) +
> + " doesn't support the \"" + attributeName + "\"
attribute.";
> + throw new BuildException(msg);
> + }
> }
> try {
> as.set(p, element, value);
> @@ -498,6 +503,16 @@
> public Object createElement(Project project, Object parent,
> String elementName) throws BuildException {
> NestedCreator nc = (NestedCreator)
nestedCreators.get(elementName);
> + if (nc == null && parent instanceof DynamicConfigurator) {
> + DynamicConfigurator dc = (DynamicConfigurator) parent;
> + Object nestedElement =
dc.createDynamicElement(elementName);
> + if (nestedElement != null) {
> + if (nestedElement instanceof ProjectComponent) {
> + ((ProjectComponent)
nestedElement).setProject(project);
> + }
> + return nestedElement;
> + }
> + }
> if (nc == null) {
> String msg = project.getElementName(parent) +
> " doesn't support the nested \"" + elementName + "\"
element.";
>
>
>
> 1.1
jakarta-ant/src/main/org/apache/tools/ant/DynamicConfigurator.java
>
> Index: DynamicConfigurator.java
> ===================================================================
> /*
> * The Apache Software License, Version 1.1
> *
> * Copyright (c) 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 [EMAIL PROTECTED]
> *
> * 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;
>
> /**
> * Enables a task to control unknown attributes and elements.
> *
> * @author Erik Hatcher
> * @since Ant 1.5
> */
> public interface DynamicConfigurator {
> public void setDynamicAttribute(String name, String value);
>
> public Object createDynamicElement(String name);
> }
>
>
>
> 1.1
jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/DynamicTask.java
>
> Index: DynamicTask.java
> ===================================================================
> /*
> * The Apache Software License, Version 1.1
> *
> * Copyright (c) 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 [EMAIL PROTECTED]
> *
> * 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.taskdefs;
>
> import org.apache.tools.ant.DynamicConfigurator;
> import org.apache.tools.ant.Task;
>
> public class DynamicTask extends Task implements DynamicConfigurator {
>
> public void execute() {
> }
>
> public void setDynamicAttribute(String name, String value) {
> project.setNewProperty(name, value);
> }
>
> public Object createDynamicElement(String name) {
> return new Sub();
> }
>
> public class Sub implements DynamicConfigurator {
> public void setDynamicAttribute(String name, String value) {
> project.setNewProperty(name, value);
> }
>
> public Object createDynamicElement(String name) {
> return null;
> }
> }
> }
>
>
>
> 1.1
jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/DynamicTest.java
>
> Index: DynamicTest.java
> ===================================================================
> /*
> * The Apache Software License, Version 1.1
> *
> * Copyright (c) 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 [EMAIL PROTECTED]
> *
> * 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.taskdefs;
>
> import org.apache.tools.ant.BuildFileTest;
>
> public class DynamicTest extends BuildFileTest {
>
> public DynamicTest(String name) {
> super(name);
> }
>
> public void setUp() {
> configureProject("src/etc/testcases/taskdefs/dynamictask.xml");
> }
>
> public void testSimple() {
> executeTarget("simple");
> assertEquals("1", project.getProperty("prop1"));
> assertEquals("2", project.getProperty("prop2"));
> assertEquals("3", project.getProperty("prop3"));
> assertEquals("4", project.getProperty("prop4"));
> }
> }
>
>
>
> 1.1
jakarta-ant/src/etc/testcases/taskdefs/dynamictask.xml
>
> Index: dynamictask.xml
> ===================================================================
> <?xml version="1.0"?>
>
> <project name="dynamic-test" default="simple">
>
> <path id="testclasses">
> <pathelement location="../../../../build/testcases" />
> <pathelement path="${java.class.path}" />
> </path>
>
> <target name="simple">
> <taskdef name="dyna"
> classname="org.apache.tools.ant.taskdefs.DynamicTask">
> <classpath refid="testclasses" />
> </taskdef>
> <dyna prop1="1" prop2="2">
> <sub prop3="3"/>
> <anything prop4="4"/>
> </dyna>
> </target>
>
> </project>
>
>
>
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel