[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:
parent
bbc885725f
commit
6aa0dcbc70
@ -14,17 +14,17 @@ package org.openhab.automation.jrubyscripting.internal.watch;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.WatchEvent;
|
import java.util.Optional;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory;
|
import org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory;
|
||||||
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
|
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
|
||||||
import org.openhab.core.automation.module.script.ScriptEngineFactory;
|
import org.openhab.core.automation.module.script.ScriptEngineFactory;
|
||||||
import org.openhab.core.automation.module.script.ScriptEngineManager;
|
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.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.ReadyService;
|
||||||
|
import org.openhab.core.service.StartLevelService;
|
||||||
import org.osgi.framework.Constants;
|
import org.osgi.framework.Constants;
|
||||||
import org.osgi.service.component.annotations.Activate;
|
import org.osgi.service.component.annotations.Activate;
|
||||||
import org.osgi.service.component.annotations.Component;
|
import org.osgi.service.component.annotations.Component;
|
||||||
@ -37,7 +37,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @author Cody Cutrer - Initial contribution
|
* @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 {
|
public class JRubyScriptFileWatcher extends AbstractScriptFileWatcher {
|
||||||
private final Logger logger = LoggerFactory.getLogger(JRubyScriptFileWatcher.class);
|
private final Logger logger = LoggerFactory.getLogger(JRubyScriptFileWatcher.class);
|
||||||
|
|
||||||
@ -47,32 +48,21 @@ public class JRubyScriptFileWatcher extends AbstractScriptFileWatcher {
|
|||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public JRubyScriptFileWatcher(final @Reference ScriptEngineManager manager,
|
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) {
|
+ "=org.openhab.automation.jrubyscripting)") ScriptEngineFactory scriptEngineFactory) {
|
||||||
super(manager, readyService, FILE_DIRECTORY);
|
super(manager, readyService, startLevelService, FILE_DIRECTORY);
|
||||||
|
|
||||||
this.scriptEngineFactory = (JRubyScriptEngineFactory) scriptEngineFactory;
|
this.scriptEngineFactory = (JRubyScriptEngineFactory) scriptEngineFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void importFile(ScriptFileReference ref) {
|
protected Optional<String> getScriptType(Path scriptFilePath) {
|
||||||
if (isIgnored(ref.getScriptFileURL().getFile())) {
|
String path = scriptFilePath.toString();
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.importFile(ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (scriptEngineFactory.isFileInGemHome(path) || scriptEngineFactory.isFileInLoadPath(path)) {
|
||||||
protected void processWatchEvent(@Nullable WatchEvent<?> event, WatchEvent.@Nullable Kind<?> kind,
|
return Optional.empty();
|
||||||
@Nullable Path path) {
|
|
||||||
if (Objects.nonNull(path)) {
|
|
||||||
if (!isIgnored(path.toString())) {
|
|
||||||
super.processWatchEvent(event, kind, path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
return super.getScriptType(scriptFilePath);
|
||||||
|
|
||||||
private boolean isIgnored(String path) {
|
|
||||||
return scriptEngineFactory.isFileInGemHome(path) || scriptEngineFactory.isFileInLoadPath(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,17 +14,15 @@ package org.openhab.automation.jsscripting.internal.fs.watch;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.WatchEvent;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
|
||||||
import org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory;
|
import org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory;
|
||||||
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
|
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
|
||||||
import org.openhab.core.automation.module.script.ScriptEngineManager;
|
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.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.ReadyService;
|
||||||
|
import org.openhab.core.service.StartLevelService;
|
||||||
import org.osgi.service.component.annotations.Activate;
|
import org.osgi.service.component.annotations.Activate;
|
||||||
import org.osgi.service.component.annotations.Component;
|
import org.osgi.service.component.annotations.Component;
|
||||||
import org.osgi.service.component.annotations.Reference;
|
import org.osgi.service.component.annotations.Reference;
|
||||||
@ -34,41 +32,26 @@ import org.osgi.service.component.annotations.Reference;
|
|||||||
*
|
*
|
||||||
* @author Jonathan Gilbert - Initial contribution
|
* @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 {
|
public class JSScriptFileWatcher extends AbstractScriptFileWatcher {
|
||||||
private static final String FILE_DIRECTORY = "automation" + File.separator + "js";
|
private static final String FILE_DIRECTORY = "automation" + File.separator + "js";
|
||||||
|
|
||||||
private final String ignorePath;
|
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public JSScriptFileWatcher(final @Reference ScriptEngineManager manager,
|
public JSScriptFileWatcher(final @Reference ScriptEngineManager manager, final @Reference ReadyService readyService,
|
||||||
final @Reference ReadyService readyService) {
|
final @Reference StartLevelService startLevelService) {
|
||||||
super(manager, readyService, FILE_DIRECTORY);
|
super(manager, readyService, startLevelService, FILE_DIRECTORY);
|
||||||
|
|
||||||
ignorePath = pathToWatch + File.separator + "node_modules";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processWatchEvent(@Nullable WatchEvent<?> event, WatchEvent.@Nullable Kind<?> kind,
|
protected Optional<String> getScriptType(Path scriptFilePath) {
|
||||||
@Nullable Path path) {
|
if (!scriptFilePath.startsWith(pathToWatch + File.separator + "node_modules")
|
||||||
if (Objects.nonNull(path)) {
|
&& "js".equals(super.getScriptType(scriptFilePath).orElse(null))) {
|
||||||
if (!path.startsWith(ignorePath)) {
|
return Optional.of(GraalJSScriptEngineFactory.MIME_TYPE);
|
||||||
super.processWatchEvent(event, kind, path);
|
} 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
|
@Override
|
||||||
protected boolean watchSubDirectories() {
|
protected boolean watchSubDirectories() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user