if (!SCRIPT_TYPES.contains(scriptType)) {
return null;
}
- return new DebuggingGraalScriptEngine<>(
- new OpenhabGraalJSScriptEngine(injectionEnabled, useIncludedLibrary, jsScriptServiceUtil));
+ return new DebuggingGraalScriptEngine<>(new OpenhabGraalJSScriptEngine(injectionEnabled, useIncludedLibrary,
+ jsScriptServiceUtil, jsDependencyTracker));
}
@Override
* lifecycle and provides hooks for scripts to do so too.
*/
public OpenhabGraalJSScriptEngine(boolean injectionEnabled, boolean useIncludedLibrary,
- JSScriptServiceUtil jsScriptServiceUtil) {
+ JSScriptServiceUtil jsScriptServiceUtil, JSDependencyTracker jsDependencyTracker) {
super(null); // delegate depends on fields not yet initialised, so we cannot set it immediately
this.injectionEnabled = injectionEnabled;
this.useIncludedLibrary = useIncludedLibrary;
delegate = GraalJSScriptEngine.create(ENGINE,
Context.newBuilder("js").allowExperimentalOptions(true).allowAllAccess(true)
- .allowHostAccess(HOST_ACCESS).option("js.commonjs-require-cwd", JSDependencyTracker.LIB_PATH)
+ .allowHostAccess(HOST_ACCESS)
+ .option("js.commonjs-require-cwd", jsDependencyTracker.getLibraryPath().toString())
.option("js.nashorn-compat", "true") // Enable Nashorn compat mode as openhab-js relies on
// accessors, see
// https://github.com/oracle/graaljs/blob/master/docs/user/NashornMigrationGuide.md#accessors
package org.openhab.automation.jsscripting.internal.fs.watch;
import java.io.File;
-import java.nio.file.Files;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
private final Logger logger = LoggerFactory.getLogger(JSDependencyTracker.class);
- public static final String LIB_PATH = String.join(File.separator, "automation", "js", "node_modules");
+ private static final String LIB_PATH = String.join(File.separator, "automation", "js", "node_modules");
@Activate
public JSDependencyTracker(@Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
super(watchService, LIB_PATH);
-
- if (Files.isRegularFile(this.libraryPath)) {
- logger.warn("Trying to watch directory '{}', however it is a file", this.libraryPath);
- }
}
@Deactivate