]> git.basschouten.com Git - openhab-addons.git/blob
f4cb934d9dc28122562638afa61bf8e90ecfca86
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.automation.jsscripting.internal.fs.watch;
14
15 import java.io.File;
16
17 import org.openhab.core.OpenHAB;
18 import org.openhab.core.automation.module.script.rulesupport.loader.DependencyTracker;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * Tracks JS module dependencies
24  *
25  * @author Jonathan Gilbert - Initial contribution
26  */
27 public class JSDependencyTracker extends DependencyTracker {
28
29     private final Logger logger = LoggerFactory.getLogger(JSDependencyTracker.class);
30
31     public static final String LIB_PATH = String.join(File.separator, OpenHAB.getConfigFolder(), "automation", "js",
32             "node_modules");
33
34     public JSDependencyTracker() {
35         super(LIB_PATH);
36     }
37
38     public void activate() {
39         File directory = new File(LIB_PATH);
40         if (!directory.exists()) {
41             if (!directory.mkdirs()) {
42                 logger.warn("Failed to create watched directory: {}", LIB_PATH);
43             }
44         } else if (directory.isFile()) {
45             logger.warn("Trying to watch directory {}, however it is a file", LIB_PATH);
46         }
47
48         super.activate();
49     }
50 }