Error due to older Groovy version

One Star

Error due to older Groovy version

Hi,
I have code in a tGroovy component which requires a more recent version of Groovy than is provided in Talend. Specifically, there is a missing property 'mkp' in the class MarkupBuilder which is loaded from groovy-1.0.jar. I tested the same script in a recent Groovy version, where it works. Then I installed a more recent version of Talend (5.2.2), to find out it uses the same Groovy version. Next I thought about replacing the jar file, however this got me into deeper trouble.
Any advice?
Kind regards,
Yves
One Star

Re: Error due to older Groovy version

To be a bit more specific:
As can be seen in the TOS install dir, the Groovy version is quite recent:
\plugins\org.codehaus.groovy_1.8.6.xx-20120301-1300-e36-RELEASE\
However, my Groovy code is in a tGroovy component, and the tGroovy component depends on the file groovy-1.0.jar in the tGroovyFile component. When this jar is replaced by one which is more recent, errors occur when building the script ("groovy-1.0.jar is missing" etc.)
Is there any way of fixing this?
Thanks,
Yves
One Star

Re: Error due to older Groovy version

Any one? I find this dependency on groovy-1.0.jar quite odd, frankly...
(full path: \plugins\org.talend.designer.components.localprovider_5.2.2.r99271\components\tGroovyFile)
Thanks,
Yves
One Star

Re: Error due to older Groovy version

To continue my monologue :-)... (I do hope someone is listening out there)
So it turns out Talend uses Groovy v1.0, despite of - and as mentioned earlier - the plugin which suggests Groovy v.1.8.6
In my script: println org.codehaus.groovy.runtime.InvokerHelper.getVersion()
Any plans to update the tGroovy (and tGroovyFile) components to a recent Groovy version?
Thanks,
Yves
Moderator

Re: Error due to older Groovy version

Hi yvest,
There is an issue reported on talend bug tracker: https://jira.talendforge.org/browse/TDI-24781. Our developer will make a research on it and give the response asap, thanks for your suggestion.
In addition, I have a solution for your issue. Download the new version jar and rename the jar as "Groovy-1.0.jar", and then replace the old one, try it and let me know if it works?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Error due to older Groovy version

Hi Sabrina,
Many thanks for your response. I had tried already your suggestion of taking a recent jar and renaming it, however other problems arose (in the generated java code for the tGroovy component, the GroovyShell.evaluate() method which accepts an InputStream was first deprecated and has subsequently been removed; hence the code won't compile).
For now, I have worked around the issue by using tSystem and executing the script in the Groovy SDK on my system. However this is a rather ugly and non-portable solution, which I will surely fix as soon as Talend adapts the most recent Groovy version.
Best regards,
Yves
Moderator

Re: Error due to older Groovy version

Hi,
however other problems arose (in the generated java code for the tGroovy component, the GroovyShell.evaluate() method which accepts an InputStream was first deprecated and has subsequently been removed; hence the code won't compile).

Thanks for your feedback, I will make a research on this problem, hope there will be a solution for it. In addition, I'm tracing this bug and give you a notification when it has been fixed.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Moderator

Re: Error due to older Groovy version

Hi,
Many thanks for your response. I had tried already your suggestion of taking a recent jar and renaming it, however other problems arose (in the generated java code for the tGroovy component, the GroovyShell.evaluate() method which accepts an InputStream was first deprecated and has subsequently been removed; hence the code won't compile).

Maybe the jar is not refreshed, try to delete the component cache file and restart Talend Studio, to do:
1. Go to <Talend Studio installation path>/configuration/ the delete the file ComponentsCache.javacache.
2. Restart Talend Studio, the file ComponentsCache.javacache" file will be created again.
Let me know if it works?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Error due to older Groovy version

Hi Rebecca,
I did that, and - having Groovy-2.1.1.jar renamed to Groovy-1.0.jar - compilation now failed because the generated java code still has a dependency on a Groovy 1.0 method which is no longer in Groovy 2.1.1. Here is the excerpt:
String codetGroovy_1 = "my groovy script";
java.io.ByteArrayInputStream istGroovy_1 = new java.io.ByteArrayInputStream(codetGroovy_1.getBytes());
groovy.lang.Binding bindingtGroovy_1 = new groovy.lang.Binding();
bindingtGroovy_1.setVariable("i2b2DataDir", context.i2b2DataDir);
groovy.lang.GroovyShell shelltGroovy_1 = new groovy.lang.GroovyShell(bindingtGroovy_1);
shelltGroovy_1.evaluate(istGroovy_1); // >>> compilation fails here <<<
The method GroovyShell.evaluate(InputStream) was deprecated in Groovy 1.8, and later removed from the API. One possible solution would be to use the method GroovyShell.evaluate(String) instead, and pass codetGroovy_1 to it.
Best regards,
Yves
Seventeen Stars

Re: Error due to older Groovy version

Yes this is an issue which can only be solved by creating a new component as copy of the existing one. I suggest doing that and rename the new component tGroovy2.
The component designer allows to copy an existing component and modify it. I already did that in for a missing feature in the LDAP components.
Moderator

Re: Error due to older Groovy version

Hi,
There already been an issue about upgrading groovy jars for groovy components on our Jira, our developer is working on it, please monitor the issue.
https://jira.talendforge.org/browse/TDI-24781
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Error due to older Groovy version

I've been using Groovy frequently in Talend, so let me share how to upgrade your tGroovy component to use Groovy 2.1.1:
1. first, download and copy the Groovy jars referenced in the 2nd step to this directory:
{workspace}\java\lib
2. then, edit tGroovy_java.xml in this directory:
{TALEND_INSTALL_DIR}\plugins\org.talend.designer.components.localprovider_5.6.2.20150508_1414\components\tGroovy
Change the references hereafter to whatever Groovy version you adapt to:
<CODEGENERATION>
    <IMPORTS>
<IMPORT NAME="Groovy_Module" MODULE="antlr-2.7.6.jar" UrlPath="platform:/plugin/org.talend.libraries.apache.axis2/lib/antlr-2.7.6.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-2.1.1.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-2.1.1.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-starter.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-starter.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-xmlrpc-0.3.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-xmlrpc-0.3.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-xml-2.1.1.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-xml-2.1.1.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-sql-2.1.1.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-sql-2.1.1.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-4.0.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-analysis-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-analysis-4.0.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-commons-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-commons-4.0.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-tree-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-tree-4.0.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-util-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-util-4.0.jar" REQUIRED="true" />
     </IMPORTS>
   </CODEGENERATION>
3. This part required a few code changes so it was a bit trickier, but you'll be just fine if you copy the content beneath verbatim in tGroovy_begin.javajet:
<%@ jet 
    imports="
        org.talend.core.model.process.INode 
        org.talend.core.model.process.ElementParameterParser
        org.talend.designer.codegen.config.CodeGeneratorArgument
        java.util.Map
        java.util.List
    "
%>
<%
    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode)codeGenArgument.getArgument();
    String cid = node.getUniqueName();
    String codeStringArray{} = ElementParameterParser.getValue(node, "__CODE__").split("\n");
%>
String code<%=cid%> = "" 
<%for(int i =0 ;i<codeStringArray.length;i++){
    codeStringArray{i} = codeStringArray{i}.replace("\\","\\\\");
    codeStringArray{i} = codeStringArray{i}.replace("\"","\\\"");    
    %>
    + "<%=codeStringArray{i}%>" + "\n"
<%}%>; 
java.io.ByteArrayInputStream is<%=cid%> = new java.io.ByteArrayInputStream(code<%=cid%>.getBytes());
groovy.lang.Binding binding<%=cid%> = new groovy.lang.Binding();
<%
List<Map<String, String>> tableValues =
    (List<Map<String,String>>)ElementParameterParser.getObjectValue(
        node,
        "__VARIABLES__"
    );
    
    for(Map<String, String> tableValue : tableValues) {
                   %>
        binding<%=cid%>.setVariable(<%=tableValue.get("NAME")%>, <%=tableValue.get("VALUE")%>);
<%
}
%>
groovy.lang.GroovyShell shell<%=cid%> = new groovy.lang.GroovyShell(binding<%=cid%>);
shell<%=cid%>.evaluate(code<%=cid%>);
4. Restart Talend
That's it! 
One Star dbh
One Star

Re: Error due to older Groovy version

This topic lives on at TDI-33821
Now, there are incompatibilities between the Ancient Groovy 1.0 (Used on TOS DI 6.1.x) and Java 1.8.
If interested, please see the JIRA which has my attached changes to tGroovy to be compatible with Java 1.8 and upgrade Groovy itself.
I believe the right approach to use this is as follows:
* make a custom component out of the modified tGroovy
* Switch jobs to use the revised version
* Talend to integrate the fix and Groovy version upgrade
* Upon that fix being included in the talend release, switch Jobs back over to using the official talend component