private static Option getOptions( final Method methodName, final Collection<JUnit4ConfigMethod> configMethods) throws Exception { // always add the junit extender final DefaultCompositeOption option = new DefaultCompositeOption( mavenBundle() .groupId("org.ops4j.pax.exam") .artifactId("pax-exam") .version(Info.getPaxExamVersion()) .update(Info.isPaxExamSnapshotVersion()) .startLevel(START_LEVEL_SYSTEM_BUNDLES), mavenBundle() .groupId("org.ops4j.pax.exam") .artifactId("pax-exam-junit-extender") .version(Info.getPaxExamVersion()) .update(Info.isPaxExamSnapshotVersion()) .startLevel(START_LEVEL_SYSTEM_BUNDLES), mavenBundle() .groupId("org.ops4j.pax.exam") .artifactId("pax-exam-junit-extender-impl") .version(Info.getPaxExamVersion()) .update(Info.isPaxExamSnapshotVersion()) .startLevel(START_LEVEL_SYSTEM_BUNDLES)); // add options based on available configuration options from the test itself for (JUnit4ConfigMethod configMethod : configMethods) { if (configMethod.matches(methodName)) { option.add(configMethod.getOptions()); } } // add junit bundles, if the user did not add junit bundles into configuration if (OptionUtils.filter(JUnitBundlesOption.class, option).length == 0) { option.add(junitBundles()); } return option; }
public TestContainer start() throws TestContainerException { ClassLoader parent = null; try { final Map<String, String> p = new HashMap<String, String>(m_properties); String folder = p.get("org.osgi.framework.storage"); if (folder == null) { folder = System.getProperty("org.osgi.framework.storage"); } if (folder == null) { // folder = System.getProperty( "user.home" ) + File.separator + "osgi"; folder = getCache(); } LOG.debug("Cache folder set to " + folder); FileUtils.delete(new File(folder)); // load default stuff p.put("org.osgi.framework.storage", folder); // System.setProperty( "org.osgi.vendor.framework", "org.ops4j.pax.exam" ); p.put( "org.osgi.framework.system.packages.extra", "org.ops4j.pax.exam;version=" + skipSnapshotFlag(Info.getPaxExamVersion())); parent = Thread.currentThread().getContextClassLoader(); // Thread.currentThread().setContextClassLoader( null ); m_framework = m_frameworkFactory.newFramework(p); m_framework.init(); installAndStartBundles(m_framework.getBundleContext()); Thread.currentThread().setContextClassLoader(parent); } catch (Exception e) { throw new TestContainerException("Problem starting test container.", e); } finally { if (parent != null) { Thread.currentThread().setContextClassLoader(parent); } } return this; }