Groovy Add-on » History » Version 8
Udo Offermann, 08.04.2013 16:32
1 | 1 | Udo Offermann | h1. Groovy Add-on |
---|---|---|---|
2 | 2 | Udo Offermann | |
3 | 3 | Udo Offermann | The Groovy Add-on allows to use the "Groovy language":http://groovy.codehaus.org/ within z2 applications. It supports pure Groovy modules beside pure Java modules as well as modules containing both Java and Groovy source code. |
4 | |||
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 | 6 | Udo Offermann | At first you need to add the Groovy Add-on repository to your environment with @gitcr.uri=gitcr.uri=http://git.z2-environment.net/z2-addons.groovy@ (see also the @environment@ module of [[Sample Groovy Support]]). |
19 | |||
20 | @environment/groovyAddon.properties:@ |
||
21 | <pre> |
||
22 | com.zfabrik.systemStates.participation=com.zfabrik.boot.main/sysrepo_up |
||
23 | |||
24 | # git stored component repository |
||
25 | com.zfabrik.component.type=com.zfabrik.gitcr |
||
26 | |||
27 | # true <=> optional repository. If gitcr.uri is invalid, then this gitcr will be ignore silently |
||
28 | gitcr.optional=true |
||
29 | |||
30 | # this can also point to a remote repository like |
||
31 | # ssh://myserver/some/git/repo |
||
32 | gitcr.uri=http://git.z2-environment.net/z2-addons.groovy |
||
33 | |||
34 | # the git branch to use (e.g. 'master') |
||
35 | gitcr.branch=master |
||
36 | </pre> |
||
37 | |||
38 | 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]]). |
39 | 3 | Udo Offermann | |
40 | Edit the Java component descriptor and change/add the @java.compile.order@ property: |
||
41 | |||
42 | @<module-name>/java/z.properties:@ |
||
43 | <pre><code class="python"> |
||
44 | com.zfabrik.component.type=com.zfabrik.java |
||
45 | java.privateReferences=... |
||
46 | java.publicReferences=... |
||
47 | |||
48 | java.compile.order = groovy |
||
49 | </code></pre> |
||
50 | 5 | Udo Offermann | |
51 | When using Spring with AspectJ the compile order will be: |
||
52 | 1 | Udo Offermann | |
53 | 8 | Udo Offermann | @java.compile.order = groovy, spring_aspectj@ |
54 | 5 | Udo Offermann | |
55 | You might need to change the heap and the perm size settings of the web worker since Groovy is usually more memory hungry than Java. |
||
56 | 3 | Udo Offermann | |
57 | @environment/webWorker.properties:@ |
||
58 | <pre><code class="python"> |
||
59 | ... |
||
60 | worker.process.vmOptions=\ |
||
61 | -Xmx128m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -XX:MaxPermSize=256m \ |
||
62 | ... |
||
63 | </code></pre> |