[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:
J-N-K
2023-01-12 22:23:20 +01:00
committed by GitHub
parent bbc885725f
commit 6aa0dcbc70
2 changed files with 26 additions and 53 deletions

View File

@@ -14,17 +14,17 @@ package org.openhab.automation.jrubyscripting.internal.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.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory;
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
import org.openhab.core.automation.module.script.ScriptEngineFactory;
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.framework.Constants;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@@ -37,7 +37,8 @@ import org.slf4j.LoggerFactory;
*
* @author Cody Cutrer - Initial contribution
*/
@Component(immediate = true, service = ScriptDependencyTracker.Listener.class)
@Component(immediate = true, service = { ScriptFileWatcher.class, ScriptDependencyTracker.Listener.class })
@NonNullByDefault
public class JRubyScriptFileWatcher extends AbstractScriptFileWatcher {
private final Logger logger = LoggerFactory.getLogger(JRubyScriptFileWatcher.class);
@@ -47,32 +48,21 @@ public class JRubyScriptFileWatcher extends AbstractScriptFileWatcher {
@Activate
public JRubyScriptFileWatcher(final @Reference ScriptEngineManager manager,
final @Reference ReadyService readyService, final @Reference(target = "(" + Constants.SERVICE_PID
final @Reference ReadyService readyService, final @Reference StartLevelService startLevelService,
final @Reference(target = "(" + Constants.SERVICE_PID
+ "=org.openhab.automation.jrubyscripting)") ScriptEngineFactory scriptEngineFactory) {
super(manager, readyService, FILE_DIRECTORY);
super(manager, readyService, startLevelService, FILE_DIRECTORY);
this.scriptEngineFactory = (JRubyScriptEngineFactory) scriptEngineFactory;
}
@Override
protected void importFile(ScriptFileReference ref) {
if (isIgnored(ref.getScriptFileURL().getFile())) {
return;
}
super.importFile(ref);
}
protected Optional<String> getScriptType(Path scriptFilePath) {
String path = scriptFilePath.toString();
@Override
protected void processWatchEvent(@Nullable WatchEvent<?> event, WatchEvent.@Nullable Kind<?> kind,
@Nullable Path path) {
if (Objects.nonNull(path)) {
if (!isIgnored(path.toString())) {
super.processWatchEvent(event, kind, path);
}
if (scriptEngineFactory.isFileInGemHome(path) || scriptEngineFactory.isFileInLoadPath(path)) {
return Optional.empty();
}
}
private boolean isIgnored(String path) {
return scriptEngineFactory.isFileInGemHome(path) || scriptEngineFactory.isFileInLoadPath(path);
return super.getScriptType(scriptFilePath);
}
}