Project

General

Profile

Groovy Add-on » History » Version 14

Henning Blohm, 08.04.2013 16:40

1 1 Udo Offermann
h1. Groovy Add-on
2 2 Udo Offermann
3 12 Udo Offermann
The Groovy Add-on allows to use the "Groovy language":http://groovy.codehaus.org/ within z2 applications. It supports pure Groovy modules as well as modules containing both Java and Groovy source code. 
4 3 Udo Offermann
5
The Groovy Add-on comes with the Groovy version 2.1.2. 
6
7
h2. How does it work?
8
9
The z2-Groovy compiler checks for each source component (i.e. @java/src.api@ and @java/src.impl@) whether it contains pure Groovy source files or Java and Groovy sources and chooses the appropriate compiler. 
10
11
The Joint-Compiler of Groovy SDK compiles mixed Groovy and Java sources within three passes: In step 1) all Groovy classes are compiled as stubs (i.e. only the signatures w/o any lines of code) so that in step 2) the Java compiler from the JDK can compile all Java classes and resolve all dependencies to Groovy classes using the stubs. In step 3) the Groovy source files are translated into bytecode - since the Java classes are now translated, references from Groovy to Java can be also resolved correctly. 
12
If however no Java sources are found step 1 and 2 are skipped and the compilation process is speed-up by leaving only the plain Groovy compiler! 
13
14
A mixture of Groovy classes and Java classes across z2 modules is supported as well. Since cyclic dependencies are not allowed this does not even require the Groovy Joint-Compiler. 
15
16
h2. How do I use it?
17
18 10 Udo Offermann
h3. 1) Include the Groovy Add-on
19
20 14 Henning Blohm
At first you need to add the Groovy Add-on repository to your environment with @gitcr.uri=http://git.z2-environment.net/z2-addons.groovy@ (see also the @environment@ module of [[Sample-groovy-in-Z2]]).
21 6 Udo Offermann
22
@environment/groovyAddon.properties:@
23
<pre>
24
com.zfabrik.systemStates.participation=com.zfabrik.boot.main/sysrepo_up
25
26
# git stored component repository
27
com.zfabrik.component.type=com.zfabrik.gitcr
28
29
# true <=> optional repository. If gitcr.uri is invalid, then this gitcr will be ignore silently  
30
gitcr.optional=true
31
32
# this can also point to a remote repository like 
33
# ssh://myserver/some/git/repo
34
gitcr.uri=http://git.z2-environment.net/z2-addons.groovy
35
36
# the git branch to use (e.g. 'master')
37
gitcr.branch=master
38
</pre>
39
40 10 Udo Offermann
h3. 2) Write code
41
42 7 Udo Offermann
Put Groovy source files into the same structure as Java source files - i.e. @<module-name>/java/src.api@, @<module-name>/java/src.impl@ or @<module-name>/java/src.test@ (see the @com.zfabrik.samples.groovy.web@ module of [[Sample Groovy Support]]).
43 3 Udo Offermann
44 11 Udo Offermann
h3. 3) Define compile order
45 10 Udo Offermann
46 3 Udo Offermann
Edit the Java component descriptor and change/add the @java.compile.order@ property:
47
48
@<module-name>/java/z.properties:@
49
<pre><code class="python">
50
com.zfabrik.component.type=com.zfabrik.java
51
java.privateReferences=...
52
java.publicReferences=...
53
54
java.compile.order = groovy
55
</code></pre>
56 5 Udo Offermann
57
When using Spring with AspectJ the compile order will be:
58 1 Udo Offermann
 
59 8 Udo Offermann
@java.compile.order = groovy, spring_aspectj@
60 5 Udo Offermann
 
61 10 Udo Offermann
h3. 4) Adjust memory settings
62
63 9 Udo Offermann
You might need to change the heap and the perm size settings of the web worker in your environment since Groovy is usually more memory hungry than Java.
64 3 Udo Offermann
65
@environment/webWorker.properties:@
66
<pre><code class="python">
67
...
68
worker.process.vmOptions=\
69
 -Xmx128m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -XX:MaxPermSize=256m \
70
...
71
</code></pre>