From c2ceed510d7d94c3062c09c3ac189cde61e94e22 Mon Sep 17 00:00:00 2001 From: Dmitry Sklyut Date: Tue, 23 Dec 2014 18:52:34 -0500 Subject: [PATCH] ignore start option for fragment bundles. skip fragment bundles during 'pax.exam.osgi.unresolved.fail' key check --- .../exam/nat/internal/NativeTestContainer.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/containers/pax-exam-container-native/src/main/java/org/ops4j/pax/exam/nat/internal/NativeTestContainer.java b/containers/pax-exam-container-native/src/main/java/org/ops4j/pax/exam/nat/internal/NativeTestContainer.java index 9febe2a8f..724769a0f 100644 --- a/containers/pax-exam-container-native/src/main/java/org/ops4j/pax/exam/nat/internal/NativeTestContainer.java +++ b/containers/pax-exam-container-native/src/main/java/org/ops4j/pax/exam/nat/internal/NativeTestContainer.java @@ -57,6 +57,7 @@ import org.ops4j.pax.exam.options.ValueOption; import org.ops4j.pax.exam.options.extra.CleanCachesOption; import org.ops4j.pax.exam.options.extra.RepositoryOption; +import org.ops4j.pax.swissbox.core.BundleUtils; import org.ops4j.pax.swissbox.tracker.ServiceLookup; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -310,11 +311,10 @@ private void installAndStartBundles(BundleContext context) throws BundleExceptio int startLevel = getStartLevel(bundle); BundleStartLevel sl = b.adapt(BundleStartLevel.class); sl.setStartLevel(startLevel); - if (bundle.shouldStart()) { + if (bundle.shouldStart() && ! isFragment(b)) { try { b.start(); - } - catch (BundleException e) { + } catch (BundleException e) { throw new BundleException("Error starting bundle " + b.getSymbolicName() + ". " + e.getMessage(), e); } LOG.debug("+ Install (start@{}) {}", startLevel, bundle); @@ -384,14 +384,13 @@ public void frameworkEvent(FrameworkEvent frameworkEvent) { private void verifyThatBundlesAreResolved(List bundles) { boolean hasUnresolvedBundles = false; for (Bundle bundle : bundles) { - if (bundle.getState() == Bundle.INSTALLED) { + if (bundle.getState() == Bundle.INSTALLED && !isFragment(bundle)) { LOG.error("Bundle [{}] is not resolved", bundle); hasUnresolvedBundles = true; } } ConfigurationManager cm = new ConfigurationManager(); - boolean failOnUnresolved = Boolean.parseBoolean(cm.getProperty(EXAM_FAIL_ON_UNRESOLVED_KEY, - "false")); + boolean failOnUnresolved = Boolean.parseBoolean(cm.getProperty(EXAM_FAIL_ON_UNRESOLVED_KEY, "false")); if (hasUnresolvedBundles && failOnUnresolved) { throw new TestContainerException( "There are unresolved bundles. See previous ERROR log messages for details."); @@ -469,4 +468,8 @@ public synchronized void uninstallProbe() { throw new TestContainerException(exc); } } + + private boolean isFragment(Bundle bundle) { + return bundle.getHeaders().get(org.osgi.framework.Constants.FRAGMENT_HOST) != null; + } }