As divers scripting/dynamic support is the latest fashion :) I spent
couple of hours on adding Groovy support. It was pretty smooth having
in count that my experience with Groove start by noon today :) and it
is pretty much similar in working and implementation to the JRuby/JS
support: you add the GroovyMixin to your Composite and implement the
groovy script. The implementation supports two styles of relating the
method call to the groovy script:
* script style: the method call will be matched to a file
<mixinType>.<methodName>.groovy. If found the script (whole file) is
evaluated and script output returned.
* object style: if the above file is not found the method call will be
matched to a file <mixinType>.groovy. If found the groovy object is
instantiated (one per mixin type per composite instance) and the
method with the same name and arguments is called, returning the
returned value.

As the Ruby mixin does with @this, GroovyMixin also "injects" the
composite as follow, depending on the type above:
* for scripts: there is a variable "self" bounded to the composite.
Question is: shall we also bind the arguments to a groovy variable
let's say "args" (Object array)?
* for objects: you can (mandatory now) def(ine) a variable named self
that will be set to the composite.
I had to use "self" instead of "this" as "this" is a reserved word and
I could not name it "@this".

For an example you can look at "GroovyHelloWorldCompositeTest".

I also found an "interesting" problem that I could not figure out why
it happened:
In the above test "HelloWorldSettings" has two properties: phrase and
name. While accessing the "phrase" from groovy everything worked fine,
accessing "name" was behaving different between running the test from
IDEA and from Maven. From idea it was returning the expected (set
before) value but from Maven it was returning the maven project name
as defined in pom.xml. I guess there was a strange interference
between maven groovy support and the run test. As my experience with
Groovy is so limited I cannot say exactly why this happen.

Alin

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to