Project

General

Profile

Groovy Add-on » History » Version 18

Henning Blohm, 28.04.2013 11:01

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 17 Henning Blohm
h2. Repository
6 1 Udo Offermann
7 17 Henning Blohm
"z2-addons-groovy":https://redmine.z2-environment.net/projects/z2-addons/repository/z2-addons-groovy
8
9
h2. Version map
10
11
|_. add-on version |_. Groovy version |
12 18 Henning Blohm
| master | 2.0.6 |
13 3 Udo Offermann
14
h2. How does it work?
15
16
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. 
17
18
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. 
19
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! 
20
21
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. 
22
23
h2. How do I use it?
24
25 10 Udo Offermann
h3. 1) Include the Groovy Add-on
26
27 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]]).
28 6 Udo Offermann
29
@environment/groovyAddon.properties:@
30
<pre>
31
com.zfabrik.systemStates.participation=com.zfabrik.boot.main/sysrepo_up
32
33
# git stored component repository
34
com.zfabrik.component.type=com.zfabrik.gitcr
35
36
# true <=> optional repository. If gitcr.uri is invalid, then this gitcr will be ignore silently  
37
gitcr.optional=true
38
39
# this can also point to a remote repository like 
40
# ssh://myserver/some/git/repo
41
gitcr.uri=http://git.z2-environment.net/z2-addons.groovy
42
43
# the git branch to use (e.g. 'master')
44
gitcr.branch=master
45
</pre>
46
47 10 Udo Offermann
h3. 2) Write code
48
49 15 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-in-Z2]]).
50 3 Udo Offermann
51 11 Udo Offermann
h3. 3) Define compile order
52 10 Udo Offermann
53 3 Udo Offermann
Edit the Java component descriptor and change/add the @java.compile.order@ property:
54
55
@<module-name>/java/z.properties:@
56
<pre><code class="python">
57
com.zfabrik.component.type=com.zfabrik.java
58
java.privateReferences=...
59
java.publicReferences=...
60
61
java.compile.order = groovy
62
</code></pre>
63 5 Udo Offermann
64
When using Spring with AspectJ the compile order will be:
65 1 Udo Offermann
 
66 8 Udo Offermann
@java.compile.order = groovy, spring_aspectj@
67 5 Udo Offermann
 
68 10 Udo Offermann
h3. 4) Adjust memory settings
69
70 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.
71 3 Udo Offermann
72
@environment/webWorker.properties:@
73
<pre><code class="python">
74
...
75
worker.process.vmOptions=\
76
 -Xmx128m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -XX:MaxPermSize=256m \
77
...
78
</code></pre>