-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[addonsinfoprovider] Addon for providing addon-info of other addons #15780
Closed
Closed
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f9429a0
[addonsuggestionfinder] initial contribution
andrewfg 86335c9
[addonsuggestionfinder] delete addons.xml
andrewfg 82f22db
[addonsuggestionfinder] ignore addons.xml
andrewfg 4d86b85
[addonsuggestionfinder] fix addon ids
andrewfg 80ba2fa
[addonsuggestionfinder] refactoring
andrewfg 0434443
[addonsuggestionfinder] refactoring
andrewfg fd25845
[addonsuggestionfinder] add binding test cases
andrewfg 48d8df3
[addonsuggestionfinder] adopt reviewer suggestions
andrewfg 615c693
[addonsuggestionfinder] log PatternSyntaxException errors
andrewfg 81e0d30
[addonsuggestionfinder] use uid rather than id
andrewfg 1de4eea
[addonsuggestionfinder] refactor unit test from addon to core
andrewfg d5785e9
[addonsuggestionfinder] remove hue, hp
andrewfg d2f8199
[addonsuggestionfinder] shorten read me
andrewfg 9a4769b
[addonsuggestionfinder] add regex syntax checks
andrewfg 9e837a7
[addonsuggestionfinder] improve addon description
andrewfg 4e52ccb
[addonsinfoprovider] rename addon
andrewfg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ | ||
/src/main/resources/addons.xml |
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,13 @@ | ||
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-addons |
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,80 @@ | ||
# AddonSuggestionFinder Addon | ||
|
||
This is a special addon that implements an `AddonInfoProvider` service containing information about suggested Addons that could potentially be installed. | ||
It allows developers to include information in their own addons so that the system can scan the user's network to discover potential addons that can automatically be installed. | ||
|
||
## Addon Developer Notes | ||
|
||
If you want to your addon to scan the user's system then you need to include additional fields in your `src/main/resources/OH-INF/addon.xml` file. | ||
|
||
| XML Element Name | Description | Instances | | ||
|---------------------|-------------------------------------------------------------------------------|------------------------------------------------| | ||
| `discovery-methods` | Wrapper for `discovery-method` elements (see below). | Zero or one instances per file. | | ||
| `discovery-method` | Complex XML element describing an addon discovery method. | Zero or more instances per file. | | ||
| `service-type` | The type of discovery method. May be `upnp` or `mdns`. | Mandatory one per `discovery-method`. | | ||
| `mdns-service-type` | If `service-type` is `mdns`, contains the MDNS discovery service type. | Optional one per `discovery-method`. | | ||
| `match-properties` | Wrapper for `match-property` elements (see below). | Zero or one instances per `discovery-method`. | | ||
| `match-property` | A property name and regular expression used for matching discovery findings. | Zero or more instances per `discovery-method`. | | ||
| `name` | A property name to search for. | Mandatory one instance per `match-property`. | | ||
| `regex` | A regular expression (or plain string) that needs to match the property name. | Mandatory one instance per `match-property`. | | ||
|
||
## Example `addon.xml` File | ||
|
||
The following is an example for the discovery XML description for HP Printers. | ||
|
||
```xml | ||
<addon:addon id="hpprinter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:addon="https://openhab.org/schemas/addon/v1.0.0" | ||
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0 https://openhab.org/schemas/addon-1.0.0.xsd"> | ||
|
||
<type>binding</type> | ||
<name>HP Printer</name> | ||
<description>HP Printer Binding</description> | ||
<connection>local</connection> | ||
<discovery-methods> | ||
<discovery-method> | ||
<service-type>mdns</service-type> | ||
<mdns-service-type>_printer._tcp.local.</mdns-service-type> | ||
<match-properties> | ||
<match-property> | ||
<name>rp</name> | ||
<regex>.*</regex> | ||
</match-property> | ||
<match-property> | ||
<name>ty</name> | ||
<regex>hp (.*)</regex> | ||
</match-property> | ||
</match-properties> | ||
</discovery-method> | ||
</discovery-methods> | ||
</addon:addon> | ||
``` | ||
|
||
The following is an example for the discovery XML description for the Philips Hue bridge. | ||
|
||
```xml | ||
<addon:addon id="hue" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:addon="https://openhab.org/schemas/addon/v1.0.0" | ||
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0 https://openhab.org/schemas/addon-1.0.0.xsd"> | ||
|
||
<type>binding</type> | ||
<name>Philips Hue</name> | ||
<description>Philips Hue Binding</description> | ||
<connection>local</connection> | ||
<discovery-methods> | ||
<discovery-method> | ||
<serviceType>mdns</serviceType> | ||
<mdnsServiceType>_hue._tcp.local.</mdnsServiceType> | ||
</discovery-method> | ||
<discovery-method> | ||
<service-type>upnp</service-type> | ||
</match-properties> | ||
<match-property> | ||
<name>modelName</name> | ||
<regex>Philips hue bridge</regex> | ||
</match-property> | ||
</match-properties> | ||
</discovery-method> | ||
</discovery-methods> | ||
</addon:addon> | ||
``` |
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,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
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.addons.bundles</groupId> | ||
<artifactId>org.openhab.addons.reactor.bundles</artifactId> | ||
<version>4.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.openhab.misc.addonsuggestionfinder</artifactId> | ||
|
||
<name>openHAB Add-ons :: Bundles :: Addon Suggestion Finder</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<inherited>false</inherited> | ||
<executions> | ||
<execution> | ||
<id>create-addonsinfo</id> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<phase>generate-sources</phase> | ||
<configuration> | ||
<target> | ||
<concat destfile="src/main/resources/addons.xml"> | ||
<header file="src/main/resources/header.xml" filtering="no"/> | ||
<fileset dir="${basedirRoot}/bundles"> | ||
<include name="*/src/main/resources/OH-INF/addon/addon.xml"/> | ||
</fileset> | ||
<filterchain> | ||
<linecontainsRegExp negate="true"> | ||
<regexp pattern="<\?xml"/> | ||
</linecontainsRegExp> | ||
</filterchain> | ||
<footer file="src/main/resources/footer.xml" filtering="no"/> | ||
</concat> | ||
</target> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
9 changes: 9 additions & 0 deletions
9
bundles/org.openhab.misc.addonsuggestionfinder/src/main/feature/feature.xml
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,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<features name="org.openhab.misc.addonsuggestionfinder-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0"> | ||
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository> | ||
|
||
<feature name="openhab-misc-addonsuggestionfinder" description="Addon Suggestion Finder" version="${project.version}"> | ||
<feature>openhab-runtime-base</feature> | ||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.misc.addonsuggestionfinder/${project.version}</bundle> | ||
</feature> | ||
</features> |
89 changes: 89 additions & 0 deletions
89
...der/src/main/java/org/openhab/misc/addonsuggestionfinder/AddonSuggestionInfoProvider.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,89 @@ | ||
/** | ||
* 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.misc.addonsuggestionfinder; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashSet; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import java.util.regex.PatternSyntaxException; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.addon.AddonInfo; | ||
import org.openhab.core.addon.AddonInfoList; | ||
import org.openhab.core.addon.AddonInfoListReader; | ||
import org.openhab.core.addon.AddonInfoProvider; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link AddonSuggestionInfoProvider} provides a list of candidate suggested addons to be installed. | ||
* | ||
* @author Andrew Fiddian-Green - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
@Component(name = "addon-suggestion-info-provider", service = AddonInfoProvider.class) | ||
public class AddonSuggestionInfoProvider implements AddonInfoProvider { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(AddonSuggestionInfoProvider.class); | ||
private final Set<AddonInfo> candidateAddonInfos = new HashSet<>(); | ||
|
||
@Activate | ||
public AddonSuggestionInfoProvider() { | ||
setCandidates(getResourceXml()); | ||
} | ||
|
||
@Override | ||
public @Nullable AddonInfo getAddonInfo(@Nullable String id, @Nullable Locale locale) { | ||
return candidateAddonInfos.stream().filter(a -> a.getId().equals(id)).findFirst().orElse(null); | ||
andrewfg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
public Set<AddonInfo> getAddonInfos(@Nullable Locale locale) { | ||
return candidateAddonInfos; | ||
} | ||
|
||
private String getResourceXml() { | ||
ClassLoader loader = getClass().getClassLoader(); | ||
if (loader != null) { | ||
InputStream stream = loader.getResourceAsStream("addons.xml"); | ||
if (stream != null) { | ||
try { | ||
return new String(stream.readAllBytes(), StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
} | ||
} | ||
} | ||
throw new IllegalStateException("Error loading 'addons.xml' resource"); | ||
} | ||
|
||
public void setCandidates(String xml) { | ||
candidateAddonInfos.clear(); | ||
AddonInfoListReader reader = new AddonInfoListReader(); | ||
try { | ||
AddonInfoList addonInfoList = reader.readFromXML(xml); | ||
if (addonInfoList != null) { | ||
candidateAddonInfos.addAll(addonInfoList.getAddons().stream().collect(Collectors.toSet())); | ||
} | ||
} catch (PatternSyntaxException e) { | ||
logger.warn("PatternSyntaxException: message:{}, description:{}, pattern:{}, index:{}", e.getMessage(), | ||
e.getDescription(), e.getPattern(), e.getIndex(), e); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
bundles/org.openhab.misc.addonsuggestionfinder/src/main/resources/OH-INF/addon/addon.xml
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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<addon:addon id="addonsuggestionfinder" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:addon="https://openhab.org/schemas/addon/v1.0.0" | ||
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0 https://openhab.org/schemas/addon-1.0.0.xsd"> | ||
|
||
<type>misc</type> | ||
<name>Addon Suggestion Finder</name> | ||
<description>This is a special addon for finding suggested addons to be installed on setup.</description> | ||
|
||
</addon:addon> |
3 changes: 3 additions & 0 deletions
3
bundles/org.openhab.misc.addonsuggestionfinder/src/main/resources/footer.xml
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,3 @@ | ||
|
||
</addons> | ||
</addon-info-list> |
16 changes: 16 additions & 0 deletions
16
bundles/org.openhab.misc.addonsuggestionfinder/src/main/resources/header.xml
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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 | ||
--> | ||
|
||
<addon-info-list> | ||
<addons> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be documented here, i.e. through the openhab-docs repository:
https://www.openhab.org/docs/developer/addons/addon.html#xml-structure-for-add-on-definitions
A link could be provided here, but probably the contents should be removed to avoid double maintenance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. But let us keep it here for now, until we make more progress on the total package.