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;
15 import org.openhab.core.automation.module.script.ScriptEngineManager;
16 import org.openhab.core.service.ReadyService;
17 import org.osgi.service.component.annotations.Activate;
18 import org.osgi.service.component.annotations.Component;
19 import org.osgi.service.component.annotations.Deactivate;
20 import org.osgi.service.component.annotations.Reference;
23 * Monitors <openHAB-conf>/automation/js for Javascript files & libraries.
25 * This class is required to ensure that the *order* of set up is correct. Specifically, the dependency tracker must
26 * be activated after the script file watcher. This is because AbstractWatchService only allows a single service to
27 * watch a single directory, and given that the watchers are nested and the last registration wins, the one we want to
28 * monitor the libraries must be registered last.
30 * @author Jonathan Gilbert - Initial contribution
32 @Component(immediate = true, service = JSFileWatcher.class)
33 public class JSFileWatcher {
35 private final JSScriptFileWatcher jsScriptFileWatcher;
36 private final JSDependencyTracker jsDependencyTracker;
39 public JSFileWatcher(final @Reference ScriptEngineManager manager, final @Reference ReadyService readyService) {
40 jsDependencyTracker = new JSDependencyTracker();
41 jsScriptFileWatcher = new JSScriptFileWatcher(manager, readyService, jsDependencyTracker);
45 public void activate() {
46 jsScriptFileWatcher.activate();
47 jsDependencyTracker.activate();
48 jsDependencyTracker.addChangeTracker(jsScriptFileWatcher);
53 jsDependencyTracker.removeChangeTracker(jsScriptFileWatcher);
54 jsDependencyTracker.deactivate();
55 jsScriptFileWatcher.deactivate();