Re: PL/Java new build plugin

From: Chapman Flack <chap(at)anastigmatix(dot)net>
To: Kartik Ohri <kartikohri13(at)gmail(dot)com>
Cc: pljava-dev(at)lists(dot)postgresql(dot)org
Subject: Re: PL/Java new build plugin
Date: 2020-07-21 03:45:09
Message-ID: 5F1664C5.2070700@anastigmatix.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

On 07/20/20 22:51, Kartik Ohri wrote:
>> <script engine="nashorn">...</script>
>>
> It is possible to have this syntax. We need to specify an executionID in
> the executionBlock for that. In the plugin, we can get the entire
> configuration XML as a Plexus Xpp3Dom object from which we can retrieve the
> attribute from any element. I'll add this. What attribute should be used
> though mimetype or engine or allow both and give engine precedence over
> mimetype ?

I like allowing both; giving engine preference, or just complaining if
both are specified. (Or, if both are specified, look up by engine, then
complain if its mimetypes don't include mimetype.)

By the way, when allowing an attribute to specify the script language,
it then becomes trickier to make functions available to the script
by eval'ing function definitions for them, as the mojo now does; if
those are in JavaScript and somebody wants to write a script block
in Tcl, that'll be trouble. (Not that I have any actual plans to add
Tcl scripts to this build, but....)

The ScriptEngineFactory has useful methods getMethodCallSyntax and
getOutputStatement, but it doesn't really have a
"getWholeFunctionDeclaration" method to help out there.

What I have found does work with Nashorn (haven't tried it with Graal yet)
is just engine.put (or getContext().setAttribute()), passing a functional
interface instance, e.g.:

engine.put("quoteStringForC",
(Function<String,String>)PGXSUtils::quoteStringForC);

I'm not sure that works with every script engine out there (but then
again, neither would defining the functions as JavaScript). If it does
work with both Nashorn and Graal, it seems the cleanest way.

Regards,
-Chap

In response to

Responses

Browse pljava-dev by date

  From Date Subject
Next Message Kartik Ohri 2020-07-21 18:03:30 Re: PL/Java new build plugin
Previous Message Chapman Flack 2020-07-21 03:25:17 Re: PL/Java new build plugin