jastrachan | 15 Apr 06:09 2004
Picon

Re: Bean properties

On 14 Apr 2004, at 17:55, Kevin Jones wrote:
> I'm trying to script Ant classes and I'm seeing something I thought 
> should
> work
>
> I'm trying to use the Get class something like this
>
> project = new Project()
> getter = new Get()
> getter.project = project
> getter.verbose = true
>
> The getter.verbose  = true fails, however getter.setVerbose(true) 
> works. The
> error I'm seeing is
>
> Caught: groovy.lang.GroovyRuntimeException: Cannot read property: src
>
> Looking at the javadocs for Ant it looks like there is a protected 
> 'Project'
> variable in Get class (which is inherited), but if there is a 'Verbose'
> field it must be private. Obviously there is a Get.setVerbose method. I
> thought that Groovy used reflection to look for a getXXX method, but 
> that
> doesn't seem to be working, or am I missing something (again!)
>
> This is with CVS HEAD about 24 hours old,

I just tried this in groovysh...

1> g = new org.apache.tools.ant.taskdefs.Get()
2> go

1> g.verbose = true
2> go
Cannot read property: verbose

it appears that the statement

     g.verbose = true

actually calls the getter for some reason. This sounds like some 
redundancy we're generating in the bytecode. Basically the property is 
write only in the Ant code (has a setter but no getter) hence the 
exception. But this is a bug - you would be able to update a write-only 
property.

I've raised this issue...

http://jira.codehaus.org/secure/ViewIssue.jspa?key=GROOVY-393

Until we sort this out, you can use Ant tasks easily via the 
AntBuilder...

import groovy.util.AntBuilder
ant = new AntBuilder()
ant.get(verbose:true, src:'foo/bar')

etc.

http://groovy.codehaus.org/ant.html

e.g.

http://tinyurl.com/35nab

James
-------
http://radio.weblogs.com/0112098/

Gmane