Skip to content

Commit 8c68fb7

Browse files
authored
[jsscripting] Use OSGi-ified GraalVM dependencies (openhab#18053)
* [jsscripting] Use OSGI-ified org.graalvm.sdk:* dependencies Signed-off-by: Florian Hotze <[email protected]>
1 parent 01cb892 commit 8c68fb7

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

bundles/org.openhab.automation.jsscripting/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JavaScript Scripting
22

3-
This add-on provides support for JavaScript (ECMAScript 2022+) that can be used as a scripting language within automation rules.
3+
This add-on provides support for JavaScript (ECMAScript 2024+) that can be used as a scripting language within automation rules.
44
It is based on [GraalJS](https://www.graalvm.org/javascript/) from the [GraalVM project](https://www.graalvm.org/).
55

66
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

bundles/org.openhab.automation.jsscripting/bnd.bnd

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ Require-Capability:
77
osgi.serviceloader:=
88
filter:="(osgi.serviceloader=org.graalvm.polyglot.impl.AbstractPolyglotImpl)";
99
cardinality:=multiple
10+
Require-Bundle: org.graalvm.sdk.collections;bundle-version="24.1.2",\
11+
org.graalvm.sdk.jniutils;bundle-version="24.1.2",\
12+
org.graalvm.sdk.nativeimage;bundle-version="24.1.2",\
13+
org.graalvm.sdk.word;bundle-version="24.1.2",\
14+
org.graalvm.shadowed.icu4j;bundle-version="24.1.2",\
15+
org.graalvm.truffle.truffle-compiler;bundle-version="24.1.2",\
16+
org.graalvm.truffle.truffle-runtime;bundle-version="24.1.2"
1017

1118
SPI-Provider: *
1219
SPI-Consumer: *

bundles/org.openhab.automation.jsscripting/pom.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
!jdk.vm.ci.services
2424
</bnd.importpackage>
2525
<!-- Remember to check if the fix https://github.com/openhab/openhab-core/pull/4437 still works when upgrading GraalJS -->
26-
<graaljs.version>24.1.1</graaljs.version>
26+
<graaljs.version>24.1.2</graaljs.version>
2727
<oh.version>${project.version}</oh.version>
2828
<ohjs.version>[email protected]</ohjs.version>
2929
</properties>
@@ -46,6 +46,14 @@
4646
<excludes>
4747
<exclude>org.lastnpe.eea:eea-all</exclude>
4848
<exclude>org.apache.karaf.features:framework</exclude>
49+
<!-- we use OSGI-ified version, so we don't need the following -->
50+
<exclude>org.graalvm.sdk:collections</exclude>
51+
<exclude>org.graalvm.sdk:jniutils</exclude>
52+
<exclude>org.graalvm.sdk:nativeimage</exclude>
53+
<exclude>org.graalvm.sdk:word</exclude>
54+
<exclude>org.graalvm.shadowed:icu4j</exclude>
55+
<exclude>org.graalvm.truffle:truffle-compiler</exclude>
56+
<exclude>org.graalvm.truffle:truffle-runtime</exclude>
4957
</excludes>
5058
</artifactSet>
5159
<createDependencyReducedPom>false</createDependencyReducedPom>
@@ -109,6 +117,7 @@
109117
</execution>
110118
</executions>
111119
</plugin>
120+
<!-- embed the JS resources into the bundle -->
112121
<plugin>
113122
<groupId>org.codehaus.mojo</groupId>
114123
<artifactId>build-helper-maven-plugin</artifactId>
@@ -141,6 +150,7 @@
141150
</build>
142151

143152
<dependencies>
153+
<!-- Graal Polyglot Framework -->
144154
<dependency>
145155
<groupId>org.graalvm.polyglot</groupId>
146156
<artifactId>polyglot</artifactId>

bundles/org.openhab.automation.jsscripting/src/main/feature/feature.xml

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
<feature name="openhab-automation-jsscripting" description="JavaScript Scripting" version="${project.version}">
77
<feature>openhab-runtime-base</feature>
8+
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.sdk.collections/24.1.2</bundle>
9+
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.sdk.jniutils/24.1.2</bundle>
10+
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.sdk.nativeimage/24.1.2</bundle>
11+
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.sdk.word/24.1.2</bundle>
12+
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.shadowed.icu4j/24.1.2</bundle>
13+
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.truffle.truffle-compiler/24.1.2</bundle>
14+
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.truffle.truffle-runtime/24.1.2</bundle>
815
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.automation.jsscripting/${project.version}</bundle>
916
</feature>
1017
</features>

bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import javax.script.ScriptEngineFactory;
2424
import javax.script.ScriptException;
2525

26-
import org.eclipse.jdt.annotation.NonNull;
27-
2826
/**
2927
* {@link ScriptEngine} implementation that delegates to a supplied ScriptEngine instance. Allows overriding specific
3028
* methods.
@@ -33,9 +31,9 @@
3331
*/
3432
public abstract class DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable<T extends ScriptEngine & Invocable & Compilable & AutoCloseable>
3533
implements ScriptEngine, Invocable, Compilable, AutoCloseable {
36-
protected @NonNull T delegate;
34+
protected T delegate;
3735

38-
public DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable(@NonNull T delegate) {
36+
public DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable(T delegate) {
3937
this.delegate = delegate;
4038
}
4139

0 commit comments

Comments
 (0)