diff options
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java | 34 | ||||
-rw-r--r-- | container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java | 4 |
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."; } |