Re: unable to use javascript ScriptEngine in pipeline step implementation

2016-08-18 Thread Jesse Glick
On Thu, Aug 18, 2016 at 2:30 PM, Chris Price  wrote:
> Is there any specific classloader you'd recommend for use in a plugin
> context?

Not really. That of some class in your plugin? Of some class in
Jenkins core? The parent of that of some class in Jenkins core? You
really need to poke in a debugger and see *why* it is not loading the
standard implementations.

> any idea why it would work OK in the tests?

The context loader is probably different, and anyway your plugin
classes are being loaded in a different loader.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr2j4RXRVgfRzqTwkAizpxeoeYjhmFm2iJoac%3DdbWEcv8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: unable to use javascript ScriptEngine in pipeline step implementation

2016-08-18 Thread Chris Price


On Thursday, August 18, 2016 at 10:54:41 AM UTC-7, Jesse Glick wrote:
>
> On Thu, Aug 18, 2016 at 12:55 PM, Chris Price  > wrote: 
> > ScriptEngineManager manager = new ScriptEngineManager(); 
>
> Probably your `Thread.currentThread().getContextClassLoader()` is not 
> able to “see” the JRE’s engines for some reason a debugger might 
> illuminate. Try using the constructor taking an explicit 
> `ClassLoader`. 
>

Is there any specific classloader you'd recommend for use in a plugin 
context?  Also, any idea why it would work OK in the tests?  Seems like 
there is an implication that the classloader will be swapped out by Jenkins 
when running inside the live server, so I'm not quite sure how to get a 
reference to a better classloader in that context?
 

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/ea077b20-4aca-4bd5-889b-4f03473da6e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: unable to use javascript ScriptEngine in pipeline step implementation

2016-08-18 Thread Jesse Glick
On Thu, Aug 18, 2016 at 12:55 PM, Chris Price  wrote:
> ScriptEngineManager manager = new ScriptEngineManager();

Probably your `Thread.currentThread().getContextClassLoader()` is not
able to “see” the JRE’s engines for some reason a debugger might
illuminate. Try using the constructor taking an explicit
`ClassLoader`.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1g501yGfAKNZzsNdZ4K8-MEU4Q6ykAt%3DPMnhsnY2i0ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


unable to use javascript ScriptEngine in pipeline step implementation

2016-08-18 Thread Chris Price
Hi,

I have a custom pipeline step I'm writing (in Java, implementing workflow
Step/StepExecution).  Inside of my step's implementation I need to load
some JavaScript code.  I started off with this approach:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");

I have some tests that I've written that use the
JenkinsRule/CpsFlowDefinition pattern (basically used
workflow-basic-steps-plugin as the example).  In these tests, the lines of
code above work just fine.  (They seem to work fine in either JDK7, where I
get an instance of a Rhino javascript engine, or in JDK8 where I get a
Nashorn one.)

However, after I got those working, I ran `mvn hpi:run` to spin up the GUI,
and went in and created a pipeline job that called the same custom step,
and in this context, the ScriptEngine ends up being `null`.  Stepping with
a debugger and looking into the ScriptEngineManager, I can see that it
contains a ScriptEngine for groovy, but nothing else.  This happens in both
JDK7 and JDK8, even if I've explicitly added a maven dependency on Rhino.
So it seems like Jenkins is manipulating the ScriptEngineManager before
calling plugins somehow... perhaps?

I modified my code to call into the Rhino API explicitly; this, coupled
with the explicit maven dep on Rhino, seems to work fine in both test and
hpi:run context.  This workaround is probably sufficient for my needs for
now, but I wanted to at least share the issue that I ran into in case it is
not intended / expected behavior, and should perhaps be filed as a bug?

Thanks
Chris

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/CAMx1QfL22RWt8HUsb6AXFhCVLOoB7aLsJJBEzK5G1sFSeMjtYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.