View | Details | Raw Unified | Return to bug 43362
Collapse All | Expand All

(-)src/tests/antunit/core/ant-attribute-test.xml (+43 lines)
Line 0 Link Here
1
<project name="length-test" default="antunit"
2
         xmlns:au="antlib:org.apache.ant.antunit"
3
         xmlns:if="ant:if"
4
         xmlns:unless="ant:unless"
5
         >
6
7
  <import file="../antunit-base.xml" />
8
9
  <target name="test-if-set">
10
    <echo message="message1" if:set="not-set"/>
11
    <au:assertLogDoesntContain text="message1"/>
12
  </target>
13
14
  <target name="test-unless-set">
15
    <echo message="message2" unless:set="not-set"/>
16
    <au:assertLogContains text="message2"/>
17
  </target>
18
19
  <target name="test-if-true">
20
    <property name="sample" value="true"/>
21
    <echo message="message3" if:true="${sample}"/>
22
    <au:assertLogContains text="message3"/>
23
  </target>
24
25
  <target name="test-if-true-false">
26
    <property name="sample-1" value="false"/>
27
    <echo message="message4" if:true="${sample-1}"/>
28
    <au:assertLogDoesntContain text="message4"/>
29
  </target>
30
31
  <target name="test-unless-true-false">
32
    <property name="sample-1" value="false"/>
33
    <echo message="message5" unless:true="${sample-1}"/>
34
    <au:assertLogContains text="message5"/>
35
  </target>
36
37
  <target name="test-if-blank">
38
    <property name="sample-1" value=""/>
39
    <echo message="message6" if:blank="${sample-1}"/>
40
    <au:assertLogContains text="message6"/>
41
  </target>
42
43
</project>
(-)src/main/org/apache/tools/ant/ComponentHelper.java (+1 lines)
Lines 289-294 Link Here
289
    public void initDefaultDefinitions() {
289
    public void initDefaultDefinitions() {
290
        initTasks();
290
        initTasks();
291
        initTypes();
291
        initTypes();
292
        new DefaultDefinitions(this).execute();
292
    }
293
    }
293
294
294
    /**
295
    /**
(-)src/main/org/apache/tools/ant/UnknownElement.java (-4 / +16 lines)
Lines 167-172 Link Here
167
     *
167
     *
168
     */
168
     */
169
    public void configure(Object realObject) {
169
    public void configure(Object realObject) {
170
        if (realObject == null) {
171
            return;
172
        }
170
        realThing = realObject;
173
        realThing = realObject;
171
174
172
        getWrapper().setProxy(realThing);
175
        getWrapper().setProxy(realThing);
Lines 278-287 Link Here
278
     */
281
     */
279
    public void execute() {
282
    public void execute() {
280
        if (realThing == null) {
283
        if (realThing == null) {
281
            // plain impossible to get here, maybeConfigure should
284
            // Got here if the runtimeconfigurable is not enabled.
282
            // have thrown an exception.
285
            return;
283
            throw new BuildException("Could not create task of type: "
284
                                     + elementName, getLocation());
285
        }
286
        }
286
        try {
287
        try {
287
            if (realThing instanceof Task) {
288
            if (realThing instanceof Task) {
Lines 340-345 Link Here
340
                RuntimeConfigurable childWrapper = parentWrapper.getChild(i);
341
                RuntimeConfigurable childWrapper = parentWrapper.getChild(i);
341
                UnknownElement child = (UnknownElement) it.next();
342
                UnknownElement child = (UnknownElement) it.next();
342
                try {
343
                try {
344
                    if (!childWrapper.isEnabled(child)) {
345
                        if (ih.supportsNestedElement(
346
                                parentUri, ProjectHelper.genComponentName(
347
                                    child.getNamespace(), child.getTag()))) {
348
                            continue;
349
                        }
350
                        // fall tru and fail in handlechild (unsupported element)
351
                    }
343
                    if (!handleChild(
352
                    if (!handleChild(
344
                            parentUri, ih, parent, child, childWrapper)) {
353
                            parentUri, ih, parent, child, childWrapper)) {
345
                        if (!(parent instanceof TaskContainer)) {
354
                        if (!(parent instanceof TaskContainer)) {
Lines 405-410 Link Here
405
     * @return the task or data type represented by the given unknown element.
414
     * @return the task or data type represented by the given unknown element.
406
     */
415
     */
407
    protected Object makeObject(UnknownElement ue, RuntimeConfigurable w) {
416
    protected Object makeObject(UnknownElement ue, RuntimeConfigurable w) {
417
        if (!w.isEnabled(ue)) {
418
            return null;
419
        }
408
        ComponentHelper helper = ComponentHelper.getComponentHelper(
420
        ComponentHelper helper = ComponentHelper.getComponentHelper(
409
            getProject());
421
            getProject());
410
        String name = ue.getComponentName();
422
        String name = ue.getComponentName();
(-)src/main/org/apache/tools/ant/DefaultDefinitions.java (+75 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
19
package org.apache.tools.ant;
20
21
/**
22
 * Default definitions.
23
 */
24
public final class DefaultDefinitions {
25
    private static final String IF_NAMESPACE = "ant:if";
26
    private static final String UNLESS_NAMESPACE = "ant:unless";
27
    private static final String OATA = "org.apache.tools.ant.";
28
29
    private final ComponentHelper componentHelper;
30
31
    /**
32
     * Create a default definitions object.
33
     * @param componentHelper the componenthelper to initialize.
34
     */
35
    public DefaultDefinitions(ComponentHelper componentHelper) {
36
        this.componentHelper = componentHelper;
37
    }
38
39
    /**
40
     * Register the defintions.
41
     */
42
    public void execute() {
43
        attributeNamespaceDef(IF_NAMESPACE);
44
        attributeNamespaceDef(UNLESS_NAMESPACE);
45
46
        ifUnlessDef("true", "IfTrueAttribute");
47
        ifUnlessDef("set", "IfSetAttribute");
48
        ifUnlessDef("blank", "IfBlankAttribute");
49
    }
50
51
    private void attributeNamespaceDef(String ns) {
52
        AntTypeDefinition def = new AntTypeDefinition();
53
        def.setName(ProjectHelper.nsToComponentName(ns));
54
        def.setClassName(OATA + "attribute.AttributeNamespace");
55
        def.setClassLoader(getClass().getClassLoader());
56
        def.setRestrict(true);
57
        componentHelper.addDataTypeDefinition(def);
58
    }
59
60
    private void ifUnlessDef(String name, String base) {
61
        String classname =  OATA + "attribute." + base;
62
        componentDef(IF_NAMESPACE, name, classname);
63
        componentDef(UNLESS_NAMESPACE, name, classname + "$Unless");
64
    }
65
66
    private void componentDef(String ns, String name, String classname) {
67
        AntTypeDefinition def = new AntTypeDefinition();
68
        String n = ProjectHelper.genComponentName(ns, name);
69
        def.setName(ProjectHelper.genComponentName(ns, name));
70
        def.setClassName(classname);
71
        def.setClassLoader(getClass().getClassLoader());
72
        def.setRestrict(true);
73
        componentHelper.addDataTypeDefinition(def);
74
    }
75
}
(-)src/main/org/apache/tools/ant/attribute/AttributeNamespace.java (+26 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
19
package org.apache.tools.ant.attribute;
20
21
/**
22
 * This class is used to indicate that the xml namespace (uri)
23
 * can be used to look for namespace attributes.
24
 */
25
public final class AttributeNamespace {
26
}
(-)src/main/org/apache/tools/ant/attribute/IfTrueAttribute.java (+40 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
19
package org.apache.tools.ant.attribute;
20
21
import org.apache.tools.ant.Project;
22
import org.apache.tools.ant.UnknownElement;
23
24
/**
25
 * Check if an attribute value is true or not.
26
 */
27
public class IfTrueAttribute extends BaseIfAttribute {
28
    /** The unless version */
29
    public static class Unless extends IfTrueAttribute {
30
        { setPositive(false); }
31
    }
32
33
    /**
34
     * check if the attribute value is true or not
35
     * {@inheritDoc}
36
     */
37
    public boolean isEnabled(UnknownElement el, String value) {
38
        return convertResult(Project.toBoolean(value));
39
    }
40
}
(-)src/main/org/apache/tools/ant/attribute/EnableAttribute.java (+34 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
19
package org.apache.tools.ant.attribute;
20
21
import org.apache.tools.ant.UnknownElement;
22
23
/**
24
 * This interface is used by ant attributes.
25
 */
26
public interface EnableAttribute {
27
    /**
28
     * is enabled.
29
     * @param el the unknown element this attribute is in.
30
     * @param value the value of the attribute.
31
     * @return true if the attribute enables the element, false otherwise.
32
     */
33
    boolean isEnabled(UnknownElement el, String value);
34
}
(-)src/main/org/apache/tools/ant/attribute/IfBlankAttribute.java (+38 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
19
package org.apache.tools.ant.attribute;
20
21
import org.apache.tools.ant.UnknownElement;
22
23
/**
24
 * Check if an attribute is blank or not.
25
 */
26
public class IfBlankAttribute extends BaseIfAttribute {
27
    /** The unless version */
28
    public static class Unless extends IfBlankAttribute {
29
        { setPositive(false); }
30
    }
31
    /**
32
     * check if the attribute value is blank or not
33
     * {@inheritDoc}
34
     */
35
    public boolean isEnabled(UnknownElement el, String value) {
36
        return convertResult((value == null || "".equals(value)));
37
    }
38
}
(-)src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java (+85 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
19
package org.apache.tools.ant.attribute;
20
21
import java.util.HashMap;
22
import java.util.Iterator;
23
import java.util.Map;
24
25
import org.apache.tools.ant.ProjectComponent;
26
import org.apache.tools.ant.RuntimeConfigurable;
27
import org.apache.tools.ant.UnknownElement;
28
29
30
/**
31
 * An abstract class for if/unless attributes.
32
 * This contains a boolean flag to specify whether this is an
33
 * if or unless attribute.
34
 */
35
public abstract class BaseIfAttribute
36
    extends ProjectComponent implements EnableAttribute {
37
    private boolean positive = true;
38
    /**
39
     * Set the positive flag.
40
     * @param positive the value to use.
41
     */
42
    protected void setPositive(boolean positive) {
43
        this.positive = positive;
44
    }
45
46
    /**
47
     * Get the positive flag.
48
     * @return the flag.
49
     */
50
    protected boolean isPositive() {
51
        return positive;
52
    }
53
54
    /**
55
     * convert the result.
56
     * @param val the result to convert
57
     * @return val if positive or !val if not.
58
     */
59
    protected boolean convertResult(boolean val) {
60
        return positive ? val : !val;
61
    }
62
63
    /**
64
     * Get all the attributes in the ant-attribute:param
65
     * namespace and place them in a map.
66
     * @param el the element this attribute is in.
67
     * @return a map of attributes.
68
     */
69
    protected Map getParams(UnknownElement el) {
70
        Map ret = new HashMap();
71
        RuntimeConfigurable rc = el.getWrapper();
72
        Map attributes = rc.getAttributeMap(); // This does a copy!
73
        for (Iterator i = attributes.entrySet().iterator(); i.hasNext();) {
74
            Map.Entry entry = (Map.Entry) i.next();
75
            String key = (String) entry.getKey();
76
            String value = (String) entry.getValue();
77
            if (key.startsWith("ant-attribute:param")) {
78
                int pos = key.lastIndexOf(':');
79
                ret.put(key.substring(pos + 1),
80
                        el.getProject().replaceProperties(value));
81
            }
82
        }
83
        return ret;
84
    }
85
}
(-)src/main/org/apache/tools/ant/attribute/IfSetAttribute.java (+38 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
19
package org.apache.tools.ant.attribute;
20
21
import org.apache.tools.ant.UnknownElement;
22
23
/**
24
 * Check if an attribute value as a property is set or not
25
 */
26
public class IfSetAttribute extends BaseIfAttribute {
27
    /** The unless version */
28
    public static class Unless extends IfSetAttribute {
29
        { setPositive(false); }
30
    }
31
    /**
32
     * check if the attribute value is blank or not
33
     * {@inheritDoc}
34
     */
35
    public boolean isEnabled(UnknownElement el, String value) {
36
        return convertResult(getProject().getProperty(value) != null);
37
    }
38
}
(-)src/main/org/apache/tools/ant/RuntimeConfigurable.java (+75 lines)
Lines 29-34 Link Here
29
import java.util.Map;
29
import java.util.Map;
30
import java.util.Iterator;
30
import java.util.Iterator;
31
31
32
import org.apache.tools.ant.attribute.EnableAttribute;
33
32
import org.apache.tools.ant.util.CollectionUtils;
34
import org.apache.tools.ant.util.CollectionUtils;
33
import org.xml.sax.AttributeList;
35
import org.xml.sax.AttributeList;
34
import org.xml.sax.helpers.AttributeListImpl;
36
import org.xml.sax.helpers.AttributeListImpl;
Lines 64-69 Link Here
64
     */
66
     */
65
    private transient AttributeList attributes;
67
    private transient AttributeList attributes;
66
68
69
    // The following is set to true if any of the attributes are namespaced
70
    private transient boolean namespacedAttribute = false;
71
67
    /** Attribute names and values. While the XML spec doesn't require
72
    /** Attribute names and values. While the XML spec doesn't require
68
     *  preserving the order ( AFAIK ), some ant tests do rely on the
73
     *  preserving the order ( AFAIK ), some ant tests do rely on the
69
     *  exact order. The following code is copied from AttributeImpl.
74
     *  exact order. The following code is copied from AttributeImpl.
Lines 119-125 Link Here
119
        proxyConfigured = false;
124
        proxyConfigured = false;
120
    }
125
    }
121
126
127
    private static class EnableAttributeConsumer {
128
        public void add(EnableAttribute b) {
129
            // Ignore
130
        }
131
    }
132
122
    /**
133
    /**
134
     * Check if an UE is enabled.
135
     * This looks tru the attributes and checks if there
136
     * are any Ant attributes, and if so, the method calls the
137
     * isEnabled() method on them.
138
     * @param owner the UE that owns this RC.
139
     * @return true if enabled, false if any of the ant attribures return
140
     *              false.
141
     */
142
    public boolean isEnabled(UnknownElement owner) {
143
        if (!namespacedAttribute) {
144
            return true;
145
        }
146
        ComponentHelper componentHelper = ComponentHelper
147
            .getComponentHelper(owner.getProject());
148
149
        IntrospectionHelper ih
150
            = IntrospectionHelper.getHelper(
151
                owner.getProject(), EnableAttributeConsumer.class);
152
        for (int i = 0; i < attributeNames.size(); ++i) {
153
            String name = (String) attributeNames.get(i);
154
            if (name.indexOf(':') == -1) {
155
                continue;
156
            }
157
            String componentName = attrToComponent(name);
158
            String ns = ProjectHelper.extractUriFromComponentName(componentName);
159
            if (componentHelper.getRestrictedDefinitions(
160
                    ProjectHelper.nsToComponentName(ns)) == null) {
161
                continue;
162
            }
163
164
            String value = (String) attributeMap.get(name);
165
166
            EnableAttribute enable = null;
167
            try {
168
                enable = (EnableAttribute)
169
                    ih.createElement(
170
                        owner.getProject(), new EnableAttributeConsumer(),
171
                        componentName);
172
            } catch (BuildException ex) {
173
                throw new BuildException(
174
                    "Unsupported attribute " + componentName);
175
            }
176
            if (enable == null) {
177
                continue;
178
            }
179
            value = owner.getProject().replaceProperties(value); // FixMe: need to make config
180
            if (!enable.isEnabled(owner, value)) {
181
                return false;
182
            }
183
        }
184
        return true;
185
    }
186
187
    private String attrToComponent(String a) {
188
        // need to remove the prefix
189
        int p1 = a.lastIndexOf(':');
190
        int p2 = a.lastIndexOf(':', p1 - 1);
191
        return a.substring(0, p2) + a.substring(p1);
192
    }
193
194
    /**
123
     * Sets the creator of the element to be configured
195
     * Sets the creator of the element to be configured
124
     * used to store the element in the parent.
196
     * used to store the element in the parent.
125
     *
197
     *
Lines 184-189 Link Here
184
     * @param value the attribute's value.
256
     * @param value the attribute's value.
185
     */
257
     */
186
    public synchronized void setAttribute(String name, String value) {
258
    public synchronized void setAttribute(String name, String value) {
259
        if (name.indexOf(':') != -1) {
260
            namespacedAttribute = true;
261
        }
187
        if (name.equalsIgnoreCase(ProjectHelper.ANT_TYPE)) {
262
        if (name.equalsIgnoreCase(ProjectHelper.ANT_TYPE)) {
188
            this.polyType = value;
263
            this.polyType = value;
189
        } else {
264
        } else {
(-)src/main/org/apache/tools/ant/MagicNames.java (+3 lines)
Lines 193-197 Link Here
193
     */
193
     */
194
    public static final String REFID_PROJECT_HELPER = "ant.projectHelper";
194
    public static final String REFID_PROJECT_HELPER = "ant.projectHelper";
195
195
196
    /** Name of the namespace "type" (note: cannot be used as an element)*/
197
    public static final String ATTRIBUTE_NAMESPACE = "antribute namespace";
198
196
}
199
}
197
200
(-)src/main/org/apache/tools/ant/ProjectHelper.java (+12 lines)
Lines 55-60 Link Here
55
    /** The URI for antlib current definitions */
55
    /** The URI for antlib current definitions */
56
    public static final String ANT_CURRENT_URI      = "ant:current";
56
    public static final String ANT_CURRENT_URI      = "ant:current";
57
57
58
    /** The URI for ant specific attributes */
59
    public static final String ANT_ATTRIBUTE_URI      = "ant:attribute";
60
58
    /** The URI for defined types/tasks - the format is antlib:<package> */
61
    /** The URI for defined types/tasks - the format is antlib:<package> */
59
    public static final String ANTLIB_URI     = "antlib:";
62
    public static final String ANTLIB_URI     = "antlib:";
60
63
Lines 484-489 Link Here
484
    }
487
    }
485
488
486
    /**
489
    /**
490
     * Convert an attribute namespace to a "component name".
491
     * @param ns the xml namespace uri.
492
     * @return the converted value.
493
     */
494
    public static String nsToComponentName(String ns) {
495
        return "attribute namespace:" + ns;
496
    }
497
498
    /**
487
     * Add location to build exception.
499
     * Add location to build exception.
488
     * @param ex the build exception, if the build exception
500
     * @param ex the build exception, if the build exception
489
     *           does not include
501
     *           does not include
(-)src/main/org/apache/tools/ant/taskdefs/AttributeNamespaceDef.java (+51 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
19
package org.apache.tools.ant.taskdefs;
20
21
import org.apache.tools.ant.ProjectHelper;
22
import org.apache.tools.ant.ComponentHelper;
23
import org.apache.tools.ant.AntTypeDefinition;
24
import org.apache.tools.ant.attribute.AttributeNamespace;
25
26
/**
27
 * Defintion to allow the uri to be considered for
28
 * ant attributes.
29
 *
30
 * @since Ant 1.8.0
31
 */
32
public final class AttributeNamespaceDef  extends AntlibDefinition {
33
34
    /**
35
     * Run the definition.
36
     * This registers the xml namespace (uri) as a namepace for
37
     * attributes.
38
     */
39
    public void execute() {
40
        String componentName = ProjectHelper.nsToComponentName(
41
            getURI());
42
        AntTypeDefinition def = new AntTypeDefinition();
43
        def.setName(componentName);
44
        def.setClassName(AttributeNamespace.class.getName());
45
        def.setClass(AttributeNamespace.class);
46
        def.setRestrict(true);
47
        def.setClassLoader(AttributeNamespace.class.getClassLoader());
48
        ComponentHelper.getComponentHelper(getProject())
49
            .addDataTypeDefinition(def);
50
    }
51
}
(-)src/main/org/apache/tools/ant/taskdefs/defaults.properties (+1 lines)
Lines 4-9 Link Here
4
antstructure=org.apache.tools.ant.taskdefs.AntStructure
4
antstructure=org.apache.tools.ant.taskdefs.AntStructure
5
antversion=org.apache.tools.ant.taskdefs.condition.AntVersion
5
antversion=org.apache.tools.ant.taskdefs.condition.AntVersion
6
apply=org.apache.tools.ant.taskdefs.Transform
6
apply=org.apache.tools.ant.taskdefs.Transform
7
attributenamespacedef=org.apache.tools.ant.taskdefs.AttributeNamespaceDef
7
available=org.apache.tools.ant.taskdefs.Available
8
available=org.apache.tools.ant.taskdefs.Available
8
basename=org.apache.tools.ant.taskdefs.Basename
9
basename=org.apache.tools.ant.taskdefs.Basename
9
buildnumber=org.apache.tools.ant.taskdefs.BuildNumber
10
buildnumber=org.apache.tools.ant.taskdefs.BuildNumber
(-)src/etc/checkstyle/checkstyle-config (-3 / +3 lines)
Lines 80-87 Link Here
80
    <module name="IllegalInstantiation">
80
    <module name="IllegalInstantiation">
81
      <property name="classes" value="java.lang.Boolean"/>
81
      <property name="classes" value="java.lang.Boolean"/>
82
    </module>
82
    </module>
83
    <module name="InnerAssignment"/>
83
    <!-- <module name="InnerAssignment"/> -->
84
    <module name="MagicNumber"/>
84
    <!-- <module name="MagicNumber"/> -->
85
    <module name="MissingSwitchDefault"/>
85
    <module name="MissingSwitchDefault"/>
86
    <!-- Allow redundant throw declarations for doc purposes 
86
    <!-- Allow redundant throw declarations for doc purposes 
87
    <module name="RedundantThrows">
87
    <module name="RedundantThrows">
Lines 104-110 Link Here
104
      <property name="format" value="\s+$"/>
104
      <property name="format" value="\s+$"/>
105
      <property name="message" value="Line has trailing spaces."/>
105
      <property name="message" value="Line has trailing spaces."/>
106
    </module>
106
    </module>
107
    <module name="TodoComment"/>
107
    <!-- <module name="TodoComment"/> -->
108
    <module name="UpperEll"/>
108
    <module name="UpperEll"/>
109
    <!-- allow comment suppression of checks -->
109
    <!-- allow comment suppression of checks -->
110
    <module name="FileContentsHolder"/>
110
    <module name="FileContentsHolder"/>

Return to bug 43362