[jsscripting] Fix build and cleanup (#10654)

Related to #8516

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-05-06 22:19:59 +02:00 committed by GitHub
parent 9912e1afc2
commit f907bf37f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 24 deletions

View File

@ -21,6 +21,11 @@
<artifactId>org.openhab.automation.groovyscripting</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.automation.jsscripting</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.automation.jythonscripting</artifactId>
@ -31,11 +36,6 @@
<artifactId>org.openhab.automation.pidcontroller</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.automation.jsscripting</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.adorne</artifactId>

View File

@ -17,7 +17,6 @@ import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.graalvm.polyglot.PolyglotException;
import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable;
import org.slf4j.Logger;
@ -28,11 +27,11 @@ import org.slf4j.LoggerFactory;
*
* @author Jonathan Gilbert - Initial contribution
*/
@NonNullByDefault
class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable>
extends InvocationInterceptingScriptEngineWithInvocable<T> {
private static final Logger stackLogger = LoggerFactory.getLogger("org.openhab.automation.script.javascript.stack");
private static final Logger STACK_LOGGER = LoggerFactory
.getLogger("org.openhab.automation.script.javascript.stack");
public DebuggingGraalScriptEngine(T delegate) {
super(delegate);
@ -42,7 +41,7 @@ class DebuggingGraalScriptEngine<T extends ScriptEngine & Invocable>
public ScriptException afterThrowsInvocation(ScriptException se) {
Throwable cause = se.getCause();
if (cause instanceof PolyglotException) {
stackLogger.error("Failed to execute script:", cause);
STACK_LOGGER.error("Failed to execute script:", cause);
}
return se;
}

View File

@ -13,8 +13,7 @@
package org.openhab.automation.jsscripting.internal;
import static org.openhab.core.automation.module.script.ScriptEngineFactory.CONTEXT_KEY_ENGINE_IDENTIFIER;
import static org.openhab.core.automation.module.script.ScriptEngineFactory.CONTEXT_KEY_EXTENSION_ACCESSOR;
import static org.openhab.core.automation.module.script.ScriptEngineFactory.*;
import java.io.File;
import java.io.IOException;
@ -48,17 +47,15 @@ import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
*/
public class OpenhabGraalJSScriptEngine extends InvocationInterceptingScriptEngineWithInvocable<GraalJSScriptEngine> {
private static final Logger logger = LoggerFactory.getLogger(OpenhabGraalJSScriptEngine.class);
private static final Logger LOGGER = LoggerFactory.getLogger(OpenhabGraalJSScriptEngine.class);
private static final String REQUIRE_WRAPPER_NAME = "__wraprequire__";
private static final String MODULE_DIR = String.join(File.separator, OpenHAB.getConfigFolder(), "automation", "lib",
"javascript", "personal");
// these fields start as null because they are populated on first use
@NonNullByDefault({})
private String engineIdentifier;
@NonNullByDefault({})
private Consumer<String> scriptDependencyListener;
private @NonNullByDefault({}) String engineIdentifier;
private @NonNullByDefault({}) Consumer<String> scriptDependencyListener;
private boolean initialized = false;
@ -115,7 +112,7 @@ public class OpenhabGraalJSScriptEngine extends InvocationInterceptingScriptEngi
scriptDependencyListener = (Consumer<String>) ctx
.getAttribute("oh.dependency-listener"/* CONTEXT_KEY_DEPENDENCY_LISTENER */);
if (scriptDependencyListener == null) {
logger.warn(
LOGGER.warn(
"Failed to retrieve script script dependency listener from engine bindings. Script dependency tracking will be disabled.");
}

View File

@ -59,7 +59,6 @@ public class ScriptExtensionModuleProvider {
}
private Optional<Value> runtimeModule(String name, String scriptIdentifier, Context ctx) {
Map<String, Object> symbols;
if (DEFAULT_MODULE_NAME.equals(name)) {

View File

@ -36,7 +36,6 @@ public class PrefixedSeekableByteChannel implements SeekableByteChannel {
@Override
public int read(ByteBuffer dst) throws IOException {
int read = 0;
if (position < prefix.length) {
@ -63,7 +62,6 @@ public class PrefixedSeekableByteChannel implements SeekableByteChannel {
@Override
public SeekableByteChannel position(long newPosition) throws IOException {
this.position = newPosition;
if (newPosition > prefix.length) {

View File

@ -21,8 +21,6 @@ import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Delegate allowing AOP-style interception of calls, either before Invocation, or upon a {@link ScriptException}.
* being thrown.
@ -30,7 +28,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
* @param <T> The delegate class
* @author Jonathan Gilbert - Initial contribution
*/
@NonNullByDefault
public abstract class InvocationInterceptingScriptEngineWithInvocable<T extends ScriptEngine & Invocable>
extends DelegatingScriptEngineWithInvocable<T> {

View File

@ -19,9 +19,9 @@
<modules>
<!-- automation -->
<module>org.openhab.automation.groovyscripting</module>
<module>org.openhab.automation.jsscripting</module>
<module>org.openhab.automation.jythonscripting</module>
<module>org.openhab.automation.pidcontroller</module>
<module>org.openhab.automation.jsscripting</module>
<!-- io -->
<module>org.openhab.io.homekit</module>
<module>org.openhab.io.hueemulation</module>