Skip to content

Commit

Permalink
[jsscripting] Use OSGi-ified GraalVM dependencies (#18053)
Browse files Browse the repository at this point in the history
* [jsscripting] Use OSGI-ified org.graalvm.sdk:* dependencies

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Feb 13, 2025
1 parent 01cb892 commit 8c68fb7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.automation.jsscripting/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JavaScript Scripting

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

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
Expand Down
7 changes: 7 additions & 0 deletions bundles/org.openhab.automation.jsscripting/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Require-Capability:
osgi.serviceloader:=
filter:="(osgi.serviceloader=org.graalvm.polyglot.impl.AbstractPolyglotImpl)";
cardinality:=multiple
Require-Bundle: org.graalvm.sdk.collections;bundle-version="24.1.2",\
org.graalvm.sdk.jniutils;bundle-version="24.1.2",\
org.graalvm.sdk.nativeimage;bundle-version="24.1.2",\
org.graalvm.sdk.word;bundle-version="24.1.2",\
org.graalvm.shadowed.icu4j;bundle-version="24.1.2",\
org.graalvm.truffle.truffle-compiler;bundle-version="24.1.2",\
org.graalvm.truffle.truffle-runtime;bundle-version="24.1.2"

SPI-Provider: *
SPI-Consumer: *
Expand Down
12 changes: 11 additions & 1 deletion bundles/org.openhab.automation.jsscripting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
!jdk.vm.ci.services
</bnd.importpackage>
<!-- Remember to check if the fix https://github.com/openhab/openhab-core/pull/4437 still works when upgrading GraalJS -->
<graaljs.version>24.1.1</graaljs.version>
<graaljs.version>24.1.2</graaljs.version>
<oh.version>${project.version}</oh.version>
<ohjs.version>[email protected]</ohjs.version>
</properties>
Expand All @@ -46,6 +46,14 @@
<excludes>
<exclude>org.lastnpe.eea:eea-all</exclude>
<exclude>org.apache.karaf.features:framework</exclude>
<!-- we use OSGI-ified version, so we don't need the following -->
<exclude>org.graalvm.sdk:collections</exclude>
<exclude>org.graalvm.sdk:jniutils</exclude>
<exclude>org.graalvm.sdk:nativeimage</exclude>
<exclude>org.graalvm.sdk:word</exclude>
<exclude>org.graalvm.shadowed:icu4j</exclude>
<exclude>org.graalvm.truffle:truffle-compiler</exclude>
<exclude>org.graalvm.truffle:truffle-runtime</exclude>
</excludes>
</artifactSet>
<createDependencyReducedPom>false</createDependencyReducedPom>
Expand Down Expand Up @@ -109,6 +117,7 @@
</execution>
</executions>
</plugin>
<!-- embed the JS resources into the bundle -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down Expand Up @@ -141,6 +150,7 @@
</build>

<dependencies>
<!-- Graal Polyglot Framework -->
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>polyglot</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

<feature name="openhab-automation-jsscripting" description="JavaScript Scripting" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.sdk.collections/24.1.2</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.sdk.jniutils/24.1.2</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.sdk.nativeimage/24.1.2</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.sdk.word/24.1.2</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.shadowed.icu4j/24.1.2</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.truffle.truffle-compiler/24.1.2</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/org.graalvm.truffle.truffle-runtime/24.1.2</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.automation.jsscripting/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import javax.script.ScriptEngineFactory;
import javax.script.ScriptException;

import org.eclipse.jdt.annotation.NonNull;

/**
* {@link ScriptEngine} implementation that delegates to a supplied ScriptEngine instance. Allows overriding specific
* methods.
Expand All @@ -33,9 +31,9 @@
*/
public abstract class DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable<T extends ScriptEngine & Invocable & Compilable & AutoCloseable>
implements ScriptEngine, Invocable, Compilable, AutoCloseable {
protected @NonNull T delegate;
protected T delegate;

public DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable(@NonNull T delegate) {
public DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable(T delegate) {
this.delegate = delegate;
}

Expand Down

2 comments on commit 8c68fb7

@Nadahar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florian-h05 When trying to resolve dependencies for openhab-distro/launch/app/app.bndrun with the jsscripting addon included, I now get:

 Unable to resolve <<INITIAL>>: missing requirement osgi.identity;filter:='(osgi.identity=org.openhab.automation.jsscripting)' [caused by: Unable to resolve org.openhab.automation.jsscripting version=5.0.0.202502140010: missing requirement osgi.wiring.bundle;filter:='(&(osgi.wiring.bundle=org.graalvm.sdk.collections)(bundle-version>=24.1.2))']

Reverting this commit makes it resolve.

Maybe there's a corresponding change that needs to be done in "openhab-distro" to make this work?

@openhab-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/running-org-openhab-demo-app-with-org-openhab-automation-jsscripting-enabled/162466/1

Please sign in to comment.