Hi, Here is the patch I mentioned in my previous e-mail. It defines a new interface called DeclaringTask which must be implemented by those tasks that should be allowed outside targets. As the name indicates, such tasks should be limited to those use for declaring things like <property>, <taskdef>, <typedef>. These are the only three allowed by this patch.
We can discuse later if there are any other tasks that should also be DeclaringTasks. The thing I like is that removes one and for all the hardcoded task names from ProjectHelper. Cheers, Jose Alberto
BEGIN:VCARD VERSION:2.1 N:Fernandez;Jose;Alberto FN:Jose Alberto Fernandez TEL;HOME;VOICE:+44.20.8805.0809 TEL;CELL;VOICE:+44.77.4767.3468 TEL;HOME;FAX:+44.20.8805.0809 ADR;HOME;ENCODING=QUOTED-PRINTABLE:;;2 Caroe Court=0D=0A1 Bury Street;London;;N9 7LE;UK LABEL;HOME;ENCODING=QUOTED-PRINTABLE:2 Caroe Court=0D=0A1 Bury Street=0D=0ALondon N9 7LE=0D=0AUK X-WAB-GENDER:2 URL:www.geocities.com/j_a_fernandez BDAY:19600811 EMAIL;PREF;INTERNET:[EMAIL PROTECTED] REV:20011013T012328Z END:VCARD
Index: src/main/org/apache/tools/ant/DeclaringTask.java =================================================================== RCS file: DeclaringTask.java diff -N DeclaringTask.java --- /dev/null Fri Oct 12 18:04:29 2001 +++ DeclaringTask.java Fri Oct 12 18:06:11 2001 @@ -0,0 +1,67 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 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; + +/** + * Interface for tasks that perform a declaration of some sort. + * DeclaringTasks are the only ones that can be located outside targets. + * <p> + * <code>property, taskdef</code> and <code>typedef</code> are examples + * of such tasks. + * @author <a href="mailto:[EMAIL PROTECTED]">Jose Alberto Fernandez</a> + */ +public interface DeclaringTask { +} + Index: src/main/org/apache/tools/ant/ProjectHelper.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v retrieving revision 1.62 diff -u -r1.62 ProjectHelper.java --- src/main/org/apache/tools/ant/ProjectHelper.java 2001/09/30 13:21:53 1.62 +++ src/main/org/apache/tools/ant/ProjectHelper.java 2001/10/13 01:06:16 @@ -334,24 +334,21 @@ } public void startElement(String name, AttributeList attrs) throws SAXParseException { - if (name.equals("taskdef")) { - handleTaskdef(name, attrs); - } else if (name.equals("property")) { - handleProperty(name, attrs); - } else if (name.equals("target")) { + Object cls = null; + + if (name.equals("target")) { handleTarget(name, attrs); + } else if ((cls = project.getTaskDefinitions().get(name)) != null + && DeclaringTask.class.isAssignableFrom((Class)cls)) { + handleDeclaringTask(name, attrs); } else if (project.getDataTypeDefinitions().get(name) != null) { handleDataType(name, attrs); } else { throw new SAXParseException("Unexpected element \"" + name + "\"", locator); } } - - private void handleTaskdef(String name, AttributeList attrs) throws SAXParseException { - (new TaskHandler(this, null, null)).init(name, attrs); - } - private void handleProperty(String name, AttributeList attrs) throws SAXParseException { + private void handleDeclaringTask(String name, AttributeList attrs) throws SAXParseException { (new TaskHandler(this, null, null)).init(name, attrs); } Index: src/main/org/apache/tools/ant/taskdefs/Definer.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v retrieving revision 1.7 diff -u -r1.7 Definer.java --- src/main/org/apache/tools/ant/taskdefs/Definer.java 2001/08/06 09:59:51 1.7 +++ src/main/org/apache/tools/ant/taskdefs/Definer.java 2001/10/13 01:06:17 @@ -67,7 +67,7 @@ * @author Costin Manolache * @author <a href="[EMAIL PROTECTED]">Stefan Bodewig</a> */ -public abstract class Definer extends Task { +public abstract class Definer extends Task implements DeclaringTask { private String name; private String value; private Path classpath; Index: src/main/org/apache/tools/ant/taskdefs/Property.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v retrieving revision 1.32 diff -u -r1.32 Property.java --- src/main/org/apache/tools/ant/taskdefs/Property.java 2001/08/30 13:26:37 1.32 +++ src/main/org/apache/tools/ant/taskdefs/Property.java 2001/10/13 01:06:19 @@ -68,7 +68,7 @@ * @author Sam Ruby <[EMAIL PROTECTED]> * @author Glenn McAllister <[EMAIL PROTECTED]> */ -public class Property extends Task { +public class Property extends Task implements DeclaringTask { protected String name; protected String value;
