aboutsummaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2023-01-06 10:24:00 +0100
committergjoranv <gv@verizonmedia.com>2023-01-09 13:00:13 +0100
commit0a73fdd941994cbeb5ac3f09dfc7f640ed661669 (patch)
tree7dcab8c17a92ccaa7ed734c4975af76907da1164 /container-core
parent516a0b0c6ab03e9a6f42b4f08f6964db90970a21 (diff)
Add more improvements to bundle resolution error message:
- Add already installed bundles with same symbolic name. - Only include message for version qualifier if relevant.
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java34
-rw-r--r--container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java4
2 files changed, 33 insertions, 5 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
index 903169b1795..85797444de8 100644
--- a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
+++ b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
@@ -4,6 +4,7 @@ package com.yahoo.container.core.config;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.yahoo.component.AbstractComponent;
+import com.yahoo.component.ComponentSpecification;
import com.yahoo.component.annotation.Inject;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.concurrent.ThreadFactoryFactory;
@@ -22,9 +23,11 @@ import com.yahoo.jdisc.service.ServerProvider;
import com.yahoo.osgi.OsgiImpl;
import com.yahoo.osgi.OsgiWrapper;
import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -111,12 +114,37 @@ public class HandlersConfigurerDi {
}
@Override
- protected String bundleResolutionErrorMessage() {
- return String.format("Installed application bundles: [%s].",
- applicationBundleLoader.activeBundlesBsnVersion().stream()
+ protected String bundleResolutionErrorMessage(ComponentSpecification bundleSpec) {
+ List<BsnVersion> activeBundles = applicationBundleLoader.activeBundlesBsnVersion();
+ List<Version> activeVersions = activeVersionsOfBundle(bundleSpec, activeBundles);
+
+ String versionsMessage = "";
+ if (activeVersions.size() == 1) {
+ versionsMessage = "There is an installed bundle with the same name with version: " + activeVersions.get(0);
+ } else if (activeVersions.size() > 1) {
+ versionsMessage = "There are installed bundles with the same name with versions: " + activeVersions;
+ }
+ if (qualifierIsUsed(bundleSpec, activeVersions)) {
+ versionsMessage += " Note that qualifier strings must be matched exactly";
+ }
+ return String.format("%s. Installed application bundles: [%s]",
+ versionsMessage,
+ activeBundles.stream()
.map(BsnVersion::toReadableString)
.collect(Collectors.joining(", ")));
}
+
+ private static boolean qualifierIsUsed(ComponentSpecification bundleSpec, List<Version> activeVersions) {
+ return ! bundleSpec.getVersionSpecification().getQualifier().isEmpty() ||
+ activeVersions.stream().anyMatch(version -> ! version.getQualifier().isEmpty());
+ }
+
+ private static List<Version> activeVersionsOfBundle(ComponentSpecification bundleSpec, List<BsnVersion> activeBundles) {
+ return activeBundles.stream()
+ .filter(bundle -> bundle.symbolicName().equals(bundleSpec.getName()))
+ .map(BsnVersion::version)
+ .collect(Collectors.toList());
+ }
}
/**
diff --git a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
index f0f9de9fe36..7d5f1472e45 100644
--- a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
+++ b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
@@ -88,10 +88,10 @@ public class OsgiImpl implements Osgi {
throw new IllegalArgumentException(
"Could not create a component with id '" + spec.classId.getName() +
"'. Tried to load class directly, since no bundle was found for spec: " + spec.bundle +
- ". " + bundleResolutionErrorMessage());
+ ". " + bundleResolutionErrorMessage(spec.bundle));
}
- protected String bundleResolutionErrorMessage() {
+ protected String bundleResolutionErrorMessage(ComponentSpecification bundleSpec) {
return " If a bundle with the same name is installed, there is a either a version mismatch " +
"or the installed bundle's version contains a qualifier string.";
}