archimatetool / archi-scripting-plugin

jArchi - Scripting for Archi: ArchiMate Modelling Tool
https://www.archimatetool.com
118 stars 33 forks source link

Nashorn ES6 to GraalVM script error #88

Closed JoCriSem closed 3 years ago

JoCriSem commented 3 years ago

Version of jArchi, Operating System

Archi 4.8.0 - jArchi 1.0.0 - MacOS 11.1

Actions taken

Changed Javascript engine from Nashorn ES6 to GraalVM, ran the below script.

Expected behaviour

Script execution successful, as with Nashorn ES6

Observed behaviour

received error: Script Error: javax.script.ScriptException: org.graalvm.polyglot.PolyglotException: TypeError: undefined has no such function "setAsCurrent"

Script executed

/*
 * Setting the Jasper Reporting properties for the selected model
 * Setting the model property on true will not include the details of that category in the report
 */

var version = "1.0";
var scriptname = "SetModelReportingProperties";
var debug = true;

console.clear();
print("Setting the Jasper Reporting properties for the selected model");
console.log("Applied script "+scriptname+" - version "+version);
debug? console.log("debugging is on !!"):true;

//set properties
var msg = "Which of the loaded models is the destination (enter its index)?";
var modelList = $.model.getLoadedModels();

for (i = 0; i < modelList.length; i++) {
    msg += "\n (" + i + ") " + modelList[i];
}

var answer = window.prompt(msg, "");

if (!answer) {
    console.log("no model chosen");
} else {

    model = modelList[answer];
    model.setAsCurrent();
    modelname = model.name;

        model.prop("Report:Model:Hide:Strategy","true");
    model.prop("Report:Model:Hide:Business","true");
    model.prop("Report:Model:Hide:Application","true");
    model.prop("Report:Model:Hide:Technology&Physical","true");
    model.prop("Report:Model:Hide:Motivation","true");
    model.prop("Report:Model:Hide:Implementation&Migration","true");
    model.prop("Report:Model:Hide:Other","true");
    model.prop("Report:Model:Hide:Relations","true");
    model.prop("Report:Model:Hide:Views","false");
    model.prop("Report:Model:Hide:ViewNumbering","true");

    console.log("Model Jasper Reporting Properties Set");
}
Phillipus commented 3 years ago

This returns a string type:

var answer = window.prompt(msg, "");

It seems that GraalVM does not convert string to int types in the array index - modelList[answer]

So you need to convert answer to an int first:

answer = parseInt(answer);

This is a GraalVM thing, so there's nothing I can do about it. GraalVM support is experimental and will require some changes in one's JS code.

jbsarrodie commented 3 years ago

This is a GraalVM thing, so there's nothing I can do about it. GraalVM support is experimental and will require some changes in one's JS code.

I think we should make it clearer that GraalVM is not meant to be one-to-one compatible with existing scripts nor current API.

Phillipus commented 3 years ago

I think we should make it clearer that GraalVM is not meant to be one-to-one compatible with existing scripts nor current API.

Well, I tried to in the forum post (https://forum.archimatetool.com/index.php?topic=951.0). I imagine that even if we made this clearer in the wiki I'm not sure people will read it.

JoCriSem commented 3 years ago

I did read that though. But was clueless on how to resolve this. It is working properly now. Thank you.

jbsarrodie commented 3 years ago

I imagine that even if we made this clearer in the wiki I'm not sure people will read it.

It might be worth displaying a red message on the Script Console each time a script is ran using GraalVM ;-)