Skip to content

Commit

Permalink
Merge branch 'openhab:main' into feature/s-bus
Browse files Browse the repository at this point in the history
  • Loading branch information
cipianpascu committed Jan 17, 2024
2 parents c203b2f + 0b1e1b6 commit 64c6d7d
Show file tree
Hide file tree
Showing 2,214 changed files with 4,267 additions and 3,421 deletions.
18 changes: 4 additions & 14 deletions bom/compile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<dependency>
<groupId>org.jmdns</groupId>
<artifactId>jmdns</artifactId>
<version>3.5.7</version>
<version>3.5.9</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -364,20 +364,10 @@

<!-- jollyday -->
<dependency>
<groupId>de.jollyday</groupId>
<artifactId>jollyday</artifactId>
<version>0.5.10</version>
<groupId>de.focus-shift</groupId>
<artifactId>jollyday-jackson</artifactId>
<version>0.23.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- JAXB -->
Expand Down
24 changes: 10 additions & 14 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<version>1.5.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.5.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
Expand Down Expand Up @@ -461,7 +467,7 @@
<dependency>
<groupId>org.jmdns</groupId>
<artifactId>jmdns</artifactId>
<version>3.5.8</version>
<version>3.5.9</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -942,20 +948,10 @@

<!-- jollyday -->
<dependency>
<groupId>de.jollyday</groupId>
<artifactId>jollyday</artifactId>
<version>0.5.10</version>
<groupId>de.focus-shift</groupId>
<artifactId>jollyday-jackson</artifactId>
<version>0.23.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- jose4j -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand All @@ -12,6 +12,8 @@
*/
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;
Expand All @@ -25,6 +27,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -36,6 +39,7 @@
import org.openhab.core.addon.AddonService;
import org.openhab.core.addon.AddonType;
import org.openhab.core.cache.ExpiringCache;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.config.core.ConfigParser;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventPublisher;
Expand All @@ -61,11 +65,23 @@ public abstract class AbstractRemoteAddonService implements AddonService {
static final String CONFIG_REMOTE_ENABLED = "remote";
static final String CONFIG_INCLUDE_INCOMPATIBLE = "includeIncompatible";
static final Comparator<Addon> BY_COMPATIBLE_AND_VERSION = (addon1, addon2) -> {
// prefer compatible over incompatible
// prefer compatible to incompatible
int compatible = Boolean.compare(addon2.getCompatible(), addon1.getCompatible());
// prefer newer version over older
return compatible != 0 ? compatible
: new BundleVersion(addon2.getVersion()).compareTo(new BundleVersion(addon1.getVersion()));
if (compatible != 0) {
return compatible;
}
try {
// Add-on versions often contain a dash instead of a dot as separator for the qualifier (e.g. -SNAPSHOT)
// This is not a valid format and everything after the dash needs to be removed.
BundleVersion version1 = new BundleVersion(addon1.getVersion().replaceAll("-.*", ".0"));
BundleVersion version2 = new BundleVersion(addon2.getVersion().replaceAll("-.*", ".0"));

// prefer newer version over older
return version2.compareTo(version1);
} catch (IllegalArgumentException e) {
// assume they are equal (for ordering) if we can't compare the versions
return 0;
}
};

protected final BundleVersion coreVersion;
Expand All @@ -82,8 +98,9 @@ public abstract class AbstractRemoteAddonService implements AddonService {
protected List<String> installedAddons = List.of();

private final Logger logger = LoggerFactory.getLogger(AbstractRemoteAddonService.class);
private final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool(THREAD_POOL_NAME_COMMON);

public AbstractRemoteAddonService(EventPublisher eventPublisher, ConfigurationAdmin configurationAdmin,
protected AbstractRemoteAddonService(EventPublisher eventPublisher, ConfigurationAdmin configurationAdmin,
StorageService storageService, AddonInfoRegistry addonInfoRegistry, String servicePid) {
this.addonInfoRegistry = addonInfoRegistry;
this.eventPublisher = eventPublisher;
Expand Down Expand Up @@ -113,9 +130,14 @@ public void refreshSource() {
getClass());
return;
}

List<Addon> addons = new ArrayList<>();

// retrieve add-ons that should be available from storage and check if they are really installed
// this is safe, because the {@link AddonHandler}s only report ready when they installed everything from the
// cache
try {
installedAddonStorage.stream().map(this::convertFromStorage).forEach(addons::add);
installedAddonStorage.stream().map(this::convertFromStorage).peek(this::setInstalled).forEach(addons::add);
} catch (JsonSyntaxException e) {
List.copyOf(installedAddonStorage.getKeys()).forEach(installedAddonStorage::remove);
logger.error(
Expand All @@ -124,18 +146,21 @@ public void refreshSource() {
refreshSource();
}

// remove not installed add-ons from the add-ons list, but remember their UIDs to re-install them
List<String> missingAddons = addons.stream().filter(addon -> !addon.isInstalled()).map(Addon::getUid).toList();
missingAddons.forEach(installedAddonStorage::remove);
addons.removeIf(addon -> missingAddons.contains(addon.getUid()));

// create lookup list to make sure installed addons take precedence
List<String> installedAddons = addons.stream().map(Addon::getUid).toList();

// get the remote addons
if (remoteEnabled()) {
List<Addon> remoteAddons = Objects.requireNonNullElse(cachedRemoteAddons.getValue(), List.of());
remoteAddons.stream().filter(a -> !installedAddons.contains(a.getUid())).forEach(addons::add);
remoteAddons.stream().filter(a -> !installedAddons.contains(a.getUid())).peek(this::setInstalled)
.forEach(addons::add);
}

// check real installation status based on handlers
addons.forEach(
addon -> addon.setInstalled(addonHandlers.stream().anyMatch(h -> h.isInstalled(addon.getUid()))));

// remove incompatible add-ons if not enabled
boolean showIncompatible = includeIncompatible();
addons.removeIf(addon -> !addon.isInstalled() && !addon.getCompatible() && !showIncompatible);
Expand All @@ -151,6 +176,15 @@ public void refreshSource() {

cachedAddons = addons;
this.installedAddons = installedAddons;

if (!missingAddons.isEmpty()) {
logger.info("Re-installing missing add-ons from remote repository: {}", missingAddons);
scheduler.execute(() -> missingAddons.forEach(this::install));
}
}

private void setInstalled(Addon addon) {
addon.setInstalled(addonHandlers.stream().anyMatch(h -> h.isInstalled(addon.getUid())));
}

/**
Expand Down Expand Up @@ -199,52 +233,57 @@ public List<AddonType> getTypes(@Nullable Locale locale) {
@Override
public void install(String id) {
Addon addon = getAddon(id, null);
if (addon != null) {
for (MarketplaceAddonHandler handler : addonHandlers) {
if (handler.supports(addon.getType(), addon.getContentType())) {
if (!handler.isInstalled(addon.getUid())) {
try {
handler.install(addon);
installedAddonStorage.put(id, gson.toJson(addon));
refreshSource();
postInstalledEvent(addon.getUid());
} catch (MarketplaceHandlerException e) {
postFailureEvent(addon.getUid(), e.getMessage());
}
} else {
postFailureEvent(addon.getUid(), "Add-on is already installed.");
if (addon == null) {
postFailureEvent(id, "Add-on can't be installed because it is not known.");
return;
}
for (MarketplaceAddonHandler handler : addonHandlers) {
if (handler.supports(addon.getType(), addon.getContentType())) {
if (!handler.isInstalled(addon.getUid())) {
try {
handler.install(addon);
addon.setInstalled(true);
installedAddonStorage.put(id, gson.toJson(addon));
refreshSource();
postInstalledEvent(addon.getUid());
} catch (MarketplaceHandlerException e) {
postFailureEvent(addon.getUid(), e.getMessage());
}
return;
} else {
postFailureEvent(addon.getUid(), "Add-on is already installed.");
}
return;
}
}
postFailureEvent(id, "Add-on not known.");
postFailureEvent(id, "Add-on can't be installed because there is no handler for it.");
}

@Override
public void uninstall(String id) {
Addon addon = getAddon(id, null);
if (addon != null) {
for (MarketplaceAddonHandler handler : addonHandlers) {
if (handler.supports(addon.getType(), addon.getContentType())) {
if (handler.isInstalled(addon.getUid())) {
try {
handler.uninstall(addon);
installedAddonStorage.remove(id);
refreshSource();
postUninstalledEvent(addon.getUid());
} catch (MarketplaceHandlerException e) {
postFailureEvent(addon.getUid(), e.getMessage());
}
} else {
if (addon == null) {
postFailureEvent(id, "Add-on can't be uninstalled because it is not known.");
return;
}
for (MarketplaceAddonHandler handler : addonHandlers) {
if (handler.supports(addon.getType(), addon.getContentType())) {
if (handler.isInstalled(addon.getUid())) {
try {
handler.uninstall(addon);
installedAddonStorage.remove(id);
postFailureEvent(addon.getUid(), "Add-on is not installed.");
refreshSource();
postUninstalledEvent(addon.getUid());
} catch (MarketplaceHandlerException e) {
postFailureEvent(addon.getUid(), e.getMessage());
}
return;
} else {
installedAddonStorage.remove(id);
postFailureEvent(addon.getUid(), "Add-on is not installed.");
}
return;
}
}
postFailureEvent(id, "Add-on not known.");
postFailureEvent(id, "Add-on can't be uninstalled because there is no handler for it.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down Expand Up @@ -129,15 +129,15 @@ public void addTemplateAsJSON(String uid, String json) throws ParsingException {
* This adds a new rule template to the persistent storage from its YAML representation.
*
* @param uid the UID to be used for the template
* @param json the template content as a YAML string
* @param yaml the template content as a YAML string
*
* @throws ParsingException if the content cannot be parsed correctly
*/
public void addTemplateAsYAML(String uid, String yaml) throws ParsingException {
try {
RuleTemplateDTO dto = yamlMapper.readValue(yaml, RuleTemplateDTO.class);
// add a tag with the add-on ID to be able to identify the widget in the registry
dto.tags = new HashSet<@Nullable String>((dto.tags != null) ? dto.tags : new HashSet<String>());
dto.tags = new HashSet<@Nullable String>((dto.tags != null) ? dto.tags : new HashSet<>());
dto.tags.add(uid);
RuleTemplate entry = RuleTemplateDTOMapper.map(dto);
RuleTemplate template = new RuleTemplate(entry.getUID(), entry.getLabel(), entry.getDescription(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down
Loading

0 comments on commit 64c6d7d

Please sign in to comment.