I've just added a new module to start better supporting components
implemented in Groovy.  We've already Groovy support from the
implementation-script extension but the generic multi-language nature of
that extension means it can't exploit some of the features unique to each
language.

This new module enables using Groovy scripts anywhere in SCA where Java can
be used and this makes it really really easy to start exploring the use of
Groovy. Groovy works well with this approach as the syntax is so close to
Java there's not much of a learning curve and as Groovy now supports things
like annotations it can be used interchangeably with SCA Java components.
The SCDL doesn't need to change as the groovy script gets compiled into Java
byte code looking exactly like a regular Java class and can be referenced
with <implementation.java> in the .composite file.

For example try this with the Tuscany calculator sample:

Add this dependency to the calculator sample pom.xml:

        <dependency>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-contribution-groovy</artifactId>
            <version>1.2-incubating-SNAPSHOT</version>
            <scope>runtime</scope>
        </dependency>

Delete the Java src/main/java/calculator/DivideImpl.java class and create a
Groovy script named src/main/resources/calculator/divide.groovy with the
following contents:

package calculator;
class DivideServiceImpl implements DivideService {
    double divide(double n1, double n2) {
        return n1 / n2;
    }
}

Thats it, the sample should continue to work just as before but under the
covers its invoking the Groovy script.  See http://groovy.codehaus.org/ to
learn more about all the features provided by Groovy.

   ...ant

Reply via email to