Return-Path: X-Original-To: apmail-ant-notifications-archive@minotaur.apache.org Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 11F41F787 for ; Sun, 5 May 2013 23:50:15 +0000 (UTC) Received: (qmail 8814 invoked by uid 500); 5 May 2013 23:50:14 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 8730 invoked by uid 500); 5 May 2013 23:50:14 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 8723 invoked by uid 99); 5 May 2013 23:50:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 May 2013 23:50:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 May 2013 23:50:11 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id ED57D238889B for ; Sun, 5 May 2013 23:49:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1479422 - in /ant/core/trunk: ./ manual/ manual/Types/ src/etc/checkstyle/ src/main/org/apache/tools/ant/ src/main/org/apache/tools/ant/attribute/ src/main/org/apache/tools/ant/taskdefs/ src/tests/antunit/core/ Date: Sun, 05 May 2013 23:49:49 -0000 To: notifications@ant.apache.org From: antoine@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130505234950.ED57D238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: antoine Date: Sun May 5 23:49:49 2013 New Revision: 1479422 URL: http://svn.apache.org/r1479422 Log: adding if and unless namespaces allowing to put conditions on all tasks and nested elements. Code written by Peter Reilly. Bugzilla PR 43362. Added: ant/core/trunk/manual/ifunless.html - copied, changed from r1479367, ant/core/trunk/manual/targets.html ant/core/trunk/src/main/org/apache/tools/ant/DefaultDefinitions.java (with props) ant/core/trunk/src/main/org/apache/tools/ant/attribute/ ant/core/trunk/src/main/org/apache/tools/ant/attribute/AttributeNamespace.java (with props) ant/core/trunk/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java (with props) ant/core/trunk/src/main/org/apache/tools/ant/attribute/EnableAttribute.java (with props) ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfBlankAttribute.java (with props) ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfSetAttribute.java (with props) ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfTrueAttribute.java (with props) ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AttributeNamespaceDef.java (with props) ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml (with props) Modified: ant/core/trunk/WHATSNEW ant/core/trunk/manual/Types/namespace.html ant/core/trunk/manual/conceptstypeslist.html ant/core/trunk/src/etc/checkstyle/checkstyle-config ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Sun May 5 23:49:49 2013 @@ -29,6 +29,9 @@ Other changes: * simplifying Execute.getEnvironmentVariables since we are only running on Java 1.5 or higher now + * Add conditional attributes + Bugzilla report 43362 + Changes from Ant 1.8.4 TO Ant 1.9.0 =================================== Modified: ant/core/trunk/manual/Types/namespace.html URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/Types/namespace.html?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/manual/Types/namespace.html (original) +++ ant/core/trunk/manual/Types/namespace.html Sun May 5 23:49:49 2013 @@ -152,6 +152,10 @@

+ In Ant 1.9.1 two attribute namespaces ant:if and ant:unless are added in order to allow to insert elements + conditionally +

+

Other attributes are simply ignored.

Modified: ant/core/trunk/manual/conceptstypeslist.html URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/conceptstypeslist.html?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/manual/conceptstypeslist.html (original) +++ ant/core/trunk/manual/conceptstypeslist.html Sun May 5 23:49:49 2013 @@ -35,6 +35,7 @@

  • build.sysclasspath
  • Ant properties controlling javac
  • Common Attributes
  • +
  • If and Unless Attributes
  • List of Types

    Copied: ant/core/trunk/manual/ifunless.html (from r1479367, ant/core/trunk/manual/targets.html) URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/ifunless.html?p2=ant/core/trunk/manual/ifunless.html&p1=ant/core/trunk/manual/targets.html&r1=1479367&r2=1479422&rev=1479422&view=diff ============================================================================== --- ant/core/trunk/manual/targets.html (original) +++ ant/core/trunk/manual/ifunless.html Sun May 5 23:49:49 2013 @@ -19,282 +19,46 @@ - Targets and Extension-Points + If and Unless on all tasks/nested elements -

    Targets

    +

    If And Unless

    -

    A target is a container of tasks that cooperate to reach a - desired state during the build process.

    +

    Since Ant 1.9.1 it is possible to add if and unless attributes on all tasks and nested elements using special namespaces.

    -

    Targets can depend on other targets and Apache Ant ensures that these - other targets have been executed before the current target. For - example you might have a target for compiling and a - target for creating a distributable. You can only build a - distributable when you have compiled first, so the distribute - target depends on the compile target.

    - -

    Ant tries to execute the targets in the depends - attribute in the order they appear (from left to right). Keep in - mind that it is possible that a target can get executed earlier - when an earlier target depends on it:

    +

    In order to use this feature you need to add the following namespace declarations

    +
    +    xmlns:if="ant:if"
    +    xmlns:unless="ant:unless"
    +    
    +
    + +

    The if and unless namespaces support the following 3 conditions : +

      +
    • true
    • true if the value of the property evaluates to true +
    • blank
    • true if the value of the property is null or empty +
    • set
    • true if the property is set +

    -
    <target name="A"/>
    -<target name="B" depends="A"/>
    -<target name="C" depends="B"/>
    -<target name="D" depends="C,B,A"/>
    +
    +<project name="tryit"
    + xmlns:if="ant:if"
    + xmlns:unless="ant:unless"
    +>
    + <exec executable="java">
    +   <arg line="-X" if:true="showextendedparams"/>
    +   <arg line="-version" unless:true="showextendedparams"/>
    + </exec>
    + <condition property="onmac">
    +   <os family="mac"/>
    + </condition>
    + <echo if:set="onmac">running on MacOS</echo>
    + <echo unless:set="onmac">not running on MacOS</echo>
    +</project>
    +
    -

    Suppose we want to execute target D. From its - depends attribute, you might think that first target - C, then B and then A is executed. Wrong! C depends on B, and B - depends on A, so first A is executed, then B, then C, and finally - D.

    - -
    Call-Graph:  A --> B --> C --> D
    - -

    In a chain of dependencies stretching back from a given target - such as D above, each target gets executed only once, even when - more than one target depends on it. Thus, executing the D target - will first result in C being called, which in turn will first call - B, which in turn will first call A. After A, then B, then C have - executed, execution returns to the dependency list of D, which - will not call B and A, since they were already called in - process of dependency resolution for C and B respectively as - dependencies of D. Had no such dependencies been discovered in - processing C and B, B and A would have been executed after C in - processing D's dependency list.

    - -

    A target also has the ability to perform its execution if (or - unless) a property has been set. This allows, for example, better - control on the building process depending on the state of the - system (java version, OS, command-line property defines, etc.). - To make a target sense this property, you should add - the if (or unless) attribute with the - name of the property that the target should react - to. Note: In the most simple case Ant will only - check whether the property has been set, the value doesn't matter, - but using property expansions you can build more complex - conditions. See - the properties page for - more details. For example:

    - -
    -
    <target name="build-module-A" if="module-A-present"/>
    -
    <target name="build-own-fake-module-A" unless="module-A-present"/>
    -
    - -

    In the first example, if the module-A-present - property is set (to any value, e.g. false), the target will - be run. In the second example, if - the module-A-present property is set (again, to any - value), the target will not be run.

    - -

    Only one propertyname can be specified in the if/unless - clause. If you want to check multiple conditions, you can use a - dependend target for computing the result for the check:

    - -
    -<target name="myTarget" depends="myTarget.check" if="myTarget.run">
    -    <echo>Files foo.txt and bar.txt are present.</echo>
    -</target>
    -
    -<target name="myTarget.check">
    -    <condition property="myTarget.run">
    -        <and>
    -            <available file="foo.txt"/>
    -            <available file="bar.txt"/>
    -        </and>
    -    </condition>
    -</target>
    -
    - -
    Call-Graph:  myTarget.check --> maybe(myTarget)
    - -

    If no if and no unless attribute is - present, the target will always be executed.

    - -

    Important: the if and unless - attributes only enable or disable the target to which they are - attached. They do not control whether or not targets that a - conditional target depends upon get executed. In fact, they do - not even get evaluated until the target is about to be executed, - and all its predecessors have already run. - -

    The optional description attribute can be used to - provide a one-line description of this target, which is printed by - the -projecthelp command-line option. Targets without - such a description are deemed internal and will not be listed, - unless either the -verbose or -debug - option is used.

    - -

    It is a good practice to place - your tstamp tasks in a - so-called initialization target, on which all other targets - depend. Make sure that target is always the first one in the - depends list of the other targets. In this manual, most - initialization targets have the name "init".

    -
    -    <project>
    -        <target name="init">
    -            <tstamp/>
    -        </target>
    -        <target name="otherTarget" depends="init">
    -            ...
    -        </target>
    -    </project>
    -    
    - -

    Especially if you only have a few tasks you also could place these - tasks directly under the project tag (since Ant 1.6.0):

    -
    -    <project>
    -        <tstamp/>
    -    </project>
    -    
    - -

    If the depends attribute and the if/unless attribute are set, the - depends attribute is executed first.

    - -

    A target has the following attributes:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    AttributeDescriptionRequired
    namethe name of the target.Yes
    dependsa comma-separated list of names of targets on - which this target depends.No
    ifthe name of the property that must be set in - order for this target to execute, - or something evaluating to - true.No
    unlessthe name of the property that must not be set - in order for this target to execute, - or something evaluating to - false.No
    descriptiona short description of this target's function.No
    extensionOfAdds the current target to the depends list of - the named extension-point. - since Ant 1.8.0.No
    onMissingExtensionPointWhat to do if this target tries to extend a - missing - extension-point. ("fail", - "warn", "ignore"). - since Ant 1.8.2.No. Not allowed unless - extensionOf is present. Defaults to fail. -
    - -

    A target name can be any alphanumeric string valid in the - encoding of the XML file. The empty string "" is in this - set, as is comma "," and space " ". Please - avoid using these, as they will not be supported in future Ant - versions because of all the confusion they cause on command line and IDE. IDE support of - unusual target names, or any target name containing spaces, varies - with the IDE.

    - -

    Targets beginning with a hyphen such - as "-restart" are valid, and can be used to - name targets that should not be called directly from the command - line.
    - For Ants main class every option starting with hyphen is an - option for Ant itself and not a target. For that reason calling these - target from command line is not possible. On the other hand IDEs usually - don't use Ants main class as entry point and calling them from the IDE - is usually possible.

    - -

    Extension-Points

    - -

    since Ant 1.8.0.

    - -

    Extension-Points are similar to targets in that they have a name and - a depends list and can be executed from the command line. Just - like targets they represent a state during the build process.

    - -

    Unlike targets they don't contain any tasks, their main purpose - is to collect targets that contribute to the desired state in - their depends list.

    - -

    Targets can add themselves to an extension-points's depends list via - their extensionOf attribute. The targets that add themselves will be - added after the targets of the explicit depends-attribute of the - extension-point, if multiple targets add themselves, their relative - order is not defined.

    - -

    The main purpose of an extension-point is to act as an extension - point for build files designed to - be imported. In the imported - file an extension-point defines a state that must be reached and - targets from other build files can join the depends list of said - extension-point in order to contribute to that state.

    - -

    For example your imported build file may need to compile code, it - might look like:

    -
    -<target name="create-directory-layout">
    -   ...
    -</target>
    -<extension-point name="ready-to-compile"
    -              depends="create-directory-layout"/>
    -<target name="compile" depends="ready-to-compile">
    -   ...
    -</target>
    -
    - -
    Call-Graph:  create-directory-layout --> 'empty slot' --> compile
    - - -

    And you need to generate some source before compilation, then in - your main build file you may use something like

    -
    -<target name="generate-sources"
    -        extensionOf="ready-to-compile">
    -   ...
    -</target>
    -
    - -
    Call-Graph:  create-directory-layout --> generate-sources  --> compile
    - - -

    This will ensure that the generate-sources target is - executed before the compile target.

    - -

    Don't rely on the order of the depends list, - if generate-sources depends - on create-directory-layout then it must explicitly depend - on it via its own depends attribute.

    Modified: ant/core/trunk/src/etc/checkstyle/checkstyle-config URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/checkstyle/checkstyle-config?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/src/etc/checkstyle/checkstyle-config (original) +++ ant/core/trunk/src/etc/checkstyle/checkstyle-config Sun May 5 23:49:49 2013 @@ -96,8 +96,8 @@ - - + + Modified: ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java Sun May 5 23:49:49 2013 @@ -316,6 +316,7 @@ public class ComponentHelper { public void initDefaultDefinitions() { initTasks(); initTypes(); + new DefaultDefinitions(this).execute(); } /** Added: ant/core/trunk/src/main/org/apache/tools/ant/DefaultDefinitions.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DefaultDefinitions.java?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/DefaultDefinitions.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/DefaultDefinitions.java Sun May 5 23:49:49 2013 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant; + +/** + * Default definitions. + */ +public final class DefaultDefinitions { + private static final String IF_NAMESPACE = "ant:if"; + private static final String UNLESS_NAMESPACE = "ant:unless"; + private static final String OATA = "org.apache.tools.ant."; + + private final ComponentHelper componentHelper; + + /** + * Create a default definitions object. + * @param componentHelper the componenthelper to initialize. + */ + public DefaultDefinitions(ComponentHelper componentHelper) { + this.componentHelper = componentHelper; + } + + /** + * Register the defintions. + */ + public void execute() { + attributeNamespaceDef(IF_NAMESPACE); + attributeNamespaceDef(UNLESS_NAMESPACE); + + ifUnlessDef("true", "IfTrueAttribute"); + ifUnlessDef("set", "IfSetAttribute"); + ifUnlessDef("blank", "IfBlankAttribute"); + } + + private void attributeNamespaceDef(String ns) { + AntTypeDefinition def = new AntTypeDefinition(); + def.setName(ProjectHelper.nsToComponentName(ns)); + def.setClassName(OATA + "attribute.AttributeNamespace"); + def.setClassLoader(getClass().getClassLoader()); + def.setRestrict(true); + componentHelper.addDataTypeDefinition(def); + } + + private void ifUnlessDef(String name, String base) { + String classname = OATA + "attribute." + base; + componentDef(IF_NAMESPACE, name, classname); + componentDef(UNLESS_NAMESPACE, name, classname + "$Unless"); + } + + private void componentDef(String ns, String name, String classname) { + AntTypeDefinition def = new AntTypeDefinition(); + String n = ProjectHelper.genComponentName(ns, name); + def.setName(ProjectHelper.genComponentName(ns, name)); + def.setClassName(classname); + def.setClassLoader(getClass().getClassLoader()); + def.setRestrict(true); + componentHelper.addDataTypeDefinition(def); + } +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/DefaultDefinitions.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java Sun May 5 23:49:49 2013 @@ -276,5 +276,9 @@ public final class MagicNames { * @since Ant 1.9.0 */ public static final String ANT_VM_LAUNCHER_REF_ID = "ant.vmLauncher"; + /** Name of the namespace "type" (note: cannot be used as an element) + * @since Ant 1.9.1 + * */ + public static final String ATTRIBUTE_NAMESPACE = "attribute namespace"; } Modified: ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/ProjectHelper.java Sun May 5 23:49:49 2013 @@ -43,6 +43,11 @@ public class ProjectHelper { /** The URI for antlib current definitions */ public static final String ANT_CURRENT_URI = "ant:current"; + /** The URI for ant specific attributes + * @since Ant 1.9.1 + * */ + public static final String ANT_ATTRIBUTE_URI = "ant:attribute"; + /** The URI for defined types/tasks - the format is antlib: */ public static final String ANTLIB_URI = "antlib:"; @@ -523,6 +528,16 @@ public class ProjectHelper { } /** + * Convert an attribute namespace to a "component name". + * @param ns the xml namespace uri. + * @return the converted value. + * @since Ant 1.9.1 + */ + public static String nsToComponentName(String ns) { + return "attribute namespace:" + ns; + } + + /** * Add location to build exception. * @param ex the build exception, if the build exception * does not include Modified: ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/RuntimeConfigurable.java Sun May 5 23:49:49 2013 @@ -27,6 +27,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map.Entry; +import org.apache.tools.ant.attribute.EnableAttribute; + import org.apache.tools.ant.util.CollectionUtils; import org.apache.tools.ant.taskdefs.MacroDef.Attribute; import org.apache.tools.ant.taskdefs.MacroInstance; @@ -64,6 +66,9 @@ public class RuntimeConfigurable impleme */ private transient AttributeList attributes; + // The following is set to true if any of the attributes are namespaced + private transient boolean namespacedAttribute = false; + /** Attribute names and values. While the XML spec doesn't require * preserving the order ( AFAIK ), some ant tests do rely on the * exact order. @@ -113,6 +118,73 @@ public class RuntimeConfigurable impleme proxyConfigured = false; } + private static class EnableAttributeConsumer { + public void add(EnableAttribute b) { + // Ignore + } + } + + /** + * Check if an UE is enabled. + * This looks tru the attributes and checks if there + * are any Ant attributes, and if so, the method calls the + * isEnabled() method on them. + * @param owner the UE that owns this RC. + * @return true if enabled, false if any of the ant attribures return + * false. + */ + public boolean isEnabled(UnknownElement owner) { + if (!namespacedAttribute) { + return true; + } + ComponentHelper componentHelper = ComponentHelper + .getComponentHelper(owner.getProject()); + + IntrospectionHelper ih + = IntrospectionHelper.getHelper( + owner.getProject(), EnableAttributeConsumer.class); + for (int i = 0; i < attributeMap.keySet().size(); ++i) { + String name = (String) attributeMap.keySet().toArray()[i]; + if (name.indexOf(':') == -1) { + continue; + } + String componentName = attrToComponent(name); + String ns = ProjectHelper.extractUriFromComponentName(componentName); + if (componentHelper.getRestrictedDefinitions( + ProjectHelper.nsToComponentName(ns)) == null) { + continue; + } + + String value = (String) attributeMap.get(name); + + EnableAttribute enable = null; + try { + enable = (EnableAttribute) + ih.createElement( + owner.getProject(), new EnableAttributeConsumer(), + componentName); + } catch (BuildException ex) { + throw new BuildException( + "Unsupported attribute " + componentName); + } + if (enable == null) { + continue; + } + value = owner.getProject().replaceProperties(value); // FixMe: need to make config + if (!enable.isEnabled(owner, value)) { + return false; + } + } + return true; + } + + private String attrToComponent(String a) { + // need to remove the prefix + int p1 = a.lastIndexOf(':'); + int p2 = a.lastIndexOf(':', p1 - 1); + return a.substring(0, p2) + a.substring(p1); + } + /** * Sets the creator of the element to be configured * used to store the element in the parent. @@ -177,6 +249,9 @@ public class RuntimeConfigurable impleme * @param value the attribute's value. */ public synchronized void setAttribute(String name, String value) { + if (name.indexOf(':') != -1) { + namespacedAttribute = true; + } setAttribute(name, (Object) value); } Modified: ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java Sun May 5 23:49:49 2013 @@ -170,6 +170,9 @@ public class UnknownElement extends Task * */ public void configure(Object realObject) { + if (realObject == null) { + return; + } realThing = realObject; getWrapper().setProxy(realThing); @@ -281,10 +284,8 @@ public class UnknownElement extends Task */ public void execute() { if (realThing == null) { - // plain impossible to get here, maybeConfigure should - // have thrown an exception. - throw new BuildException("Could not create task of type: " - + elementName, getLocation()); + // Got here if the runtimeconfigurable is not enabled. + return; } try { if (realThing instanceof Task) { @@ -346,6 +347,14 @@ public class UnknownElement extends Task RuntimeConfigurable childWrapper = parentWrapper.getChild(i); UnknownElement child = it.next(); try { + if (!childWrapper.isEnabled(child)) { + if (ih.supportsNestedElement( + parentUri, ProjectHelper.genComponentName( + child.getNamespace(), child.getTag()))) { + continue; + } + // fall tru and fail in handlechild (unsupported element) + } if (!handleChild( parentUri, ih, parent, child, childWrapper)) { if (!(parent instanceof TaskContainer)) { @@ -411,6 +420,9 @@ public class UnknownElement extends Task * @return the task or data type represented by the given unknown element. */ protected Object makeObject(UnknownElement ue, RuntimeConfigurable w) { + if (!w.isEnabled(ue)) { + return null; + } ComponentHelper helper = ComponentHelper.getComponentHelper( getProject()); String name = ue.getComponentName(); Added: ant/core/trunk/src/main/org/apache/tools/ant/attribute/AttributeNamespace.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/attribute/AttributeNamespace.java?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/attribute/AttributeNamespace.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/attribute/AttributeNamespace.java Sun May 5 23:49:49 2013 @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.attribute; + +/** + * This class is used to indicate that the xml namespace (uri) + * can be used to look for namespace attributes. + */ +public final class AttributeNamespace { +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/attribute/AttributeNamespace.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/core/trunk/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java Sun May 5 23:49:49 2013 @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.attribute; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.tools.ant.ProjectComponent; +import org.apache.tools.ant.RuntimeConfigurable; +import org.apache.tools.ant.UnknownElement; + + +/** + * An abstract class for if/unless attributes. + * This contains a boolean flag to specify whether this is an + * if or unless attribute. + */ +public abstract class BaseIfAttribute + extends ProjectComponent implements EnableAttribute { + private boolean positive = true; + /** + * Set the positive flag. + * @param positive the value to use. + */ + protected void setPositive(boolean positive) { + this.positive = positive; + } + + /** + * Get the positive flag. + * @return the flag. + */ + protected boolean isPositive() { + return positive; + } + + /** + * convert the result. + * @param val the result to convert + * @return val if positive or !val if not. + */ + protected boolean convertResult(boolean val) { + return positive ? val : !val; + } + + /** + * Get all the attributes in the ant-attribute:param + * namespace and place them in a map. + * @param el the element this attribute is in. + * @return a map of attributes. + */ + protected Map getParams(UnknownElement el) { + Map ret = new HashMap(); + RuntimeConfigurable rc = el.getWrapper(); + Map attributes = rc.getAttributeMap(); // This does a copy! + for (Iterator i = attributes.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + String key = (String) entry.getKey(); + String value = (String) entry.getValue(); + if (key.startsWith("ant-attribute:param")) { + int pos = key.lastIndexOf(':'); + ret.put(key.substring(pos + 1), + el.getProject().replaceProperties(value)); + } + } + return ret; + } +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/core/trunk/src/main/org/apache/tools/ant/attribute/EnableAttribute.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/attribute/EnableAttribute.java?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/attribute/EnableAttribute.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/attribute/EnableAttribute.java Sun May 5 23:49:49 2013 @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.attribute; + +import org.apache.tools.ant.UnknownElement; + +/** + * This interface is used by ant attributes. + */ +public interface EnableAttribute { + /** + * is enabled. + * @param el the unknown element this attribute is in. + * @param value the value of the attribute. + * @return true if the attribute enables the element, false otherwise. + */ + boolean isEnabled(UnknownElement el, String value); +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/attribute/EnableAttribute.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfBlankAttribute.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfBlankAttribute.java?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfBlankAttribute.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfBlankAttribute.java Sun May 5 23:49:49 2013 @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.attribute; + +import org.apache.tools.ant.UnknownElement; + +/** + * Check if an attribute is blank or not. + */ +public class IfBlankAttribute extends BaseIfAttribute { + /** The unless version */ + public static class Unless extends IfBlankAttribute { + { setPositive(false); } + } + /** + * check if the attribute value is blank or not + * {@inheritDoc} + */ + public boolean isEnabled(UnknownElement el, String value) { + return convertResult((value == null || "".equals(value))); + } +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfBlankAttribute.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfSetAttribute.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfSetAttribute.java?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfSetAttribute.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfSetAttribute.java Sun May 5 23:49:49 2013 @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.attribute; + +import org.apache.tools.ant.UnknownElement; + +/** + * Check if an attribute value as a property is set or not + */ +public class IfSetAttribute extends BaseIfAttribute { + /** The unless version */ + public static class Unless extends IfSetAttribute { + { setPositive(false); } + } + /** + * check if the attribute value is blank or not + * {@inheritDoc} + */ + public boolean isEnabled(UnknownElement el, String value) { + return convertResult(getProject().getProperty(value) != null); + } +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfSetAttribute.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfTrueAttribute.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfTrueAttribute.java?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfTrueAttribute.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfTrueAttribute.java Sun May 5 23:49:49 2013 @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.attribute; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.UnknownElement; + +/** + * Check if an attribute value is true or not. + */ +public class IfTrueAttribute extends BaseIfAttribute { + /** The unless version */ + public static class Unless extends IfTrueAttribute { + { setPositive(false); } + } + + /** + * check if the attribute value is true or not + * {@inheritDoc} + */ + public boolean isEnabled(UnknownElement el, String value) { + return convertResult(Project.toBoolean(value)); + } +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/attribute/IfTrueAttribute.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AttributeNamespaceDef.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AttributeNamespaceDef.java?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AttributeNamespaceDef.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AttributeNamespaceDef.java Sun May 5 23:49:49 2013 @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.ProjectHelper; +import org.apache.tools.ant.ComponentHelper; +import org.apache.tools.ant.AntTypeDefinition; +import org.apache.tools.ant.attribute.AttributeNamespace; + +/** + * Defintion to allow the uri to be considered for + * ant attributes. + * + * @since Ant 1.8.0 + */ +public final class AttributeNamespaceDef extends AntlibDefinition { + + /** + * Run the definition. + * This registers the xml namespace (uri) as a namepace for + * attributes. + */ + public void execute() { + String componentName = ProjectHelper.nsToComponentName( + getURI()); + AntTypeDefinition def = new AntTypeDefinition(); + def.setName(componentName); + def.setClassName(AttributeNamespace.class.getName()); + def.setClass(AttributeNamespace.class); + def.setRestrict(true); + def.setClassLoader(AttributeNamespace.class.getClassLoader()); + ComponentHelper.getComponentHelper(getProject()) + .addDataTypeDefinition(def); + } +} Propchange: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AttributeNamespaceDef.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties?rev=1479422&r1=1479421&r2=1479422&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/defaults.properties Sun May 5 23:49:49 2013 @@ -20,6 +20,7 @@ antstructure=org.apache.tools.ant.taskde antversion=org.apache.tools.ant.taskdefs.condition.AntVersion apply=org.apache.tools.ant.taskdefs.Transform apt=org.apache.tools.ant.taskdefs.Apt +attributenamespacedef=org.apache.tools.ant.taskdefs.AttributeNamespaceDef augment=org.apache.tools.ant.taskdefs.AugmentReference available=org.apache.tools.ant.taskdefs.Available basename=org.apache.tools.ant.taskdefs.Basename Added: ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml?rev=1479422&view=auto ============================================================================== --- ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml (added) +++ ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml Sun May 5 23:49:49 2013 @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Propchange: ant/core/trunk/src/tests/antunit/core/ant-attribute-test.xml ------------------------------------------------------------------------------ svn:eol-style = native