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 java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
16 import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
17 import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
20 import java.nio.file.Path;
21 import java.nio.file.WatchEvent;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.openhab.core.service.AbstractWatchService;
28 * Watches a Ruby lib dir
30 * @author Cody Cutrer - Initial contribution
33 public class JRubyLibWatchService extends AbstractWatchService {
34 private JRubyDependencyTracker dependencyTracker;
36 JRubyLibWatchService(String path, JRubyDependencyTracker dependencyTracker) {
38 this.dependencyTracker = dependencyTracker;
42 protected boolean watchSubDirectories() {
47 protected WatchEvent.Kind<?> @Nullable [] getWatchEventKinds(Path path) {
48 return new WatchEvent.Kind<?>[] { ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY };
52 protected void processWatchEvent(WatchEvent<?> watchEvent, WatchEvent.Kind<?> kind, Path path) {
53 File file = path.toFile();
54 if (!file.isHidden() && (kind.equals(ENTRY_DELETE)
55 || (file.canRead() && (kind.equals(ENTRY_CREATE) || kind.equals(ENTRY_MODIFY))))) {
56 dependencyTracker.dependencyChanged(file.getPath());