Commit Graph

66 Commits

Author SHA1 Message Date
Florian Hotze
931f004ab8
[jsscripting] Upgrade to ECMAScript 2022 & Dependency improvements (#14093)
* [jsscripting] Remove asm from dependencies in pom

GraalJS >= 20.3.0 doesn't require org.ow2.asm as compile dependency anymore, see https://mvnrepository.com/artifact/org.graalvm.js/js/20.3.0.

* [jsscripting] Remove dependency org.graalvm.js/js-launcher as it is not required

js-launcher is GraalVM's JavaScript command line interpreter and not required in the addon.
See https://www.graalvm.org/22.1/reference-manual/js/RunOnJDK/.

* [jsscripting] Add missing com.ibm.icu dependency

GraalJS changelog says that it is not required for GraalJS >= 22.0.0 (see 685e5873af/CHANGELOG.md (version-2200)).
But GraalJS 22.3.0 attempts to load classes from it during runtime.

* [jsscripting] Update GraalJS engine options

Compat, as its additional functionality is not used by openhab-js and user code is not expected to use it.

* [jsscripting] Remove com.ibm.icu/icu4j dependency
* [jsscripting] Don't disable Nashorn compat mode as openhab-js requires it for accessors

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-30 23:04:43 +01:00
Florian Hotze
895defda8e
[jsscripting] Use application/javascript as MIME type (#14096)
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-29 21:01:22 +01:00
Florian Hotze
4d98cca7eb
[jsscripting] Minor fixes & improvements (#13960)
* [jsscripting] Correct wrong `createScriptEngine` implementation
* [jsscripting] Also unlock lock on unexpected exceptions (rethrow them)
* [jsscripting] Call super methods from their overrides
* [jsscripting] Move superclass call of `beforeInvocation`

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-20 09:15:43 +01:00
J-N-K
4d6d6443ef
fix spotless after release (#14014)
Signed-off-by: Jan N. Klug <github@klug.nrw>
2022-12-19 15:22:17 +01:00
openhab-bot
7993786dc9 [unleash-maven-plugin] Preparation for next development cycle. 2022-12-19 00:55:11 +00:00
openhab-bot
d20b10317c
New Crowdin updates (#13990)
* New translations tr064.properties (German)
* New translations jsscripting.properties (Danish)
* New translations jsscripting.properties (Italian)
2022-12-17 16:51:35 +01:00
Florian Hotze
11e2c4fc31
[jsscripting] Update add-on name in default translation (#13984)
Leftover from #13764.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-17 13:40:12 +01:00
openhab-bot
4a13e1a68f
New Crowdin updates (#13971)
* New translations knx.properties (German)
* New translations yamahamusiccast.properties (German)
* New translations hdpowerview.properties (Danish)
* New translations jsscripting.properties (Danish)
2022-12-17 12:13:24 +01:00
openhab-bot
d6db72774a
New Crowdin updates (#13962)
* New translations chromecast.properties (Italian)
* New translations sonos.properties (Italian)
* New translations exec.properties (Italian)
* New translations knx.properties (German)
* New translations jsscripting.properties (German)
* New translations yamahamusiccast.properties (German)
2022-12-15 23:36:49 +01:00
Wouter Born
6e8b35c4c1
[jsscripting] Fix broken event object table (#13952)
The table is not properly rendered when reading the documentation in Main UI.

Signed-off-by: Wouter Born <github@maindrain.net>
2022-12-15 07:51:22 +01:00
Florian Hotze
d4ec220925
[jsscripting] Extend synchronization to common ScriptEngine methods (#13924)
* [jsscripting] Extend synchronization to common ScriptEngine methods

This extends the multi-thread synchronization to "eval" and "invokeMethod" and moves synchronization for "invokeFunction" to the DelegatingScriptEngineWithInvocableAndAutocloseableAndSynchronization class. Fixes the multi-thread access requested warnings described in the community (https://community.openhab.org/t/openhab-3-4-milestone-discussion/138093/130) and related to https://github.com/openhab/openhab-core/pull/3180.

* Revert "[jsscripting] Extend synchronization to common ScriptEngine methods"

This reverts commit aadd21e45879c10aad29bf279ddbb0afd789b0aa.

* [jsscripting] Extend synchronization to common ScriptEngine methods & Switch to ReentrantLock

This extends the multi-thread synchronization to "eval" and "invokeMethod" and moves synchronization for "invokeFunction" to the InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable class.
The synchronization mechanism changed from using synchronized to using a ReentrantLock together with catch_finally to avoid having deadlocks when an exception is thrown.
Fixes the multi-thread access requested warnings described in the community (https://community.openhab.org/t/openhab-3-4-milestone-discussion/138093/130) and related to https://github.com/openhab/openhab-core/pull/3180.

* [jsscripting] Reduce compiler warnings
* [jsscripting] Replace finally blocks & Wrap returns in afterInvocation
* [jsscripting] Fix deadlock caused by NoSuchMethodException in Invocable interface methods

During testing my latest changes, I noticed that there is a deadlock when invokeFunction or invokeMethod are called on a non-existing method.
This happens because the NoSuchMethodException keeps afterInvocation from running and therefore the lock never gets released.

* [jsscripting] Also rethrow NPE & Fix PMD warnings/errors
* [jsscripting] Wrap and rethrow other exceptions instead of returning them
* [jsscripting] Address review comment from @jpg0

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-14 20:12:54 +01:00
Florian Hotze
438552d485
[jsscripting] Upgrade openhab-js & Remove SharedCache (#13908)
Upgrades the included openhab-js version to 3.1.0, which uses the new
caches from core (introduced in
https://github.com/openhab/openhab-core/pull/2887) and provides many
doc improvements.

Removes the SharedCache from the addon because this functionality is
now provided by core (see
https://github.com/openhab/openhab-core/pull/2887).

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-11 15:25:39 +01:00
Florian Hotze
a9d4244fd8
[jsscripting] Fix "Error removing engine" context already closed (#13855)
In recent PR #13824, I added closing the context when the engine is closed, but core seems to have problems with that.

It logs: "[ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error removing ScriptEngine
java.lang.IllegalStateException: The Context is already closed."

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-06 13:15:47 +01:00
Florian Hotze
bf48eccf8c
[jsscripting] Refactor log formatting & Respect toString polyfills (#13844)
* [jsscripting] Refactor log formatting & Respect toString polyfills
* [jsscripting] Catch errors in log formatting & Improve handling of Java obj
* [jsscripting] Update log format failure message

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-05 20:46:17 +01:00
Florian Hotze
54b2772df4
[jsscripting] Add an alternative MIME type/alias (#13851)
The alternative MIME type text/javascript is also used by Nashorn, therefore we add the same extension as for the main MIME type.
The alias is introduced to simplify the usage in SCRIPT transformation profiles.

* Fix syntax problems in the bndtools file
* Add null check to avoid potential NPE
  In some cases during testing, a NPE occured, this should solve it.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-05 18:40:15 +01:00
Florian Hotze
42b8505bef
[jsscripting] Fix memory leak that crashes openHAB (#13824)
* [jsscripting] Fix memory-leak caused by com.oracle.truffle.host.HostObject

Fixes this memory leak by making the HostAccess for the GraalJSScriptEngine available in a static final variable instead of creating it for each new engine.
Solution proposed in https://github.com/oracle/graaljs/issues/121#issuecomment-690179954.

Sharing a single engine across all Contexts (as proposed in https://github.com/oracle/graaljs/issues/121#issuecomment-880056648) is not possible, because core expects a ScriptEngine.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [jsscripting] Update JavaDoc

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

* [jsscripting] Close `GraalJSScriptEngine` when `OpenhabGraalJSScriptEngine` is closed

My breakpoint inside the close method of GraalJSScriptEngine did not trigger until this change was made.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-12-03 00:17:39 +01:00
Дилян Палаузов
6c1373f7c2
Typos a/an (#13819) 2022-12-02 13:07:31 +01:00
J-N-K
ae677dcd9d
[jsscripting] Refactor dependency tracking (#13756)
Signed-off-by: Jan N. Klug <github@klug.nrw>
2022-11-29 21:59:58 +01:00
Florian Hotze
29d2578981
[jsscripting] Fix add-on name in feature/pom (#13764)
* Update pom.xml
* Update feature.xml
* [jsscripting] Rename from JSScripting to JavaScript Scripting

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-11-24 23:23:19 +01:00
Florian Hotze
bfff07bb01
[jsscripting] Reimplement timer creation method of ScriptExecution (#13695)
* [jsscripting] Refactor ThreadsafeTimers to create futures inline instead of in an extra methods
* [jsscripting] Introduce utility class for providing easy access to script services
* [jsscripting] Reimplement timer creation methods from ScriptExecution for thread-safety
* [jsscripting] Add missing JavaDoc for reimplement timer creation methods
* [jsscripting] Remove the future from the map when setTimeout expires
* [jsscripting] Rename `GraalJSScriptServiceUtil` to `JSScriptServiceUtil`
* [jsscripting] Remove the `createTimerWithArgument` method
* [jsscripting] Replace the OSGi workaround of `JSScriptServiceUtil` with an injection mechanism
* [jsscripting] Use constructor to inject `JSScriptServiceUtil` into `GraalJSScriptEngineFactory`
* [jsscripting] Minor improvements by @J-N-K (#1)
* [jsscripting] Minor changes related to last commit to keep flexibility of `JSRuntimeFeatures`
* [jsscripting] Upgrade openhab-js to v2.1.1
* [jsscripting] Remove unused code

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Co-authored-by: Jan N. Klug <github@klug.nrw>
2022-11-20 22:08:19 +01:00
Florian Hotze
103619741d
[jsscripting] Fix the console.trace polyfill to log a stack trace & Stringify JS Error (#13749)
* [jsscripting] Fix the `console.trace` polyfill to log a stack trace & Stringify JS `Error`
* [jsscripting] Add myself to the codeowners

Fixes #12646

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-11-20 20:30:42 +01:00
Florian Hotze
4dde19203a
[jsscripting] Fix maven build (#13747)
This fixed the maven build, that fails because webpack-cli version 5.0.0 doesn’t properly process the given entrypoint.
Instead, webpack tries to use the entrypoint from openhab-js‘ webpack config file.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-11-20 17:30:23 +01:00
Florian Hotze
11d3c641e5
[jsscripting] Fix failure on some platforms & JDKs (#13714)
* [jsscripting] Downgrade GraalVM to fix issue with armv7l & OpenJDK 11.0.16

The community reported several cases where JS Scripting was not working due to some issue with the injection of the global script.
This issue seems to only occur on armv7l (e.g. Raspberry Pi 32bit) and OpenJDK 11.0.16.
Investigation showed that the occurrence of the problem depends on the GraalJS version.

See https://community.openhab.org/t/js-scripting-all-scripts-stop-working-when-upgrading-to-3-4-0-m4/140837.

* [jsscripting] Add logging for injection of JSRuntimeFeatures
* [jsscripting] Lint `@jsscripting-globals.js` with semistandard
* [jsscripting] Remove ICU4J as it moved to `org.graalvm.truffle`

Reference f5661d4655/CHANGELOG.md (version-2200).

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-11-14 20:30:44 +01:00
Florian Hotze
b0d4f5a5fd
[jsscripting] Update openhab-js version to 2.1.0 (#13664)
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-11-06 20:15:10 +01:00
Florian Hotze
51d3fc211a
[jsscripting] Reimplement timer polyfills to conform standard JS (#13623)
* [jsscripting] Reimplement timers to conform standard JS
* [jsscripting] Name scheduled jobs by loggerName + id
* [jsscripting] Update timer identifiers
* [jsscripting] Update identifiers for scheduled jobs
* [jsscripting] Synchronize method that is called when the script is reloaded
* [jsscripting] Cancel all scheduled jobs when the engine is closed
* [jsscripting] Ensure that a timerId is never reused by a subsequent call & Use long primitive type instead of Integer
* [jsscripting] Use an abstraction class to inject features into the JS runtime
* [jsscripting] Make ThreadsafeTimers threadsafe for concurrent access to the class itself
* [jsscripting] Move the locking for `invokeFunction` to `OpenhabGraalJSScriptEngine`

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-11-05 15:26:46 +01:00
Florian Hotze
eda5a562a0
[jsscripting] Name timers created by polyfills (#13576)
* [jsscripting] Name timers created by polyfills

Fixes #13478.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-10-24 23:40:44 +02:00
Florian Hotze
cf47dc0f39
[jsscripting] Fix multi-thread access (#13582)
* [jsscripting] Share the lock mechanism that was used only for rules
This change moves the lock object that was originally created for ThreadsafeSimpleRuleDelegate to OpenhabGraalJSScriptEngine to make share it across the whole engine.

* [jsscripting] Inject the lock object into the JS runtime
* [jsscripting] Update `setTimeout` & `setInterval` polyfills to enable threadsafety
* [jsscripting] Upgrade GraalJS from 21.3.0 to 22.3.0
* [jsscripting] Reduce compiler warnings
* [jsscripting] Update node version of frontend-maven-plugin

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-10-24 13:35:33 +02:00
Florian Hotze
bdefe17f08
[jsscripting] Upgrade openhab-js to 2.0.4 (#13565)
Fixes #13563.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-10-18 22:34:33 +02:00
openhab-bot
936365031c
New Crowdin updates (#13542)
* New translations adorne.properties (Italian)
* New translations knx.properties (German)
* New translations jsscripting.properties (Italian)
2022-10-13 14:35:26 +02:00
Florian Hotze
39d221d3a8
[jsscripting] Update openhab-js to 2.0.3 (#13385)
* [jsscripting] Update openhab-js to 2.0.3
* [jsscripting] Update README

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-09-13 21:57:09 +02:00
Kai Kreuzer
440f603e88
Apply spotless and resolver (#13027)
Signed-off-by: Kai Kreuzer <kai@openhab.org>
2022-06-27 16:00:37 +02:00
openhab-bot
ed4858ebbb [unleash-maven-plugin] Preparation for next development cycle. 2022-06-26 18:18:40 +00:00
Florian Hotze
b2087e3807
[jsscripting] Upgrade openhab-js to version 2.0.0 (#12945)
* Bump openhab-js version to 2.0.0
* Update README for current openhab-js version
* README: Fix paths to images

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
2022-06-18 13:24:05 +02:00
Jonathan Gilbert
bdfe999bca
Removed ClassExtender as it's no longer used and may be leaking memory (#12725)
Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
2022-05-12 23:08:40 +02:00
Daniel Lienert
47418606c6
DOCS: Add missing bracket (#12722) 2022-05-12 07:40:48 +02:00
Дилян Палаузов
6451afae5c
automation.jsscripting/README: hypelink (#12638) 2022-04-22 15:29:26 +02:00
Дилян Палаузов
e44eb7d679
automation.jsscripting/README: typo (#12637) 2022-04-22 15:28:10 +02:00
Wouter Born
b3ade70e29
Fix SAT MarkdownCheck image location findings (#12591)
This fixes all the MarkdownCheck "Images must be located in the doc/ folder." findings.

Fixes #12590

Signed-off-by: Wouter Born <github@maindrain.net>
2022-04-09 16:56:13 +02:00
Dan Cunningham
a0920d4c0c
[jsscripting] Append the ruleID or file name to the logger when console logging (#11945)
* Appends the ruleID or file name to the logger when console logging.
* Adds configurable logging, updates scriptId logic

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
2022-01-31 11:55:50 +01:00
Dan Cunningham
00da156b1b
[jsscripting] Updates to latest openhab-js library (#12171)
* Updates to latest openhab-js library
* Update for new default log level in 3.3

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
2022-01-30 18:28:58 +01:00
Jonathan Gilbert
6bd37cb02a
[jsscripting] JS script engine no longer watches node_modules for scripts (#11830)
Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
2022-01-23 11:46:13 +01:00
Richard Koshak
df7d111bce
changedSince returns a boolean, not a Number (#12079) 2022-01-20 16:51:39 +01:00
Jonathan Gilbert
4d88ad06ae
[jsscripting] Wrapped GraalJS ScriptEngines now also Autocloseable (#12022)
Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
2022-01-15 17:44:15 +01:00
Hilbrand Bouwkamp
da59cdd255
Update license headers to 2022 (#11973)
Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
2022-01-06 18:14:47 +01:00
Markus Lipp
dba4b0088f
[jsscripting] Fixed links to JS-Joda (#11950)
Fixed path to JS-Joda github page to be formatter as external links
2022-01-03 13:52:05 +01:00
openhab-bot
c23f6adf13
New Crowdin updates (#11832)
* New translations astro.properties (Finnish)
* New translations astro.properties (German)
* New translations bluetooth.properties (German)
* New translations boschshc.properties (Italian)
* New translations comfoair.properties (German)
* New translations dwdunwetter.properties (German)
* New translations epsonprojector.properties (German)
* New translations gpio.properties (German)
* New translations heliosventilation.properties (German)
* New translations homeconnect.properties (German)
* New translations homematic.properties (German)
* New translations ipp.properties (German)
* New translations jruby.properties (Hungarian)
* New translations jsscripting.properties (German)
* New translations jsscripting.properties (Hungarian)
* New translations map.properties (German)
* New translations map.properties (Hungarian)
* New translations mqttbroker.properties (Italian)
* New translations nanoleaf.properties (German)
* New translations ocean.properties (German)
* New translations openhabcloud.properties (Finnish)
* New translations samsungtv.properties (Hungarian)
* New translations shelly.properties (German)
* New translations snmp.properties (German)
* New translations sonos.properties (German)
* New translations spotify.properties (German)
* New translations tr064.properties (German)
* New translations tradfri.properties (German)
* New translations unifi.properties (German)
* New translations unifi.properties (Hungarian)
* New translations valloxmv.properties (Finnish)
* New translations volvooncall.properties (German)
* New translations xslt.properties (German)
2021-12-29 13:16:52 +01:00
Marcel
cc47ef7f3e
pom update from http to https reference (#11833)
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
2021-12-23 19:40:44 +01:00
Dan Cunningham
ec10dfe897
[jsscripting] Update docs and refactor path (#11827)
This adds a minor refactoring of loading local resource paths that i didn't have time to get into 3.2  and moves the docs directory to doc.

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
2021-12-21 23:36:22 +01:00
Michael Aschenborn
8ea76db693
Update README.md (#11836)
missing )
2021-12-21 18:39:32 +01:00
Kai Kreuzer
48746f5e3f Apply spotless
Signed-off-by: Kai Kreuzer <kai@openhab.org>
2021-12-20 09:07:55 +01:00