-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a YAML file provider for semantic tags (#3659)
* Add a YAML file provider for semantic tags Files in folder conf/tags are loaded by this provider. Related to #3619 Signed-off-by: Laurent Garnier <[email protected]>
- Loading branch information
Showing
17 changed files
with
835 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="annotationpath" value="target/dependency"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="annotationpath" value="target/dependency"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.openhab.core.model.yaml</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
This content is produced and maintained by the openHAB project. | ||
|
||
* Project home: https://www.openhab.org | ||
|
||
== Declared Project Licenses | ||
|
||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License 2.0 which is available at | ||
https://www.eclipse.org/legal/epl-2.0/. | ||
|
||
== Source Code | ||
|
||
https://github.com/openhab/openhab-core | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.openhab.core.bundles</groupId> | ||
<artifactId>org.openhab.core.reactor.bundles</artifactId> | ||
<version>4.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.openhab.core.model.yaml</artifactId> | ||
|
||
<name>openHAB Core :: Bundles :: Model YAML</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.openhab.core.bundles</groupId> | ||
<artifactId>org.openhab.core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openhab.core.bundles</groupId> | ||
<artifactId>org.openhab.core.semantics</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
65 changes: 65 additions & 0 deletions
65
...g.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/AbstractYamlFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.model.yaml; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link AbstractYamlFile} is the DTO base class used to map a YAML configuration file. | ||
* | ||
* A YAML configuration file consists of a version and a list of elements. | ||
* | ||
* @author Laurent Garnier - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public abstract class AbstractYamlFile implements YamlFile { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(AbstractYamlFile.class); | ||
|
||
/** | ||
* YAML file version | ||
*/ | ||
public int version; | ||
|
||
@Override | ||
public abstract List<? extends YamlElement> getElements(); | ||
|
||
@Override | ||
public int getVersion() { | ||
return version; | ||
} | ||
|
||
@Override | ||
public boolean isValid() { | ||
// Checking duplicated elements | ||
List<? extends YamlElement> elts = getElements(); | ||
long nbDistinctIds = elts.stream().map(YamlElement::getId).distinct().count(); | ||
if (nbDistinctIds < elts.size()) { | ||
logger.debug("Elements with same ids detected in the file"); | ||
return false; | ||
} | ||
|
||
// Checking each element | ||
for (int i = 0; i < elts.size(); i++) { | ||
if (!elts.get(i).isValid()) { | ||
logger.debug("Error in element {}", i + 1); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...es/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/YamlElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.model.yaml; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* The {@link YamlElement} interface offers an identifier and a check validity method | ||
* to any element defined in a YAML configuration file. | ||
* | ||
* @author Laurent Garnier - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public interface YamlElement { | ||
|
||
/** | ||
* Get the identifier of the YAML element | ||
* | ||
* @return the identifier as a string | ||
*/ | ||
String getId(); | ||
|
||
/** | ||
* Check that the YAML element is valid | ||
* | ||
* @return true if all the checks are OK | ||
*/ | ||
boolean isValid(); | ||
} |
48 changes: 48 additions & 0 deletions
48
bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/YamlFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.model.yaml; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* The {@link YamlFile} is the interface to manage the generic content of a YAML configuration file. | ||
* | ||
* @author Laurent Garnier - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public interface YamlFile { | ||
|
||
/** | ||
* Get the list of elements present in the YAML file. | ||
* | ||
* @return the list of elements | ||
*/ | ||
List<? extends YamlElement> getElements(); | ||
|
||
/** | ||
* Get the version present in the YAML file. | ||
* | ||
* @return the version in the file | ||
*/ | ||
int getVersion(); | ||
|
||
/** | ||
* Check that the file content is valid. | ||
* It includes the check of duplicated elements (same identifier) and the check of each element. | ||
* | ||
* @return true if all the checks are OK | ||
*/ | ||
boolean isValid(); | ||
} |
75 changes: 75 additions & 0 deletions
75
....openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/YamlModelListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.model.yaml; | ||
|
||
import java.util.Collection; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* The {@link YamlModelListener} interface is responsible for managing a particular model type | ||
* with data processed from YAML configuration files. | ||
* | ||
* @author Laurent Garnier - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public interface YamlModelListener<T extends YamlElement> { | ||
|
||
/** | ||
* Method called by the model repository when elements from a model are added. | ||
* | ||
* @param modelName the name of the model | ||
* @param elements the collection of added elements | ||
*/ | ||
void addedModel(String modelName, Collection<? extends YamlElement> elements); | ||
|
||
/** | ||
* Method called by the model repository when elements from a model are updated. | ||
* | ||
* @param modelName the name of the model | ||
* @param elements the collection of updated elements | ||
*/ | ||
void updatedModel(String modelName, Collection<? extends YamlElement> elements); | ||
|
||
/** | ||
* Method called by the model repository when elements from a model are removed. | ||
* | ||
* @param modelName the name of the model | ||
* @param elements the collection of removed elements | ||
*/ | ||
void removedModel(String modelName, Collection<? extends YamlElement> elements); | ||
|
||
/** | ||
* Get the root name of this model type which is also the name of the root folder | ||
* containing the user files for this model type. | ||
* | ||
* A path is unexpected. What is expected is for example "items" or "things". | ||
* | ||
* @return the model root name | ||
*/ | ||
String getRootName(); | ||
|
||
/** | ||
* Get the DTO class to be used for a file providing objects for this model type. | ||
* | ||
* @return the DTO file class | ||
*/ | ||
Class<? extends AbstractYamlFile> getFileClass(); | ||
|
||
/** | ||
* Get the DTO class to be used for each object of this model type. | ||
* | ||
* @return the DTO element class | ||
*/ | ||
Class<T> getElementClass(); | ||
} |
39 changes: 39 additions & 0 deletions
39
...openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/YamlParseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.model.yaml; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* The {@link YamlParseException} is used when an error is detected when parsing the content | ||
* of a YAML configuration file. | ||
* | ||
* @author Laurent Garnier - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class YamlParseException extends Exception { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public YamlParseException(String message) { | ||
super(message); | ||
} | ||
|
||
public YamlParseException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public YamlParseException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
Oops, something went wrong.