]> git.basschouten.com Git - openhab-addons.git/commitdiff
[jsscripting] Fix regressions from #14135 & Log stack on `IllegalArgumentException...
authorFlorian Hotze <florianh_dev@icloud.com>
Tue, 3 Jan 2023 19:45:23 +0000 (20:45 +0100)
committerGitHub <noreply@github.com>
Tue, 3 Jan 2023 19:45:23 +0000 (20:45 +0100)
* [jsscripting] Fix bundling of global script & regression from #14135

Fixes the regression from https://github.com/openhab/openhab-addons/pull/14135#issuecomment-1369231126.

While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint).

* [jsscripting] Enable stack logging for IllegalArgumentExceptions
* [jsscripting] Upgrade openhab-js to 3.2.4
* [jsscripting] Update README for recent PR

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
bundles/org.openhab.automation.jsscripting/README.md
bundles/org.openhab.automation.jsscripting/pom.xml
bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java
bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java

index 9d1841b9f96eee6c2022b70acd8f608ff7cde9b7..45f86299f51dd2336aaa08d4530acd9b1f6c9156 100644 (file)
@@ -1,6 +1,6 @@
 # JavaScript Scripting
 
-This add-on provides support for JavaScript (ECMAScript 2021+) that can be used as a scripting language within automation rules.
+This add-on provides support for JavaScript (ECMAScript 2022+) that can be used as a scripting language within automation rules.
 
 Also included is [openhab-js](https://github.com/openhab/openhab-js/), a fairly high-level ES6 library to support automation in openHAB. It provides convenient access
 to common openHAB functionality within rules including items, things, actions, logging and more.
index f51ed442e47e6c67fdeb4672a8ebdfc7592740eb..4817609df8fcc26a64d9c6f2e19760a1d0fc8113 100644 (file)
@@ -24,7 +24,7 @@
     </bnd.importpackage>
     <graal.version>22.0.0.2</graal.version> <!-- DO NOT UPGRADE: 22.0.0.2 is the latest version working on armv7l / OpenJDK 11.0.16 & armv7l / Zulu 17.0.5+8 -->
     <oh.version>${project.version}</oh.version>
-    <ohjs.version>openhab@3.2.1</ohjs.version>
+    <ohjs.version>openhab@3.2.4</ohjs.version>
   </properties>
 
   <build>
               <goal>npm</goal>
             </goals>
             <configuration>
+              <!--suppress UnresolvedMavenProperty -->
               <arguments>install ${ohjs.version} webpack@5.75.0 webpack-cli@4.10.0</arguments> <!-- webpack-cli >= 5.0.0 doesn't properly process the given entrypoint -->
             </configuration>
           </execution>
           <execution>
-            <id>npx webpack</id>
+            <id>npx webpack (openhab-js globals injection)</id>
+            <goals>
+              <goal>npx</goal>
+            </goals>
+            <configuration>
+              <!--suppress UnresolvedMavenProperty -->
+              <arguments>webpack -c ./node_modules/openhab/@globals-webpack.config.js --entry
+                ./node_modules/openhab/@openhab-globals.js -o ./dist</arguments>
+            </configuration>
+          </execution>
+          <execution>
+            <id>npx webpack (openhab-js)</id>
             <goals>
               <goal>npx</goal>
             </goals>
index 3cedaead07ec5b304c7e6e145a92b29438f34bc1..1791a62e81556a5663b12b9598379e4ce8809a77 100644 (file)
@@ -39,6 +39,9 @@ class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable & AutoClosea
     @Override
     public Exception afterThrowsInvocation(Exception e) {
         Throwable cause = e.getCause();
+        if (cause instanceof IllegalArgumentException) {
+            STACK_LOGGER.error("Failed to execute script:", e);
+        }
         if (cause instanceof PolyglotException) {
             STACK_LOGGER.error("Failed to execute script:", cause);
         }
index b9a460147038cc92c559256b874379a1244e0d74..4c64ec76a1a1326570ff5b7c9de4404f8dea6d53 100644 (file)
@@ -71,7 +71,6 @@ public class OpenhabGraalJSScriptEngine
 
     private static final Logger LOGGER = LoggerFactory.getLogger(OpenhabGraalJSScriptEngine.class);
     private static Source GLOBAL_SOURCE;
-
     static {
         try {
             GLOBAL_SOURCE = Source.newBuilder("js", getFileAsReader("node_modules/@jsscripting-globals.js"),
@@ -82,7 +81,6 @@ public class OpenhabGraalJSScriptEngine
     }
 
     private static Source OPENHAB_JS_SOURCE;
-
     static {
         try {
             OPENHAB_JS_SOURCE = Source
@@ -92,7 +90,7 @@ public class OpenhabGraalJSScriptEngine
             throw new RuntimeException("Failed to load @openhab-globals.js", e);
         }
     }
-    private static String OPENHAB_JS_INJECTION_CODE = "Object.assign(this, require('openhab'));";
+    private static final String OPENHAB_JS_INJECTION_CODE = "Object.assign(this, require('openhab'));";
 
     private static final String REQUIRE_WRAPPER_NAME = "__wraprequire__";
     /** Final CommonJS search path for our library */