summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2022-05-08 20:02:12 +0200
committergjoranv <gv@verizonmedia.com>2022-05-08 20:02:46 +0200
commit91449bc0aa5bf0196f0be48add49098865702f4a (patch)
tree5f4e641247d1455e9b245e16b373fd9def627eff
parentca729113517a0671a539db5eec49475a137a0791 (diff)
Don't try to resolve from the system bundle for test frameworks
.. as they have none.
-rw-r--r--container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java27
1 files changed, 15 insertions, 12 deletions
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 761d4057db3..1e171a19b05 100644
--- a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
+++ b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
@@ -39,7 +39,7 @@ public class OsgiImpl implements Osgi {
if (initialBundles.isEmpty())
throw new IllegalStateException("No initial bundles!");
- systemBundle = getSystemBundle(initialBundles);
+ systemBundle = getSystemBundle(initialBundles, jdiscOsgi);
alwaysCurrentBundle = firstNonFrameworkBundle(initialBundles);
if (alwaysCurrentBundle == null)
throw new IllegalStateException("The initial bundles only contained the framework bundle!");
@@ -76,17 +76,19 @@ public class OsgiImpl implements Osgi {
try {
return (Class<Object>) Class.forName(spec.classId.getName());
} catch (ClassNotFoundException e) {
- log.fine(() -> "Resolving class from the system bundle (jdisc core): " + spec.classId.getName());
- try {
- return (Class<Object>) systemBundle.loadClass(spec.classId.getName());
- } catch (ClassNotFoundException e2) {
- 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 +
- ". 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.");
+ if (hasFelixFramework()) {
+ log.fine(() -> "Resolving class from the system bundle (jdisc core): " + spec.classId.getName());
+ try {
+ return (Class<Object>) systemBundle.loadClass(spec.classId.getName());
+ } catch (ClassNotFoundException e2) {
+ // empty
+ }
}
}
+ 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 + ". 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.");
}
@SuppressWarnings("unchecked")
@@ -171,12 +173,13 @@ public class OsgiImpl implements Osgi {
return jdiscOsgi.isFelixFramework();
}
- private static Bundle getSystemBundle(List<Bundle> bundles ) {
+ private static Bundle getSystemBundle(List<Bundle> bundles, OsgiFramework jdiscOsgi) {
for (Bundle b : bundles) {
if (b instanceof Framework)
return b;
}
- throw new IllegalStateException("No system bundle in " + bundles);
+ if (jdiscOsgi.isFelixFramework()) throw new IllegalStateException("No system bundle in " + bundles);
+ return null;
}
private static Bundle firstNonFrameworkBundle(List<Bundle> bundles) {