From f907bf37f939f3af1778d0873f618e447e52b3da Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Thu, 6 May 2021 22:19:59 +0200 Subject: [PATCH] [jsscripting] Fix build and cleanup (#10654) Related to #8516 Signed-off-by: Wouter Born --- bom/openhab-addons/pom.xml | 10 +++++----- .../internal/DebuggingGraalScriptEngine.java | 7 +++---- .../internal/OpenhabGraalJSScriptEngine.java | 13 +++++-------- .../internal/ScriptExtensionModuleProvider.java | 1 - .../internal/fs/PrefixedSeekableByteChannel.java | 2 -- ...cationInterceptingScriptEngineWithInvocable.java | 3 --- bundles/pom.xml | 2 +- 7 files changed, 14 insertions(+), 24 deletions(-) diff --git a/bom/openhab-addons/pom.xml b/bom/openhab-addons/pom.xml index 3485b3850..4735007ce 100644 --- a/bom/openhab-addons/pom.xml +++ b/bom/openhab-addons/pom.xml @@ -21,6 +21,11 @@ org.openhab.automation.groovyscripting ${project.version} + + org.openhab.addons.bundles + org.openhab.automation.jsscripting + ${project.version} + org.openhab.addons.bundles org.openhab.automation.jythonscripting @@ -31,11 +36,6 @@ org.openhab.automation.pidcontroller ${project.version} - - org.openhab.addons.bundles - org.openhab.automation.jsscripting - ${project.version} - org.openhab.addons.bundles org.openhab.binding.adorne diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java index 0f21f455d..956f4fbdf 100644 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java @@ -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 extends InvocationInterceptingScriptEngineWithInvocable { - 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 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; } diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java index 8541eb7db..7ba654eec 100644 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java @@ -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 { - 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 scriptDependencyListener; + private @NonNullByDefault({}) String engineIdentifier; + private @NonNullByDefault({}) Consumer scriptDependencyListener; private boolean initialized = false; @@ -115,7 +112,7 @@ public class OpenhabGraalJSScriptEngine extends InvocationInterceptingScriptEngi scriptDependencyListener = (Consumer) 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."); } diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/ScriptExtensionModuleProvider.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/ScriptExtensionModuleProvider.java index d2d140114..e5d77ff42 100644 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/ScriptExtensionModuleProvider.java +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/ScriptExtensionModuleProvider.java @@ -59,7 +59,6 @@ public class ScriptExtensionModuleProvider { } private Optional runtimeModule(String name, String scriptIdentifier, Context ctx) { - Map symbols; if (DEFAULT_MODULE_NAME.equals(name)) { diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/fs/PrefixedSeekableByteChannel.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/fs/PrefixedSeekableByteChannel.java index 2bd98ca85..d9d62f6ee 100644 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/fs/PrefixedSeekableByteChannel.java +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/fs/PrefixedSeekableByteChannel.java @@ -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) { diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocable.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocable.java index 082a98dde..57640e8de 100644 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocable.java +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocable.java @@ -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 The delegate class * @author Jonathan Gilbert - Initial contribution */ -@NonNullByDefault public abstract class InvocationInterceptingScriptEngineWithInvocable extends DelegatingScriptEngineWithInvocable { diff --git a/bundles/pom.xml b/bundles/pom.xml index 29fe4b9ad..adb1ec2c7 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -19,9 +19,9 @@ org.openhab.automation.groovyscripting + org.openhab.automation.jsscripting org.openhab.automation.jythonscripting org.openhab.automation.pidcontroller - org.openhab.automation.jsscripting org.openhab.io.homekit org.openhab.io.hueemulation