gjeudy (5) [Avatar] Offline
#1
Hi,

I'm trying to run the following ant script inspired from chapter13 of GinA.

<?xml version="1.0" ?>
<project name="groovy-test" default="test">
<taskdef name="groovy" >
classname="org.codehaus.groovy.ant.Groovy"
classpath="C:/Groovy/Groovy-1.6.5/embeddable/groovy-all-1.6.5.jar" />
<target name="test">
<groovy>
class RulePrinter extends org.apache.tools.ant.Task {
def size = 40
def symbol = '*'
public void execute() { println symbol * size }
}
project.addTaskDefinition('ruler', RulePrinter)
</groovy>

<ruler />
<ruler symbol="--8-" size="10" />
</target>
</project>

The script fails with:

BUILD FAILED
Csmilieocuments and SettingsgjeudyIdeaProjects est3uild.xml:17: The <ruler> ty
pe doesn't support the "symbol" attribute.
at org.apache.tools.ant.IntrospectionHelper.setAttribute(IntrospectionHelper.java:389)
at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:370)
at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:324)
at org.apache.tools.ant.Task.maybeConfigure(Task.java:254)
at org.apache.tools.ant.UnknownElement.configureUnknownElement.java:189) at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:15smilie
at org.apache.tools.ant.Task.perform(Task.java:363)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:106smilie
at org.apache.tools.ant.Main.runBuild(Main.java:66smilie
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)

Total time: 2 seconds

From my understanding a def property should be instrumented with getter/setter methods which normally would make ant "see" the symbol property.

Any help appreciated,
-Guillaume
Mittie (397) [Avatar] Offline
#2
Re: Groovy in action ant script fails in groovy 1.6.5
Hi Guillaume,

looks like ant interprets --8- as a number.

cheers
Dierk
gjeudy (5) [Avatar] Offline
#3
Re: Groovy in action ant script fails in groovy 1.6.5
I replaced --8- with abcd and I still get the same stack trace.

I tried with both ant 1.6.5 and 1.7.1.
Mittie (397) [Avatar] Offline
#4
Re: Groovy in action ant script fails in groovy 1.6.5
hm, ok.

Two things:
a) I would type the property "String symbol" (that shouldn't matter, it's just better style)
b) I would try renaming "ruler" and the class. You may have naming conflict with a task or class of the same name on your classpath.

cheers
Dierk
gjeudy (5) [Avatar] Offline
#5
Re: Groovy in action ant script fails in groovy 1.6.5
I strong-typed the properties and now it worked!

int size = 40
String symbol = '*'

Please note the dynamic typed props were sourced from Groovy In Action book smilie

I understand strong typing is preferable, I'll have to find cases where dynamic typing makes sense. Still a groovy newbie.

Cheers,
Guillaume
Mittie (397) [Avatar] Offline
#6
Re: Groovy in action ant script fails in groovy 1.6.5
well, the dynamic version certainly worked back then. The change is in the newer Ant version (not the Groovy version for that matter). I wasn't aware of that change until your post, though.

Thanks a lot for bringing up the issue!

regards
Dierk