2 * Copyright (c) 2010-2021 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.util.Optional;
18 import org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory;
19 import org.openhab.core.automation.module.script.ScriptEngineManager;
20 import org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileReference;
21 import org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher;
22 import org.openhab.core.service.ReadyService;
23 import org.osgi.service.component.annotations.Activate;
24 import org.osgi.service.component.annotations.Component;
25 import org.osgi.service.component.annotations.Deactivate;
26 import org.osgi.service.component.annotations.Reference;
29 * Monitors <openHAB-conf>/automation/js for Javascript files
31 * @author Jonathan Gilbert - Initial contribution
33 @Component(immediate = true)
34 public class JSScriptFileWatcher extends ScriptFileWatcher {
35 private static final String FILE_DIRECTORY = "automation" + File.separator + "js";
38 public JSScriptFileWatcher(final @Reference ScriptEngineManager manager, final @Reference ReadyService readyService,
39 final @Reference JSDependencyTracker jsDependencyTracker) {
40 super(manager, jsDependencyTracker, readyService, FILE_DIRECTORY);
45 public void activate() {
51 public void deactivate() {
56 protected boolean createAndLoad(ScriptFileReference ref) {
57 return super.createAndLoad(new ScriptFileReference(ref.getScriptFileURL()) {
59 public Optional<String> getScriptType() {
60 assert super.getScriptType().get().equalsIgnoreCase("js");
61 return Optional.of(GraalJSScriptEngineFactory.MIME_TYPE);