Skip to content

Commit

Permalink
[jsscripting] Fix build and cleanup (#10654)
Browse files Browse the repository at this point in the history
Related to #8516

Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn authored May 6, 2021
1 parent 9912e1a commit f907bf3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 22 deletions.
6 changes: 3 additions & 3 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.automation.jythonscripting</artifactId>
<artifactId>org.openhab.automation.jsscripting</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.automation.pidcontroller</artifactId>
<artifactId>org.openhab.automation.jythonscripting</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.automation.jsscripting</artifactId>
<artifactId>org.openhab.automation.pidcontroller</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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;
Expand All @@ -28,11 +27,11 @@
*
* @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);
Expand All @@ -42,7 +41,7 @@ public DebuggingGraalScriptEngine(T delegate) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,17 +47,15 @@
*/
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;

Expand Down Expand Up @@ -115,7 +112,7 @@ protected void beforeInvocation() {
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.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public ModuleLocator locatorFor(Context ctx, String engineIdentifier) {
}

private Optional<Value> runtimeModule(String name, String scriptIdentifier, Context ctx) {

Map<String, Object> symbols;

if (DEFAULT_MODULE_NAME.equals(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public PrefixedSeekableByteChannel(byte[] prefix, SeekableByteChannel source) {

@Override
public int read(ByteBuffer dst) throws IOException {

int read = 0;

if (position < prefix.length) {
Expand All @@ -63,7 +62,6 @@ public long position() throws IOException {

@Override
public SeekableByteChannel position(long newPosition) throws IOException {

this.position = newPosition;

if (newPosition > prefix.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@
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.
*
* @param <T> The delegate class
* @author Jonathan Gilbert - Initial contribution
*/
@NonNullByDefault
public abstract class InvocationInterceptingScriptEngineWithInvocable<T extends ScriptEngine & Invocable>
extends DelegatingScriptEngineWithInvocable<T> {

Expand Down
2 changes: 1 addition & 1 deletion bundles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit f907bf3

Please sign in to comment.