This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 24 - Pages: 2 [ 1 2 | Next ] - Last Post: 10 Nov 22, 21:58 Last Post By: AndreWolff
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
BeanShell to Groovy tutorial?
Posted: 1 Oct 22, 18:35
 
  Click to reply to this thread Reply
I just did a quick test to convert one of my skins from BeanShell to Groovy.
I changes all .bsh fies to .groovy files and did a Make with the new skin.

I get a bunch of errors, which does not say anything to me:
Stack trace for jAlbum 29rc1 using skin FancyBoxGroovy 1.3.3:
 
se.datadosen.util.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Users\Gebruiker\AppData\Roaming\JAlbum\skins\FancyBoxGroovy\onload.groovy: 102: Can't have an abstract method in a non-abstract class. 
The class 'CustomUI$2' must be declared abstract or the method 'void focusGained(java.awt.event.FocusEvent)' must be implemented.
 in onload.groovy at line number 102 at column number 59
 
Line 102: customImageWidth.addFocusListener(new FocusListener() {                                 ^
 
C:\Users\Gebruiker\AppData\Roaming\JAlbum\skins\FancyBoxGroovy\onload.groovy: 95: 
The method focusLost should be public as it implements the corresponding method from interface java.awt.event.FocusListener
 
Line 95: private void focusLost(FocusEvent e) {
 
C:\Users\Gebruiker\AppData\Roaming\JAlbum\skins\FancyBoxGroovy\onload.groovy: 278: Modifier 'public' not allowed here.
 
Line 278: public JTextField folderImageSize = new JTextField("1920 x 1080");

I don't plan on taking a Groovy programming course.

So my question is will there be a BeanShell to Groovy tutorial?
davidekholm

Posts: 3,994
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 3 Oct 22, 15:09   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
I think those error messages are rather descriptive. Read them and follow the advises they give, i.e. add "public" when needed and change "private" to "public" on the indicated line(s)
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 5 Oct 22, 12:12   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Well David I did open an old version of the FancyBox which did not had a compiled GUI.

But if I convert the newest FancyBox version with compiled GUI, I get error statements which I don't understand:
se.datadosen.util.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Users\Gebruiker\AppData\Roaming\JAlbum\skins\FancyBoxGroovy\init.groovy: 482: token recognition error at: '"' 
in init.groovy at line number 482 at column number 103
 
Line 482:
s = engine.processTemplate(s).replaceAll(" +", " ").replaceAll("\r\n|\r|\n","<br>").replaceAll("<br>$", "").trim();
 
                                 ^
 
se.datadosen.util.ScriptException: groovy.lang.MissingMethodException: No signature of method: 
static java.lang.Integer.toString() is applicable for argument types: (BigDecimal) values: [50]
Possible solutions: toString(), toString(), toString(), toString(int), toString(int, int), toHexString(int) in common.css at line number 6
 
Line 6 in common.css:
<%
common.css does not contain: "BigDecimal" or "[50]"


Lucky the current bsh version works fine in 29c1.
davidekholm

Posts: 3,994
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 5 Oct 22, 13:24   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Groovy doesn't like $ within strings as this has special meaning (introduces a variable). If you need to use $, use \$ or use 'single quoted strings'
davidekholm

Posts: 3,994
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 5 Oct 22, 13:25   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
As for the other error. Pass me a zip/jaskin package of the failing skin for testing here.
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 5 Oct 22, 13:35   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
As for the other error. Pass me a zip/jaskin package of the failing skin for testing here.
See attached file.

Thanks fot the \$ hint, that did solve the problem.
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 19 Oct 22, 08:55   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
As for the other error. Pass me a zip/jaskin package of the failing skin for testing here.
David,, did you find a solution?
davidekholm

Posts: 3,994
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 19 Oct 22, 09:55   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Yes, but there are tons of things for you to adjust to make things work. The problems are luckily only of a few different categories, so you can apply the same types of fixes in multiple locations.

The Float.toString() error is solved like this:
Float.toString((float)(topButtonWidthFl / 2f));[(code]That extra (float) cast is needed as Groovy converts calculations to double as soon as it can.
 
Other typical errors you will be seeing in your skin are caused by these factors:
* You've made some utility methods private. Now they can't be called from other scripts.
* You need to adjust the declaration of any global variables by removing the type, so String foo=5 will become foo = 5 etc.
* Some calculations are brittle, the way you calculate "jAlbumVersion". I recommend this instead:[code]jAlbumVersion = Integer.parseInt(AlbumBean.PRODUCT_DISPLAY_VERSION);

  • You still do void tests using BeanShell syntax. I recommend adding the following to init.grooy:
    exists = binding.variables
    
    Now you can do your void tests like this:
    if (exists.foo) { ... }
    
davidekholm

Posts: 3,994
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 19 Oct 22, 09:56   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Yes, but there are tons of things for you to adjust to make things work. The problems are luckily only of a few different categories, so you can apply the same types of fixes in multiple locations.

The Float.toString() error is solved like this:
Float.toString((float)(topButtonWidthFl / 2f));
That extra (float) cast is needed as Groovy converts calculations to double as soon as it can.

Other typical errors you will be seeing in your skin are caused by these factors:
  • You've made some utility methods private. Now they can't be called from other scripts.
  • You need to adjust the declaration of any global variables by removing the type, so String foo=5 will become foo = 5 etc.
  • Some calculations are brittle, the way you calculate "jAlbumVersion". I recommend this instead:
    jAlbumVersion = Integer.parseInt(AlbumBean.PRODUCT_DISPLAY_VERSION);
    
  • You still do void tests using BeanShell syntax. I recommend adding the following to init.grooy:
    exists = binding.variables
    
    Now you can do your void tests like this:
    if (exists.foo) { ... }
    
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 19 Oct 22, 12:24   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thanks,David for these hints!

I hope others like Jeff and Rob will append here more hints!

I have now no time to investigate the Groovy conversion, that has to wait for some time.

BeanShell works fine and I am used to it, so why should I convert it to Groovy?
I am too old to learn new tricks!

Edited by: AndreWolff on 19 Oct 2022, 16:52
davidekholm

Posts: 3,994
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 19 Oct 22, 12:58   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
Thanks,David for these hints!

I have now no time to investigate the Groovy conversion, that has to wait for some time.

BeanShell works fine and I am used to it, so why should I convert it to Groovy?
I am too old to learn new tricks!


Reason being that we'll eventually remove BeanShell as it hasn't been maintained since 2005.
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 2 Nov 22, 17:05   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
  • Some calculations are brittle, the way you calculate "jAlbumVersion". I recommend this instead:
    jAlbumVersion = Integer.parseInt(AlbumBean.PRODUCT_DISPLAY_VERSION);
    
Well David, if I use your proposal I get this error:

se.datadosen.util.ScriptException: java.lang.NumberFormatException: For input string: "29.1" in init.groovy

But I get no error if I use my brittle code:
jAlbumVersionStr= internalVersion.substring(0, 2);
jAlbumVersion=Integer.parseInt(jAlbumVersionStr);  
davidekholm

Posts: 3,994
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 2 Nov 22, 22:40   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Use Float.parseFloat instead
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 2 Nov 22, 22:56   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Use Float.parseFloat instead
Yes I know that will help, but why should I not use variable internalVersion?
davidekholm

Posts: 3,994
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 3 Nov 22, 09:26   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
davidekholm wrote:
Use Float.parseFloat instead
Yes I know that will help, but why should I not use variable internalVersion?

It's not always a number. There may be "b" and "rc" characters there and doing a substring on internalVersion is ugly as it assumes two characters before a dot.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums