diff options
Diffstat (limited to 'vespa-osgi-testrunner')
-rw-r--r-- | vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java index 224105806b5..ccf963e2c3f 100644 --- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java +++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java @@ -45,14 +45,20 @@ public class JunitRunner extends AbstractComponent { private volatile Future<TestReport> execution; @Inject - public JunitRunner(OsgiFramework osgiFramework, TestRuntimeProvider testRuntimeProvider) { + public JunitRunner(OsgiFramework osgiFramework, + TestRuntimeProvider testRuntimeProvider) { this.testRuntimeProvider = testRuntimeProvider; - var tmp = osgiFramework.bundleContext(); + this.bundleContext = getUnrestrictedBundleContext(osgiFramework); + } + + // Hack to retrieve bundle context that allows access to other bundles + private static BundleContext getUnrestrictedBundleContext(OsgiFramework framework) { try { - var field = tmp.getClass().getDeclaredField("wrapped"); + BundleContext restrictedBundleContext = framework.bundleContext(); + var field = restrictedBundleContext.getClass().getDeclaredField("wrapped"); field.setAccessible(true); - bundleContext = (BundleContext) field.get(tmp); - } catch (NoSuchFieldException | IllegalAccessException e) { + return (BundleContext) field.get(restrictedBundleContext); + } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } } |