Skip to content

Commit

Permalink
resolve itests and fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <github@klug.nrw>
  • Loading branch information
J-N-K committed Dec 20, 2022
1 parent 3f167e8 commit d8784fb
Show file tree
Hide file tree
Showing 25 changed files with 82 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.openhab.core.automation.module.script.ScriptExtensionManagerWrapper;
import org.openhab.core.config.core.ConfigurableService;
import org.openhab.core.service.WatchService;
import org.openhab.core.service.WatchServiceFactory;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
Expand Down Expand Up @@ -75,7 +74,8 @@ private static Map.Entry<String, Object> mapGlobalPresets(Map.Entry<String, Obje
}

@Activate
public JRubyScriptEngineFactory( @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService, Map<String, Object> config) {
public JRubyScriptEngineFactory(@Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService,
Map<String, Object> config) {
jrubyDependencyTracker = new JRubyDependencyTracker(watchService, this);
modified(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void activate() {
watchService.registerListener(this, path);
}

@Override
@Override
public void deactivate() {
watchService.unregisterListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.automation.jrubyscripting.internal.watch;

import static org.openhab.core.service.WatchService.Kind.*;

import java.io.File;
Expand Down Expand Up @@ -52,8 +53,8 @@ public void deactivate() {
@Override
public void processWatchEvent(Kind kind, Path path) {
File file = path.toFile();
if (!file.isHidden() && (kind.equals(DELETE)
|| (file.canRead() && (kind.equals(CREATE) || kind.equals(MODIFY))))) {
if (!file.isHidden()
&& (kind.equals(DELETE) || (file.canRead() && (kind.equals(CREATE) || kind.equals(MODIFY))))) {
dependencyTracker.dependencyChanged(file.getPath());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

import java.io.File;
import java.nio.file.Path;
import java.nio.file.WatchEvent;
import java.util.Objects;

import org.eclipse.jdt.annotation.Nullable;
import org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory;
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
import org.openhab.core.automation.module.script.ScriptEngineFactory;
Expand Down Expand Up @@ -49,7 +46,8 @@ 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(target = "(" + Constants.SERVICE_PID
+ "=org.openhab.automation.jrubyscripting)") ScriptEngineFactory scriptEngineFactory,
final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
super(manager, readyService, watchService, FILE_DIRECTORY, true);
Expand All @@ -67,10 +65,10 @@ protected void importFile(ScriptFileReference ref) {

@Override
public void processWatchEvent(WatchService.Kind kind, Path path) {
if (!isIgnored(path.toString())) {
super.processWatchEvent(kind, path);
}
}
if (!isIgnored(path.toString())) {
super.processWatchEvent(kind, path);
}
}

private boolean isIgnored(String path) {
return scriptEngineFactory.isFileInGemHome(path) || scriptEngineFactory.isFileInLoadPath(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021-2022 Contributors to the SmartHome/J project
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand All @@ -19,7 +19,8 @@
*
* @author Jan N. Klug - Initial contribution
*/
@NonNullByDefault public interface JRubyWatchService {
@NonNullByDefault
public interface JRubyWatchService {

/**
* start watching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
package org.openhab.automation.jsscripting.internal.fs.watch;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.OpenHAB;
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
import org.openhab.core.automation.module.script.rulesupport.loader.AbstractScriptDependencyTracker;
import org.openhab.core.service.WatchService;
Expand All @@ -43,27 +40,15 @@ public class JSDependencyTracker extends AbstractScriptDependencyTracker {

private final Logger logger = LoggerFactory.getLogger(JSDependencyTracker.class);

public static final String LIB_PATH = String.join(File.separator, "automation", "js",
"node_modules");
public static final String LIB_PATH = String.join(File.separator, "automation", "js", "node_modules");

@Activate
public JSDependencyTracker(@Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
super(watchService, LIB_PATH);
}

@Activate
public void activate() {
Path directory = Path.of(OpenHAB.getConfigFolder(), LIB_PATH);
if (Files.isRegularFile(directory)) {
logger.warn("Trying to watch directory '{}', however it is a file",directory);
} else {
try {
Files.createDirectories(directory);
} catch (IOException e) {
logger.warn("Failed to create '{}': {}", directory, e.getMessage());
}
if (Files.isRegularFile(this.libraryPath)) {
logger.warn("Trying to watch directory '{}', however it is a file", this.libraryPath);
}

super.activate();
}

@Deactivate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public class JSScriptFileWatcher extends AbstractScriptFileWatcher {
private final String ignorePath;

@Activate
public JSScriptFileWatcher(final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService, final @Reference ScriptEngineManager manager,
final @Reference ReadyService readyService) {
public JSScriptFileWatcher(final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService,
final @Reference ScriptEngineManager manager, final @Reference ReadyService readyService) {
super(manager, readyService, watchService, FILE_DIRECTORY, false);

ignorePath = FILE_DIRECTORY + File.separator + "node_modules";
}

@Override
public void processWatchEvent( WatchService.Kind kind, Path path) {
if (!path.startsWith(ignorePath)) {
super.processWatchEvent(kind, path);
}
}
public void processWatchEvent(WatchService.Kind kind, Path path) {
if (!path.startsWith(ignorePath)) {
super.processWatchEvent(kind, path);
}
}

@Override
protected boolean createAndLoad(ScriptFileReference ref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import static java.nio.file.StandardWatchEventKinds.*;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -46,7 +45,8 @@ public class ExecWhitelistWatchService implements WatchService.WatchEventListene
private final WatchService watchService;

@Activate
public ExecWhitelistWatchService(final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
public ExecWhitelistWatchService(
final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
this.watchService = watchService;
watchService.registerListener(this, COMMAND_WHITELIST_FILE, false);

Expand All @@ -63,7 +63,7 @@ public void deactivate() {
public void processWatchEvent(WatchService.Kind kind, Path path) {
if (path.endsWith(COMMAND_WHITELIST_FILE)) {
commandWhitelist.clear();
try (Stream<String> lines = Files.lines(path) ){
try (Stream<String> lines = Files.lines(path)) {
lines.filter(line -> !line.trim().startsWith("#")).forEach(commandWhitelist::add);
logger.debug("Updated command whitelist: {}", commandWhitelist);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public void deactivate() {

@Override
public void processWatchEvent(WatchService.Kind kind, Path path) {
final Path p = path.getFileName();
if (p != null && p.toString().endsWith(DATABASE_FILES)) {
logger.debug("Local Databases file {} changed. Refreshing device database.", p.getFileName());
populateDatabase();
}
}
final Path p = path.getFileName();
if (p != null && p.toString().endsWith(DATABASE_FILES)) {
logger.debug("Local Databases file {} changed. Refreshing device database.", p.getFileName());
populateDatabase();
}
}

/**
* Return the database file URL for a given modelId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class ExecTransformationWhitelistWatchService implements WatchService.Wat
private final WatchService watchService;

@Activate
public ExecTransformationWhitelistWatchService(final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
public ExecTransformationWhitelistWatchService(
final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
this.watchService = watchService;
watchService.registerListener(this, COMMAND_WHITELIST_FILE);

Expand All @@ -60,7 +61,7 @@ public void deactivate() {
public void processWatchEvent(WatchService.Kind kind, Path path) {
if (path.endsWith(COMMAND_WHITELIST_FILE)) {
commandWhitelist.clear();
try (Stream<String> lines = Files.lines(path) ){
try (Stream<String> lines = Files.lines(path)) {
lines.filter(line -> !line.trim().startsWith("#")).forEach(commandWhitelist::add);
logger.debug("Updated command whitelist: {}", commandWhitelist);
} catch (IOException e) {
Expand Down
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.astro.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ Fragment-Host: org.openhab.binding.astro
org.openhab.core.io.console;version='[4.0.0,4.0.1)',\
org.openhab.core.storage.json;version='[4.0.0,4.0.1)',\
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.avmfritz.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ Fragment-Host: org.openhab.binding.avmfritz
org.openhab.core.test;version='[4.0.0,4.0.1)',\
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)',\
org.objectweb.asm;version='[9.4.0,9.4.1)'
org.objectweb.asm;version='[9.4.0,9.4.1)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.feed.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ Fragment-Host: org.openhab.binding.feed
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)',\
org.objectweb.asm;version='[9.4.0,9.4.1)'
org.objectweb.asm;version='[9.4.0,9.4.1)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.hue.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ Fragment-Host: org.openhab.binding.hue
org.openhab.core.test;version='[4.0.0,4.0.1)',\
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.max.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ Fragment-Host: org.openhab.binding.max
org.openhab.core.test;version='[4.0.0,4.0.1)',\
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.mielecloud.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ Fragment-Host: org.openhab.binding.mielecloud
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)',\
org.objectweb.asm;version='[9.4.0,9.4.1)'
org.objectweb.asm;version='[9.4.0,9.4.1)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.modbus.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ Fragment-Host: org.openhab.binding.modbus
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
org.openhab.core.transform;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@ Import-Package: \
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
org.openhab.core.transform;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.mqtt.homie.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@ Import-Package: \
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
org.openhab.core.transform;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'

4 changes: 3 additions & 1 deletion itests/org.openhab.binding.nest.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@ Fragment-Host: org.openhab.binding.nest
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)',\
org.objectweb.asm;version='[9.4.0,9.4.1)'
org.objectweb.asm;version='[9.4.0,9.4.1)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.ntp.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ Fragment-Host: org.openhab.binding.ntp
org.openhab.core.test;version='[4.0.0,4.0.1)',\
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
3 changes: 2 additions & 1 deletion itests/org.openhab.binding.systeminfo.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ Fragment-Host: org.openhab.binding.systeminfo
org.openhab.core.test;version='[4.0.0,4.0.1)',\
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.tradfri.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ Fragment-Host: org.openhab.binding.tradfri
org.openhab.core.test;version='[4.0.0,4.0.1)',\
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.binding.wemo.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ Fragment-Host: org.openhab.binding.wemo
org.openhab.core.thing;version='[4.0.0,4.0.1)',\
org.openhab.core.thing.xml;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)',\
org.objectweb.asm;version='[9.4.0,9.4.1)'
org.objectweb.asm;version='[9.4.0,9.4.1)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'
4 changes: 3 additions & 1 deletion itests/org.openhab.persistence.mapdb.tests/itest.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ Fragment-Host: org.openhab.persistence.mapdb
org.openhab.core.test;version='[4.0.0,4.0.1)',\
org.openhab.persistence.mapdb;version='[4.0.0,4.0.1)',\
org.openhab.persistence.mapdb.tests;version='[4.0.0,4.0.1)',\
com.google.gson;version='[2.9.1,2.9.2)'
com.google.gson;version='[2.9.1,2.9.2)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.methvin.directory-watcher;version='[0.17.1,0.17.2)'

0 comments on commit d8784fb

Please sign in to comment.