]> git.basschouten.com Git - openhab-addons.git/blob
aed75a09306964588070bc17e0e7226df6feb515
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.osgi.service.component.annotations.Activate;
20 import org.osgi.service.component.annotations.Component;
21 import org.osgi.service.component.annotations.Deactivate;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * Tracks JS module dependencies
27  *
28  * @author Jonathan Gilbert - Initial contribution
29  */
30 @Component(immediate = true, service = JSDependencyTracker.class)
31 public class JSDependencyTracker extends DependencyTracker {
32
33     private final Logger logger = LoggerFactory.getLogger(JSDependencyTracker.class);
34
35     public static final String LIB_PATH = String.join(File.separator, OpenHAB.getConfigFolder(), "automation", "js",
36             "node_modules");
37
38     public JSDependencyTracker() {
39         super(LIB_PATH);
40     }
41
42     @Activate
43     public void activate() {
44         File directory = new File(LIB_PATH);
45         if (!directory.exists()) {
46             if (!directory.mkdirs()) {
47                 logger.warn("Failed to create watched directory: {}", LIB_PATH);
48             }
49         } else if (directory.isFile()) {
50             logger.warn("Trying to watch directory {}, however it is a file", LIB_PATH);
51         }
52
53         super.activate();
54     }
55
56     @Deactivate
57     public void deactivate() {
58         super.deactivate();
59     }
60 }