diff --git a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java index fffdcc8fd0e..0aecf551e5b 100644 --- a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java +++ b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java @@ -12,6 +12,8 @@ */ package org.openhab.core.model.yaml.internal; +import static org.openhab.core.service.WatchService.Kind.CREATE; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -24,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -52,6 +55,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; +import com.fasterxml.jackson.dataformat.yaml.YAMLParser; /** * The {@link YamlModelRepositoryImpl} is an OSGi service, that encapsulates all YAML file processing @@ -82,7 +86,8 @@ public YamlModelRepositoryImpl(@Reference(target = WatchService.CONFIG_WATCHER_F .disable(YAMLGenerator.Feature.SPLIT_LINES) // do not split long lines .enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR) // indent arrays .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES) // use quotes only where necessary - .build(); + .enable(YAMLParser.Feature.PARSE_BOOLEAN_LIKE_WORDS_AS_STRINGS).build(); // do not parse ON/OFF/... as + // booleans this.objectMapper = new ObjectMapper(yamlFactory); objectMapper.findAndRegisterModules(); objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); @@ -91,6 +96,13 @@ public YamlModelRepositoryImpl(@Reference(target = WatchService.CONFIG_WATCHER_F this.watchService = watchService; watchService.registerListener(this, Path.of("")); watchPath = watchService.getWatchPath(); + + // read initial contents + try (Stream files = Files.walk(watchPath)) { + files.filter(Files::isRegularFile).map(watchPath::relativize).forEach(f -> processWatchEvent(CREATE, f)); + } catch (IOException e) { + logger.warn("Could not list YAML files in '{}', models might be missing: {}", watchPath, e.getMessage()); + } } @Deactivate diff --git a/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java b/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java index ccae8c33b99..0b6ac9a9df3 100644 --- a/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java +++ b/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java @@ -51,7 +51,7 @@ @MockitoSettings(strictness = Strictness.LENIENT) @NonNullByDefault public class YamlModelRepositoryImplTest { - private static final Path SOURCE_PATH = Path.of("src/test/resources"); + private static final Path SOURCE_PATH = Path.of("src/test/resources/model"); private static final String MODEL_NAME = "model"; private static final Path MODEL_PATH = Path.of(MODEL_NAME + ".yaml"); diff --git a/bundles/org.openhab.core.model.yaml/src/test/resources/addToModelExpectedContent.yaml b/bundles/org.openhab.core.model.yaml/src/test/resources/model/addToModelExpectedContent.yaml similarity index 100% rename from bundles/org.openhab.core.model.yaml/src/test/resources/addToModelExpectedContent.yaml rename to bundles/org.openhab.core.model.yaml/src/test/resources/model/addToModelExpectedContent.yaml diff --git a/bundles/org.openhab.core.model.yaml/src/test/resources/modelFileAddedOrRemoved.yaml b/bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileAddedOrRemoved.yaml similarity index 100% rename from bundles/org.openhab.core.model.yaml/src/test/resources/modelFileAddedOrRemoved.yaml rename to bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileAddedOrRemoved.yaml diff --git a/bundles/org.openhab.core.model.yaml/src/test/resources/modelFileUpdatePost.yaml b/bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileUpdatePost.yaml similarity index 100% rename from bundles/org.openhab.core.model.yaml/src/test/resources/modelFileUpdatePost.yaml rename to bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileUpdatePost.yaml diff --git a/bundles/org.openhab.core.model.yaml/src/test/resources/modelFileUpdatePre.yaml b/bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileUpdatePre.yaml similarity index 100% rename from bundles/org.openhab.core.model.yaml/src/test/resources/modelFileUpdatePre.yaml rename to bundles/org.openhab.core.model.yaml/src/test/resources/model/modelFileUpdatePre.yaml diff --git a/bundles/org.openhab.core.model.yaml/src/test/resources/modifyModelInitialContent.yaml b/bundles/org.openhab.core.model.yaml/src/test/resources/model/modifyModelInitialContent.yaml similarity index 100% rename from bundles/org.openhab.core.model.yaml/src/test/resources/modifyModelInitialContent.yaml rename to bundles/org.openhab.core.model.yaml/src/test/resources/model/modifyModelInitialContent.yaml diff --git a/bundles/org.openhab.core.model.yaml/src/test/resources/removeFromModelExpectedContent.yaml b/bundles/org.openhab.core.model.yaml/src/test/resources/model/removeFromModelExpectedContent.yaml similarity index 100% rename from bundles/org.openhab.core.model.yaml/src/test/resources/removeFromModelExpectedContent.yaml rename to bundles/org.openhab.core.model.yaml/src/test/resources/model/removeFromModelExpectedContent.yaml diff --git a/bundles/org.openhab.core.model.yaml/src/test/resources/updateInModelExpectedContent.yaml b/bundles/org.openhab.core.model.yaml/src/test/resources/model/updateInModelExpectedContent.yaml similarity index 100% rename from bundles/org.openhab.core.model.yaml/src/test/resources/updateInModelExpectedContent.yaml rename to bundles/org.openhab.core.model.yaml/src/test/resources/model/updateInModelExpectedContent.yaml