Project

General

Profile

Groovy Add-on » History » Version 17

Henning Blohm, 10.04.2013 13:52

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