[scripting] Adjust to core changes (#14043)
* [scripting] Adjust to core changes Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
@@ -14,17 +14,15 @@ package org.openhab.automation.jsscripting.internal.fs.watch;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.WatchEvent;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory;
|
||||
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
|
||||
import org.openhab.core.automation.module.script.ScriptEngineManager;
|
||||
import org.openhab.core.automation.module.script.rulesupport.loader.AbstractScriptFileWatcher;
|
||||
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.openhab.core.service.StartLevelService;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
@@ -34,41 +32,26 @@ import org.osgi.service.component.annotations.Reference;
|
||||
*
|
||||
* @author Jonathan Gilbert - Initial contribution
|
||||
*/
|
||||
@Component(immediate = true, service = ScriptDependencyTracker.Listener.class)
|
||||
@Component(immediate = true, service = { ScriptFileWatcher.class, ScriptDependencyTracker.Listener.class })
|
||||
public class JSScriptFileWatcher extends AbstractScriptFileWatcher {
|
||||
private static final String FILE_DIRECTORY = "automation" + File.separator + "js";
|
||||
|
||||
private final String ignorePath;
|
||||
|
||||
@Activate
|
||||
public JSScriptFileWatcher(final @Reference ScriptEngineManager manager,
|
||||
final @Reference ReadyService readyService) {
|
||||
super(manager, readyService, FILE_DIRECTORY);
|
||||
|
||||
ignorePath = pathToWatch + File.separator + "node_modules";
|
||||
public JSScriptFileWatcher(final @Reference ScriptEngineManager manager, final @Reference ReadyService readyService,
|
||||
final @Reference StartLevelService startLevelService) {
|
||||
super(manager, readyService, startLevelService, FILE_DIRECTORY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processWatchEvent(@Nullable WatchEvent<?> event, WatchEvent.@Nullable Kind<?> kind,
|
||||
@Nullable Path path) {
|
||||
if (Objects.nonNull(path)) {
|
||||
if (!path.startsWith(ignorePath)) {
|
||||
super.processWatchEvent(event, kind, path);
|
||||
}
|
||||
protected Optional<String> getScriptType(Path scriptFilePath) {
|
||||
if (!scriptFilePath.startsWith(pathToWatch + File.separator + "node_modules")
|
||||
&& "js".equals(super.getScriptType(scriptFilePath).orElse(null))) {
|
||||
return Optional.of(GraalJSScriptEngineFactory.MIME_TYPE);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean watchSubDirectories() {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user