Skip to content

Commit

Permalink
Merge branch 'openhab:main' into CryptoStore
Browse files Browse the repository at this point in the history
  • Loading branch information
morph166955 authored Jul 10, 2023
2 parents 27d2d12 + 591b16f commit b50e7a2
Show file tree
Hide file tree
Showing 838 changed files with 16,863 additions and 9,352 deletions.
45 changes: 45 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: "🐛 Bug report"
about: Something isn't working correctly in the Core. This is the wrong place for openHAB user-interface or add-on issues
labels: bug

---

<!-- Provide a general summary of the issue in the *Title* above -->

<!-- Important: Please contact the openHAB community forum for questions or -->
<!-- for configuration and usage guidance: https://community.openhab.org -->

<!-- Feel free to delete any comment lines in the template (starting with "<!--") -->

## Expected Behavior
<!-- If you're describing a bug, tell us what should happen -->
<!-- If you're suggesting a change/improvement, tell us how it should work -->

## Current Behavior
<!-- If describing a bug, tell us what happens instead of the expected behavior -->
<!-- Include related log information (preferably debug level) and related configs -->
<!-- Use a file attachment for log and config information longer than a few lines -->
<!-- Enclose multi-line log/code snippets with ``` on new lines for proper formatting -->
<!-- If suggesting a change/improvement, explain the difference from current behavior -->
<!-- For improvements, discuss at community.openhab.org first and include link to topic -->

## Possible Solution
<!-- Not obligatory, but suggest a fix/reason for the bug, -->
<!-- or ideas how to implement the addition or change -->

## Steps to Reproduce (for Bugs)
<!-- Provide a link to a live example, or an unambiguous set of steps to -->
<!-- reproduce this bug. Include code to reproduce, if relevant -->
1.
2.

## Context
<!-- How has this issue affected you? What are you trying to accomplish? -->
<!-- Providing context helps us come up with a solution that is most useful in the real world -->

## Your Environment
<!-- Include as many relevant details about the environment you experienced the bug in -->
* Version used: (e.g., openHAB and add-on versions)
* Environment name and version (e.g. Chrome 111, Java 17, Node.js 18.15, ...):
* Operating System and version (desktop or mobile, Windows 11, Raspbian Bullseye, ...):
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
blank_issues_enabled: true
contact_links:
- name: 🤔 Support/Usage Question
url: https://community.openhab.org
about: Feel free to ask anything
- name: 📖 Documentation
url: https://www.openhab.org/docs/
about: Official documentation
- name: 📚 Translation feedback
url: https://crowdin.com/project/openhab-core
about: Share feedback on translations
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: "✨ Feature request"
about: You think that the Core should gain another feature
labels: enhancement

---

<!-- Provide a general summary of the feature request in the *Title* above -->

<!-- Important: Please contact the openHAB community forum for questions or -->
<!-- for configuration and usage guidance: https://community.openhab.org -->

## Your Environment
<!-- Include as many relevant details about the environment when applicable -->
* Version used: (e.g., openHAB and add-on versions)
* Environment name and version (e.g. Chrome 111, Java 17, Node.js 18.15, ...):
* Operating System and version (desktop or mobile, Windows 11, Raspbian Bullseye, ...):
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Suggest a Sitemap change
name: 🗺 Sitemap change
about: 'Suggest a change in the Sitemap syntax and corresponding UIs'
labels: sitemap
---
Expand Down
47 changes: 47 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--
Thanks for contributing to the openHAB project!
Please describe the goal and effect of your PR here.
Pay attention to the below notes and to *the guidelines* for this repository.
Feel free to delete any comment sections in the template (starting with "<!--").
ATTENTION: Don't use "git merge" when working with your pull request branch!
This can clutter your Git history and make your PR unusable.
Use "git rebase" instead. See this forum post for further details:
https://community.openhab.org/t/rebase-your-code-or-how-to-fix-your-git-history-before-requesting-a-pull/129358
All PRs should be created using the "main" branch as base.
Important bugfixes are cherry-picked by maintainers to the patch release branch after a PR has been merged.
If your PR's code is not backward compatible with previous releases (which
should be avoided), add a message to the release notes by filing another PR:
https://github.com/openhab/openhab-distro/blob/main/distributions/openhab/src/main/resources/bin/update.lst
# Title
Provide a short summary in the *Title* above. It will show up in the release notes.
For example:
- Introduce metadata for all add-ons
- Fix memory leak in ScriptedRuleProvider
# Description
Please give a few sentences describing the overall goals of the pull request.
Give enough details to make the improvement and changes of the PR understandable
to both developers and tech-savy users.
Please keep the following in mind:
- What is the classification of the PR, e.g. Bugfix, Improvement, Novel Addition, ... ?
- Did you describe the PRs motivation and goal?
- Did you provide a link to any prior discussion, e.g. an issue or community forum thread?
- Did you describe new features for the end user?
- Did you describe any noteworthy changes in usage for the end user?
- Was the documentation updated accordingly, e.g. the Core README?
- Does your contribution follow the coding guidelines:
https://www.openhab.org/docs/developer/guidelines.html
- Did you check for any (relevant) issues from the static code analysis?
- Did you sign-off your work:
https://www.openhab.org/docs/developer/contributing.html#sign-your-work
If your pull request contains a new contribution, it will likely take some time
before it is reviewed and processed by maintainers.
-->
8 changes: 7 additions & 1 deletion bom/compile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@
<version>${jetty.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
<version>${jetty.version}</version>
<scope>compile</scope>
</dependency>

<!-- JmDNS -->
<dependency>
Expand Down Expand Up @@ -407,7 +413,7 @@
<dependency>
<groupId>org.bitbucket.b_c</groupId>
<artifactId>jose4j</artifactId>
<version>0.7.7</version>
<version>0.9.3</version>
<scope>compile</scope>
</dependency>

Expand Down
12 changes: 9 additions & 3 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
<dependency>
<groupId>org.apache.aries.spifly</groupId>
<artifactId>org.apache.aries.spifly.dynamic.bundle</artifactId>
<version>1.3.4</version>
<version>1.3.6</version>
</dependency>

<!-- END: Slightly modified EnRoute implementation index artifacts -->
Expand Down Expand Up @@ -392,7 +392,7 @@
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
<version>1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -757,6 +757,12 @@
<version>${jetty.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
<version>${jetty.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-client</artifactId>
Expand Down Expand Up @@ -967,7 +973,7 @@
<dependency>
<groupId>org.bitbucket.b_c</groupId>
<artifactId>jose4j</artifactId>
<version>0.7.7</version>
<version>0.9.3</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ public boolean supports(String type, String contentType) {
}

private Stream<Path> karFilesStream(Path addonDirectory) throws IOException {
return Files.isDirectory(addonDirectory) ? Files.list(addonDirectory).map(Path::getFileName)
.filter(path -> path.toString().endsWith(KAR_EXTENSION)) : Stream.empty();
if (Files.isDirectory(addonDirectory)) {
try (Stream<Path> files = Files.list(addonDirectory)) {
return files.map(Path::getFileName).filter(path -> path.toString().endsWith(KAR_EXTENSION)).toList()
.stream();
}
}
return Stream.empty();
}

private String pathToKarRepoName(Path path) {
Expand Down Expand Up @@ -153,8 +158,8 @@ private void addKarToCache(String addonId, URL sourceUrl) throws MarketplaceHand
private void installFromCache(String addonId) throws MarketplaceHandlerException {
Path addonPath = getAddonCacheDirectory(addonId);
if (Files.isDirectory(addonPath)) {
try {
List<Path> karFiles = Files.list(addonPath).collect(Collectors.toList());
try (Stream<Path> files = Files.list(addonPath)) {
List<Path> karFiles = files.toList();
if (karFiles.size() != 1) {
throw new MarketplaceHandlerException(
"The local cache folder doesn't contain a single file: " + addonPath, null);
Expand All @@ -172,20 +177,20 @@ private void installFromCache(String addonId) throws MarketplaceHandlerException
}

private void ensureCachedKarsAreInstalled() {
try {
if (Files.isDirectory(KAR_CACHE_PATH)) {
Files.list(KAR_CACHE_PATH).filter(Files::isDirectory).map(this::addonIdFromPath)
.filter(addonId -> !isInstalled(addonId)).forEach(addonId -> {
if (Files.isDirectory(KAR_CACHE_PATH)) {
try (Stream<Path> files = Files.list(KAR_CACHE_PATH)) {
files.filter(Files::isDirectory).map(this::addonIdFromPath).filter(addonId -> !isInstalled(addonId))
.forEach(addonId -> {
logger.info("Reinstalling missing marketplace KAR: {}", addonId);
try {
installFromCache(addonId);
} catch (MarketplaceHandlerException e) {
logger.warn("Failed reinstalling add-on from cache", e);
}
});
} catch (IOException e) {
logger.warn("Failed to re-install KARs: {}", e.getMessage());
}
} catch (IOException e) {
logger.warn("Failed to re-install KARs: {}", e.getMessage());
}
isReady = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -29,6 +30,8 @@
import org.openhab.core.OpenHAB;
import org.openhab.core.addon.Addon;
import org.openhab.core.addon.AddonEventFactory;
import org.openhab.core.addon.AddonInfo;
import org.openhab.core.addon.AddonInfoRegistry;
import org.openhab.core.addon.AddonService;
import org.openhab.core.addon.AddonType;
import org.openhab.core.cache.ExpiringCache;
Expand All @@ -45,6 +48,7 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;

/**
* The {@link AbstractRemoteAddonService} implements basic functionality of a remote add-on-service
Expand All @@ -65,13 +69,15 @@ public abstract class AbstractRemoteAddonService implements AddonService {
protected final ConfigurationAdmin configurationAdmin;
protected final ExpiringCache<List<Addon>> cachedRemoteAddons = new ExpiringCache<>(Duration.ofMinutes(15),
this::getRemoteAddons);
protected final AddonInfoRegistry addonInfoRegistry;
protected List<Addon> cachedAddons = List.of();
protected List<String> installedAddons = List.of();

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

public AbstractRemoteAddonService(EventPublisher eventPublisher, ConfigurationAdmin configurationAdmin,
StorageService storageService, String servicePid) {
StorageService storageService, AddonInfoRegistry addonInfoRegistry, String servicePid) {
this.addonInfoRegistry = addonInfoRegistry;
this.eventPublisher = eventPublisher;
this.configurationAdmin = configurationAdmin;
this.installedAddonStorage = storageService.getStorage(servicePid);
Expand All @@ -82,6 +88,16 @@ protected BundleVersion getCoreVersion() {
return new BundleVersion(FrameworkUtil.getBundle(OpenHAB.class).getVersion().toString());
}

private Addon convertFromStorage(Map.Entry<String, @Nullable String> entry) {
Addon storedAddon = Objects.requireNonNull(gson.fromJson(entry.getValue(), Addon.class));
AddonInfo addonInfo = addonInfoRegistry.getAddonInfo(storedAddon.getType() + "-" + storedAddon.getId());
if (addonInfo != null && storedAddon.getConfigDescriptionURI().isBlank()) {
return Addon.create(storedAddon).withConfigDescriptionURI(addonInfo.getConfigDescriptionURI()).build();
} else {
return storedAddon;
}
}

@Override
public void refreshSource() {
if (!addonHandlers.stream().allMatch(MarketplaceAddonHandler::isReady)) {
Expand All @@ -90,8 +106,15 @@ public void refreshSource() {
return;
}
List<Addon> addons = new ArrayList<>();
installedAddonStorage.stream().map(e -> Objects.requireNonNull(gson.fromJson(e.getValue(), Addon.class)))
.forEach(addons::add);
try {
installedAddonStorage.stream().map(this::convertFromStorage).forEach(addons::add);
} catch (JsonSyntaxException e) {
List.copyOf(installedAddonStorage.getKeys()).forEach(installedAddonStorage::remove);
logger.error(
"Failed to read JSON database, trying to purge it. You might need to re-install {} from the '{}' service.",
installedAddonStorage.getKeys(), getId());
refreshSource();
}

// create lookup list to make sure installed addons take precedence
List<String> installedAddons = addons.stream().map(Addon::getUid).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.OpenHAB;
Expand Down Expand Up @@ -79,8 +79,8 @@ protected void addBundleToCache(String addonId, URL sourceUrl) throws Marketplac
protected void installFromCache(BundleContext bundleContext, String addonId) throws MarketplaceHandlerException {
Path addonPath = getAddonCacheDirectory(addonId);
if (Files.isDirectory(addonPath)) {
try {
List<Path> bundleFiles = Files.list(addonPath).collect(Collectors.toList());
try (Stream<Path> files = Files.list(addonPath)) {
List<Path> bundleFiles = files.toList();
if (bundleFiles.size() != 1) {
throw new MarketplaceHandlerException(
"The local cache folder doesn't contain a single file: " + addonPath, null);
Expand Down Expand Up @@ -122,8 +122,10 @@ protected void uninstallBundle(BundleContext bundleContext, String addonId) thro
try {
Path addonPath = getAddonCacheDirectory(addonId);
if (Files.isDirectory(addonPath)) {
for (Path bundleFile : Files.list(addonPath).collect(Collectors.toList())) {
Files.delete(bundleFile);
try (Stream<Path> files = Files.list(addonPath)) {
for (Path path : files.toList()) {
Files.delete(path);
}
}
}
Files.delete(addonPath);
Expand All @@ -147,9 +149,9 @@ protected void uninstallBundle(BundleContext bundleContext, String addonId) thro
* @param bundleContext the {@link BundleContext} to use to look up the bundles
*/
protected void ensureCachedBundlesAreInstalled(BundleContext bundleContext) {
try {
if (Files.isDirectory(BUNDLE_CACHE_PATH)) {
Files.list(BUNDLE_CACHE_PATH).filter(Files::isDirectory).map(this::addonIdFromPath)
if (Files.isDirectory(BUNDLE_CACHE_PATH)) {
try (Stream<Path> files = Files.list(BUNDLE_CACHE_PATH)) {
files.filter(Files::isDirectory).map(this::addonIdFromPath)
.filter(addonId -> !isBundleInstalled(bundleContext, addonId)).forEach(addonId -> {
logger.info("Reinstalling missing marketplace bundle: {}", addonId);
try {
Expand All @@ -158,9 +160,9 @@ protected void ensureCachedBundlesAreInstalled(BundleContext bundleContext) {
logger.warn("Failed reinstalling add-on from cache", e);
}
});
} catch (IOException e) {
logger.warn("Failed to re-install bundles: {}", e.getMessage());
}
} catch (IOException e) {
logger.warn("Failed to re-install bundles: {}", e.getMessage());
}
}

Expand Down
Loading

0 comments on commit b50e7a2

Please sign in to comment.