2 * Copyright (c) 2010-2023 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.jrubyscripting.internal.watch;
15 import static org.openhab.core.service.WatchService.Kind.*;
18 import java.nio.file.Path;
19 import java.util.List;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.core.service.WatchService;
23 import org.openhab.core.service.WatchService.Kind;
26 * Watches a Ruby lib dir
28 * @author Cody Cutrer - Initial contribution
29 * @author Jan N. Klug - Refactored to new WatchService
32 public class JRubyLibWatchService implements JRubyWatchService, WatchService.WatchEventListener {
33 private final JRubyDependencyTracker dependencyTracker;
34 private final WatchService watchService;
35 private final List<Path> paths;
37 JRubyLibWatchService(WatchService watchService, List<Path> paths, JRubyDependencyTracker dependencyTracker) {
38 this.watchService = watchService;
39 this.dependencyTracker = dependencyTracker;
44 public void activate() {
45 watchService.registerListener(this, paths);
49 public void deactivate() {
50 watchService.unregisterListener(this);
54 public void processWatchEvent(Kind kind, Path path) {
55 File file = path.toFile();
56 if (!file.isHidden() && (kind == DELETE || (file.canRead() && (kind == CREATE || kind == MODIFY)))) {
57 dependencyTracker.dependencyChanged(file.getPath());