Re: MacroDef: Setting attribute via API should convert to lowercase

Stefan Bodewig <[email protected]>
Newsgroups gmane.comp.jakarta.ant.user
Message-ID <[email protected]>
On 2016-04-12, Al Le wrote:

> in my ant script, I define a task "MyTask" via "macrodef". The task
> has a mandatory attribute "nodeName" (not the camelCase name).

> Then I call the task from a javascript snippet:

> var myTask = project.createTask('myTask');
> myTask.setDynamicAttribute("nodeName", "blah");
> myTask.perform();

> This does not work because I use the camleCase name in the call to
> setDynamicAttribute. Later, when the task is performed, I get an error
> that the attribute "nodename" (lowercase!) is not set.

> In the source of MacroInstance I see that attribute names are
> converted to lower case when they are retrieved. But why are they not
> converted when they are set?

My guess is that you are the first person who's trying what you do and
you've simply hit a bug.

Any attribute set on a MacroInstance via an ant build file gets
lowercased in IntrospectionHelper - we've probably just overlooked the
case of anybody using the API directly.

Please open a bug ticket.

> I see one reason for converting everything to lower case

That's how Ant build files have always worked, task attributes are not
case-sensitive. And IntrospectionHelper is the central piece of mapping
attributes to method names or dynamic attributes (and a few other
things) - which takes care of using lowercase attribute names.

If you want to work around this, you may want to use IntrospectionHelper
via its API as well.

IntrospectionHelper.getHelper(MacroInstance.class).setAttribute(...)

Stefan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.