Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "JSDT/Equinox hook for Nashorn"

(Added initial description of Nashorn Hook)
 
(Added more info)
Line 1: Line 1:
 +
=== Nashorn in lib/ext ===
 
Nashorn is a Javascript runtime library, available from Java 8+ in the <java-home>/lib/ext folder.
 
Nashorn is a Javascript runtime library, available from Java 8+ in the <java-home>/lib/ext folder.
  
Line 5: Line 6:
 
As JSDT.core is using Nashorn, the JSDT team elaborated a way to load this external lib.
 
As JSDT.core is using Nashorn, the JSDT team elaborated a way to load this external lib.
  
==== '''Hooking Nashorn in different stages''' ====
+
==== '''Hooking Nashorn at Runtime''' ====
'''At runtime''': we have the  <code>org.eclipse.wst.jsdt.nashorn.extension</code> plug-in fragment, which contains a class extending <code>ClassLoaderHook</code>, which give the option to extend the bundle classpath by adding the '''lib/ext''' folder.
+
'''At runtime,''' we have the  <code>org.eclipse.wst.jsdt.nashorn.extension</code> plug-in fragment, which contains a class extending <code>ClassLoaderHook</code>, which give the option to extend the bundle classpath by adding the '''lib/ext''' folder.
  
 
To activate the ''ClassLoaderHook'' you need to add the following param to t he launch configuration:
 
To activate the ''ClassLoaderHook'' you need to add the following param to t he launch configuration:
Line 14: Line 15:
 
Practically: you will need to add the parameter to your running configuration or to your product configuration to have it working at a runtime.
 
Practically: you will need to add the parameter to your running configuration or to your product configuration to have it working at a runtime.
  
'''In testing at development time, and in local Tycho build''': you will need to specify a parameter to tell the Equinox classloader to load the normal Java extension classloader to load the normal Java extension classloader.
+
==== Hooking Nashorn in Dev, Test and Build ====
 +
In testing at development time, and in local Tycho build you will need to specify a parameter to tell the Equinox classloader to load the normal Java extension classloader to load the normal Java extension classloader.
  
 
For this you will need to use the following param:
 
For this you will need to use the following param:
Line 24: Line 26:
 
<code><argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine></code>  
 
<code><argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine></code>  
  
See also
+
=== Override the createClassloader ===
* [https://books.google.nl/books?id=xyffdhEOlAcC&pg=PT497&dq=java+boot+class+loader+OSGi&hl=en&sa=X&ved=0ahUKEwjAycHsw-nLAhVBYA4KHSf3CS8Q6AEIJjAA#v=onepage&q=java%20boot%20class%20loader%20OSGi&f=false OSGi and Equinox: Creating Highly Modular Java Systems, Chap 23.9]
+
The override is made in two bundles:
 +
* '''org.eclipse.wst.jsdt.core''' : that depends on extension and imports extension.loader
 +
* '''org.eclipse.wst.jsdt.nashorn.extension''' : fragment, containing a class that extends Hook
 +
See the wiki page explaining the
 +
 
 +
The hook is implemented in the '''extension''' bundle, by the NashornLoaderHook class, which  extends ClassLoaderHook. (more details on framework hooks here: https://wiki.eclipse.org/Adaptor_Hooks)
 +
 
 +
In our implementation, the class checks for which parent bundle is loading the extension bundle, and when the bundle is JSDT.core, we extend the classpath.
 +
 
 +
==== Activate Equinox Hook ====
 +
Equinox looks in every fragment for classes extending the Hook and calls the methods overriding the API, only when a specific parameter is effective.
 +
 
 +
===== Runtime =====
 +
So, At runtime, the eclipse configuration needs the parameter below to be effective
 +
  -Dosgi.framework.extensions=org.eclipse.wst.jsdt.nashorn.extension
 +
be effective
 +
 
 +
===== EPP, Build, Dev and Test =====
 +
Also when running the EPP Packaging we need this param in the product configuration.
 +
 
 +
The same is in testing, at development time and in local Tycho build.
 +
 
 +
To avoid issues with Tycho reactor, there is the option to use a different parameter from Equinox, to specify an external classloader. This is not standard in OSGi, so we can not use it at runtime.
 +
-Dorg.osgi.framework.bundle.parent=ext
 +
 
 +
===== Tyhco =====
 +
In '''webtools.jsdt\tests\pom.xml''', you see the arg.line which allow Tycho to run tests during the build, and the same trick can be used during the build.
 +
<argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine>
 +
“Look in the bundle parent classloader, which includes the lib/ext that are not in the boot classloader that is the default for OSGi”
 +
 
 +
==== Notes: ====
 +
* This is how it works in M6. We’re not really happy of this, as there are other options, TBC
 +
* See also: [https://books.google.nl/books?id=xyffdhEOlAcC&pg=PT497&dq=java+boot+class+loader+OSGi&hl=en&sa=X&ved=0ahUKEwjAycHsw-nLAhVBYA4KHSf3CS8Q6AEIJjAA#v=onepage&q=java%20boot%20class%20loader%20OSGi&f=false OSGi and Equinox: Creating Highly Modular Java Systems, Chap 23.9]

Revision as of 11:52, 5 April 2016

Nashorn in lib/ext

Nashorn is a Javascript runtime library, available from Java 8+ in the <java-home>/lib/ext folder.

Eclipse plug-ins are OSGi bundles which, by default, are using the "boot class loader", which excludes the lib/ext

As JSDT.core is using Nashorn, the JSDT team elaborated a way to load this external lib.

Hooking Nashorn at Runtime

At runtime, we have the org.eclipse.wst.jsdt.nashorn.extension plug-in fragment, which contains a class extending ClassLoaderHook, which give the option to extend the bundle classpath by adding the lib/ext folder.

To activate the ClassLoaderHook you need to add the following param to t he launch configuration:

-Dosgi.framework.extensions=org.eclipse.wst.jsdt.nashorn.extension

Practically: you will need to add the parameter to your running configuration or to your product configuration to have it working at a runtime.

Hooking Nashorn in Dev, Test and Build

In testing at development time, and in local Tycho build you will need to specify a parameter to tell the Equinox classloader to load the normal Java extension classloader to load the normal Java extension classloader.

For this you will need to use the following param:

-Dorg.osgi.framework.bundle.parent=ext

Practically you will need to add the param to your test configuration, and in your tycho configuration. As an example check the webtools.jsdt\tests\pom.xml, where you can see the argline passes to maven:

<argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine>

Override the createClassloader

The override is made in two bundles:

  • org.eclipse.wst.jsdt.core : that depends on extension and imports extension.loader
  • org.eclipse.wst.jsdt.nashorn.extension : fragment, containing a class that extends Hook

See the wiki page explaining the

The hook is implemented in the extension bundle, by the NashornLoaderHook class, which extends ClassLoaderHook. (more details on framework hooks here: https://wiki.eclipse.org/Adaptor_Hooks)

In our implementation, the class checks for which parent bundle is loading the extension bundle, and when the bundle is JSDT.core, we extend the classpath.

Activate Equinox Hook

Equinox looks in every fragment for classes extending the Hook and calls the methods overriding the API, only when a specific parameter is effective.

Runtime

So, At runtime, the eclipse configuration needs the parameter below to be effective

 -Dosgi.framework.extensions=org.eclipse.wst.jsdt.nashorn.extension

be effective

EPP, Build, Dev and Test

Also when running the EPP Packaging we need this param in the product configuration.

The same is in testing, at development time and in local Tycho build.

To avoid issues with Tycho reactor, there is the option to use a different parameter from Equinox, to specify an external classloader. This is not standard in OSGi, so we can not use it at runtime.

-Dorg.osgi.framework.bundle.parent=ext
Tyhco

In webtools.jsdt\tests\pom.xml, you see the arg.line which allow Tycho to run tests during the build, and the same trick can be used during the build.

<argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine>

“Look in the bundle parent classloader, which includes the lib/ext that are not in the boot classloader that is the default for OSGi”

Notes:

Back to the top