GraalVM compatibility
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 11 Mar 2019 12:59:48 +0000 (13:59 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 11 Mar 2019 12:59:48 +0000 (13:59 +0100)
org.argeo.cms.e4.rap/cms/app.js
org.argeo.cms.ui/src/org/argeo/cms/script/CmsScriptRwtApplication.java

index 75a9df369f9f13035e13a410438418917ef04470..cd5e099eb408da87303933d2a806a0a45759536e 100644 (file)
@@ -1,8 +1,12 @@
 var AppUi = Java.type('org.argeo.cms.script.AppUi')
-var CmsE4EntryPointFactory = Java.type('org.argeo.cms.e4.rap.CmsE4EntryPointFactory')
+var CmsE4EntryPointFactory = Java
+               .type('org.argeo.cms.e4.rap.CmsE4EntryPointFactory')
 
-APP.webPath = 'cms'
-APP.pageTitle = 'Argeo CMS'
-       
-APP.ui['devops'] = new AppUi(APP, new CmsE4EntryPointFactory('org.argeo.cms.e4/e4xmi/cms-devops.e4xmi'))
-APP.ui['devops'].pageTitle = 'Argeo CMS DevOps'
+APP.setWebPath('cms')
+APP.setPageTitle('Argeo CMS')
+
+APP.getUi().put(
+               'devops',
+               new AppUi(APP, new CmsE4EntryPointFactory(
+                               'org.argeo.cms.e4/e4xmi/cms-devops.e4xmi')))
+APP.getUi().get('devops').setPageTitle('Argeo CMS DevOps')
index 1bc2b0b5a18e9f9b7043363bcc17ee996b680ca3..280213e0570086f257ed6e513b4db162b27a8dd0 100644 (file)
@@ -34,36 +34,42 @@ public class CmsScriptRwtApplication implements ApplicationConfiguration {
                this.bundleContext = bundleContext;
                // System.out.println("bundleContext=" + bundleContext);
                // System.out.println("repository=" + repository);
-               ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
                ClassLoader bundleCl = bundleContext.getBundle().adapt(BundleWiring.class).getClassLoader();
-               ClassLoader currentCcl = Thread.currentThread().getContextClassLoader();
+               ClassLoader originalCcl = Thread.currentThread().getContextClassLoader();
                try {
-                       Thread.currentThread().setContextClassLoader(bundleCl);
+                       Thread.currentThread().setContextClassLoader(bundleCl);// GrallVM needs it to be before creating manager
+                       ScriptEngineManager scriptEngineManager = new ScriptEngineManager(bundleCl);
                        engine = scriptEngineManager.getEngineByName("JavaScript");
+                       if (engine == null) {// Nashorn
+                               Thread.currentThread().setContextClassLoader(originalCcl);
+                               scriptEngineManager = new ScriptEngineManager();
+                               Thread.currentThread().setContextClassLoader(bundleCl);
+                               engine = scriptEngineManager.getEngineByName("JavaScript");
+                       }
+
+                       // Load script
+                       URL appUrl = bundleContext.getBundle().getEntry("cms/app.js");
+                       // System.out.println("Loading " + appUrl);
+                       // System.out.println("Loading " + appUrl.getHost());
+                       // System.out.println("Loading " + appUrl.getPath());
+
+                       CmsScriptApp app = new CmsScriptApp(engine);
+                       engine.put(APP, app);
+                       engine.put(BC, bundleContext);
+                       try (Reader reader = new InputStreamReader(appUrl.openStream())) {
+                               engine.eval(reader);
+                       } catch (IOException | ScriptException e) {
+                               throw new CmsException("Cannot execute " + appUrl, e);
+                       }
+
+                       if (log.isDebugEnabled())
+                               log.debug("CMS script app initialized from " + appUrl);
+
                } catch (Exception e) {
                        e.printStackTrace();
                } finally {
-                       Thread.currentThread().setContextClassLoader(currentCcl);
-               }
-
-               // Load script
-               URL appUrl = bundleContext.getBundle().getEntry("cms/app.js");
-               // System.out.println("Loading " + appUrl);
-               // System.out.println("Loading " + appUrl.getHost());
-               // System.out.println("Loading " + appUrl.getPath());
-
-               CmsScriptApp app = new CmsScriptApp(engine);
-               engine.put(APP, app);
-               engine.put(BC, bundleContext);
-               try (Reader reader = new InputStreamReader(appUrl.openStream())) {
-                       engine.eval(reader);
-               } catch (IOException | ScriptException e) {
-                       throw new CmsException("Cannot execute " + appUrl, e);
+                       Thread.currentThread().setContextClassLoader(originalCcl);
                }
-
-               if (log.isDebugEnabled())
-                       log.debug("CMS script app initialized from " + appUrl);
-
        }
 
        public void destroy(BundleContext bundleContext) {