-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jonathan Gilbert <[email protected]>
- Loading branch information
Showing
4 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...c/main/java/org/openhab/automation/jsscripting/internal/fs/watch/JSDependencyTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.openhab.automation.jsscripting.internal.fs.watch; | ||
|
||
import java.io.File; | ||
|
||
import org.openhab.core.OpenHAB; | ||
import org.openhab.core.automation.module.script.rulesupport.loader.DependencyTracker; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
|
||
/** | ||
* Tracks JS module dependencies | ||
* | ||
* @author Jonathan Gilbert - Initial contribution | ||
*/ | ||
@Component(immediate = true, service = JSDependencyTracker.class) | ||
public class JSDependencyTracker extends DependencyTracker { | ||
|
||
public static final String LIB_PATH = String.join(File.separator, OpenHAB.getConfigFolder(), "automation", "js", | ||
"node_modules"); | ||
|
||
public JSDependencyTracker() { | ||
super(LIB_PATH); | ||
} | ||
|
||
@Activate | ||
public void activate() { | ||
super.activate(); | ||
} | ||
|
||
@Deactivate | ||
public void deactivate() { | ||
super.deactivate(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...c/main/java/org/openhab/automation/jsscripting/internal/fs/watch/JSScriptFileWatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.openhab.automation.jsscripting.internal.fs.watch; | ||
|
||
import java.io.File; | ||
import java.util.Optional; | ||
|
||
import org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory; | ||
import org.openhab.core.automation.module.script.ScriptEngineManager; | ||
import org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileReference; | ||
import org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher; | ||
import org.openhab.core.service.ReadyService; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
/** | ||
* Monitors <openHAB-conf>/automation/js for Javascript files | ||
* | ||
* @author Jonathan Gilbert - Initial contribution | ||
*/ | ||
@Component(immediate = true) | ||
public class JSScriptFileWatcher extends ScriptFileWatcher { | ||
private static final String FILE_DIRECTORY = "automation" + File.separator + "js"; | ||
|
||
@Activate | ||
public JSScriptFileWatcher(final @Reference ScriptEngineManager manager, final @Reference ReadyService readyService, | ||
final @Reference JSDependencyTracker jsDependencyTracker) { | ||
super(manager, jsDependencyTracker, readyService, FILE_DIRECTORY); | ||
} | ||
|
||
@Activate | ||
@Override | ||
public void activate() { | ||
super.activate(); | ||
} | ||
|
||
@Deactivate | ||
@Override | ||
public void deactivate() { | ||
super.deactivate(); | ||
} | ||
|
||
@Override | ||
protected boolean createAndLoad(ScriptFileReference ref) { | ||
return super.createAndLoad(new ScriptFileReference(ref.getScriptFileURL()) { | ||
@Override | ||
public Optional<String> getScriptType() { | ||
assert super.getScriptType().get().equalsIgnoreCase("js"); | ||
return Optional.of(GraalJSScriptEngineFactory.MIME_TYPE); | ||
} | ||
}); | ||
} | ||
} |