2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.automation.jsscripting.internal.fs.watch;
16 import java.nio.file.Path;
17 import java.nio.file.WatchEvent;
18 import java.util.Optional;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory;
22 import org.openhab.core.automation.module.script.ScriptEngineManager;
23 import org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileReference;
24 import org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher;
25 import org.openhab.core.service.ReadyService;
28 * Monitors <openHAB-conf>/automation/js for Javascript files, but not libraries
30 * @author Jonathan Gilbert - Initial contribution
32 public class JSScriptFileWatcher extends ScriptFileWatcher {
33 private static final String FILE_DIRECTORY = "automation" + File.separator + "js";
34 private static final String IGNORE_DIR_NAME = "node_modules";
36 private final String ignorePath;
38 public JSScriptFileWatcher(final ScriptEngineManager manager, final ReadyService readyService,
39 JSDependencyTracker dependencyTracker) {
40 super(manager, dependencyTracker, readyService, FILE_DIRECTORY);
42 ignorePath = pathToWatch + File.separator + "node_modules";
46 protected void processWatchEvent(@Nullable WatchEvent<?> event, WatchEvent.@Nullable Kind<?> kind,
47 @Nullable Path path) {
48 if (!path.startsWith(ignorePath)) {
49 super.processWatchEvent(event, kind, path);
54 protected boolean createAndLoad(ScriptFileReference ref) {
55 return super.createAndLoad(new ScriptFileReference(ref.getScriptFileURL()) {
57 public Optional<String> getScriptType() {
58 assert super.getScriptType().get().equalsIgnoreCase("js");
59 return Optional.of(GraalJSScriptEngineFactory.MIME_TYPE);
65 protected boolean watchSubDirectories() {