diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java index da7bffa5c..dc4babf08 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java @@ -15,7 +15,6 @@ package org.openhab.core.addon.marketplace; import static org.openhab.core.common.ThreadPoolManager.THREAD_POOL_NAME_COMMON; import java.io.IOException; -import java.net.URI; import java.time.Duration; import java.util.ArrayList; import java.util.Comparator; @@ -95,7 +94,7 @@ public abstract class AbstractRemoteAddonService implements AddonService { this::getRemoteAddons); protected final AddonInfoRegistry addonInfoRegistry; protected List cachedAddons = List.of(); - protected List installedAddons = List.of(); + protected List installedAddonIds = List.of(); private final Logger logger = LoggerFactory.getLogger(AbstractRemoteAddonService.class); private final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool(THREAD_POOL_NAME_COMMON); @@ -137,7 +136,10 @@ public abstract class AbstractRemoteAddonService implements AddonService { // this is safe, because the {@link AddonHandler}s only report ready when they installed everything from the // cache try { - installedAddonStorage.stream().map(this::convertFromStorage).peek(this::setInstalled).forEach(addons::add); + installedAddonStorage.stream().map(this::convertFromStorage).forEach(addon -> { + setInstalled(addon); + addons.add(addon); + }); } catch (JsonSyntaxException e) { List.copyOf(installedAddonStorage.getKeys()).forEach(installedAddonStorage::remove); logger.error( @@ -152,13 +154,15 @@ public abstract class AbstractRemoteAddonService implements AddonService { addons.removeIf(addon -> missingAddons.contains(addon.getUid())); // create lookup list to make sure installed addons take precedence - List installedAddons = addons.stream().map(Addon::getUid).toList(); + List currentAddonIds = addons.stream().map(Addon::getUid).toList(); // get the remote addons if (remoteEnabled()) { List remoteAddons = Objects.requireNonNullElse(cachedRemoteAddons.getValue(), List.of()); - remoteAddons.stream().filter(a -> !installedAddons.contains(a.getUid())).peek(this::setInstalled) - .forEach(addons::add); + remoteAddons.stream().filter(a -> !currentAddonIds.contains(a.getUid())).forEach(addon -> { + setInstalled(addon); + addons.add(addon); + }); } // remove incompatible add-ons if not enabled @@ -175,7 +179,7 @@ public abstract class AbstractRemoteAddonService implements AddonService { } cachedAddons = addons; - this.installedAddons = installedAddons; + this.installedAddonIds = currentAddonIds; if (!missingAddons.isEmpty()) { logger.info("Re-installing missing add-ons from remote repository: {}", missingAddons); @@ -222,9 +226,6 @@ public abstract class AbstractRemoteAddonService implements AddonService { return cachedAddons; } - @Override - public abstract @Nullable Addon getAddon(String id, @Nullable Locale locale); - @Override public List getTypes(@Nullable Locale locale) { return AddonType.DEFAULT_TYPES; @@ -244,6 +245,7 @@ public abstract class AbstractRemoteAddonService implements AddonService { handler.install(addon); addon.setInstalled(true); installedAddonStorage.put(id, gson.toJson(addon)); + cachedRemoteAddons.invalidateValue(); refreshSource(); postInstalledEvent(addon.getUid()); } catch (MarketplaceHandlerException e) { @@ -271,6 +273,7 @@ public abstract class AbstractRemoteAddonService implements AddonService { try { handler.uninstall(addon); installedAddonStorage.remove(id); + cachedRemoteAddons.invalidateValue(); refreshSource(); postUninstalledEvent(addon.getUid()); } catch (MarketplaceHandlerException e) { @@ -286,9 +289,6 @@ public abstract class AbstractRemoteAddonService implements AddonService { postFailureEvent(id, "Add-on can't be uninstalled because there is no handler for it."); } - @Override - public abstract @Nullable String getAddonId(URI addonURI); - /** * check if remote services are enabled * diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java index 4ab130f42..3d791d447 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java @@ -205,7 +205,7 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService // check if it is an installed add-on (cachedAddons also contains possibly incomplete results from the remote // side, we need to retrieve them from Discourse) - if (installedAddons.contains(queryId)) { + if (installedAddonIds.contains(queryId)) { return cachedAddons.stream().filter(e -> queryId.equals(e.getUid())).findAny().orElse(null); }