Porting pre-save JS script to nashorn

Description
drouleau
Posts: 5
Joined: Tue Mar 12, 2019 6:09 pm
Contact:

Porting pre-save JS script to nashorn

Postby drouleau » Tue Mar 12, 2019 6:24 pm

Hi,
I am trying to port a JS script to nashorn and I am getting the following exception when I call generateChange() like so

var changes = diffSvc.generateChange("", new date(),"",workitem_previous,workItem,com.polarion.alm.tracker.model.IWorkItem.DIFF_IGNORED_FIELDS);

--> Cannot cast jdk.nashorn.internal.runtime.NativeJavaPackage to java.util.Set

My Java knowledge is limited but I *think* the problem is because my package (com.polarion.alm.tracker.model.IWorkItem) is not loaded but I have not idea why.

This script used to run under Rhino and I did make some changes to it to get it to this point but I'm now stuck.

Any ideas?

Thanks in advance

Code: Select all

...
 10     var diffSvc = trackerService.getProjectsService().getDataService().getDiffManager();
 
...

 15     try                                                                                                       
 16     {
 17         var workitem_history = trackerService.getProjectsService().getDataService().getObjectHistory(workItem);
 18         var workitem_previous = workitem_history.get(workitem_history.size() - 1);
 19     }   
 20     catch (err)
 21     {
 22         workitem_previous = workItem; //If it is a new workitem, no differences
 23     }           
 24
 25     var date = Java.type("java.util.Date");

...

 33             
 34     var changes = diffSvc.generateChange("", new date(),"",workitem_previous,workItem,com.polarion.alm.tracker.model.IWorkItem.DIFF_IGNORED_FIELDS);

PatrickClaus
Posts: 19
Joined: Thu Jan 18, 2018 11:02 am
Location: Frauenauracher Str. 85, 91056 Erlangen

Re: Porting pre-save JS script to nashorn

Postby PatrickClaus » Wed Mar 13, 2019 10:07 am

Hello drouleau,

I am not sure if your code does not do this already, but try adding the explicit call to import the desired package, like so:

// Load compatibility script
load("nashorn:mozilla_compat.js");
// Import the java.awt package
importPackage(com.polarion.alm.tracker.model);

Let us know if it has helped, or if the problem still persists. :)
Best Regards,
Patrick Claus

External service provider at Valeo Siemens eAutomotive GmbH
Frauenauracher Str. 85
91056 Erlangen, Germany
Mail Address

drouleau
Posts: 5
Joined: Tue Mar 12, 2019 6:09 pm
Contact:

Re: Porting pre-save JS script to nashorn

Postby drouleau » Wed Mar 13, 2019 1:14 pm

Hi Patrick,
Thanks for the feedback. My code did not explicitely import the package so I added your lines however, the result is identical. :?

I added a throw to see what I was getting and I see a
ClassNotFoundException

Code: Select all

Error: *-wi_sourceCode-pre-save.js - java.lang.ClassNotFoundException: com.polarion.alm.tracker.model.IWorkItem.DIFF_IGNORED_FIELDS



Is it possible that the problem is related to a system-level parameter?

PatrickClaus
Posts: 19
Joined: Thu Jan 18, 2018 11:02 am
Location: Frauenauracher Str. 85, 91056 Erlangen

Re: Porting pre-save JS script to nashorn

Postby PatrickClaus » Thu Mar 14, 2019 9:54 am

Hello again,

I was just testing this on my local Polarion ALM 18.3 running on OpenJDK 11.0.1+13, and the result is as follows, for the following script:

Image

This at least confirms that the call should be working.
Maybe it is a system config option on your side.
Could you please check if you have the following enabled in your polarion.properties?
com.polarion.scripting.useRhinoJsEngine=true

If it is enabled, try disabling this option - as scripts should be moved to Java 8 anyways.
Other than that, I currently have no Idea what could cause the error showing up on your part.
Best Regards,
Patrick Claus

External service provider at Valeo Siemens eAutomotive GmbH
Frauenauracher Str. 85
91056 Erlangen, Germany
Mail Address

drouleau
Posts: 5
Joined: Tue Mar 12, 2019 6:09 pm
Contact:

Re: Porting pre-save JS script to nashorn

Postby drouleau » Thu Mar 14, 2019 3:07 pm

The polarion.properties file doesn't contain

Code: Select all

com.polarion.scripting.useRhinoJsEngine=
or any word containing "script".

Should I add com.polarion.scripting.useRhinoJsEngine=false?

What is the default if not present?

Since the script worked in an earlier version, shouldn't that still work?

Thanks
Denis

PatrickClaus
Posts: 19
Joined: Thu Jan 18, 2018 11:02 am
Location: Frauenauracher Str. 85, 91056 Erlangen

Re: Porting pre-save JS script to nashorn

Postby PatrickClaus » Mon Mar 18, 2019 10:46 am

Most properties are not directly listed in the polarion.properties file, unfortunately.
You can add the property yourself + restart the service, just to make sure. I am not sure what the default setting is, but this should exclude the possibility of any script adaption for older versions.

And yes - the script should work, but there were some internal switches in the Java version throughout different ALM versions from Polarion side. Also, they mostly switched to OpenJDK with 18.3, etc.
This could cause some problems.

Since it is working on my ALM 18.3 with OpenJDK, if the issue still persists after this, I'm kind of out of ideas what could cause this behaviour here.
Best Regards,
Patrick Claus

External service provider at Valeo Siemens eAutomotive GmbH
Frauenauracher Str. 85
91056 Erlangen, Germany
Mail Address

drouleau
Posts: 5
Joined: Tue Mar 12, 2019 6:09 pm
Contact:

Re: Porting pre-save JS script to nashorn

Postby drouleau » Mon Mar 18, 2019 4:08 pm

We are running Build: 3.18.0.20180313-2239 not 18.3.


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: Google [Bot] and 13 guests