use of org.osgi.framework.launch.FrameworkFactory in project roboguice by roboguice.
the class OSGiContainerTest method testGuiceWorksInOSGiContainer.
//This test may fail if it is not run from ant, or if it is not run after ant has
//compiled & built jars. This is because the test is validating that the Guice jar
//is properly setup to load in an OSGi container
public void testGuiceWorksInOSGiContainer() throws Throwable {
// ask framework to clear cache on startup
Properties properties = new Properties();
properties.setProperty("org.osgi.framework.storage", BUILD_TEST_DIR + "/bundle.cache");
properties.setProperty("org.osgi.framework.storage.clean", "onFirstInit");
// test each available OSGi framework in turn
Iterator<FrameworkFactory> f = ServiceRegistry.lookupProviders(FrameworkFactory.class);
while (f.hasNext()) {
Framework framework = f.next().newFramework(properties);
framework.start();
BundleContext systemContext = framework.getBundleContext();
// load all the necessary bundles and start the OSGi test bundle
/*if[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
/*end[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/guava.jar");
systemContext.installBundle("reference:file:" + GUICE_JAR);
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();
framework.stop();
}
}
use of org.osgi.framework.launch.FrameworkFactory in project voltdb by VoltDB.
the class TestVoltCSVFormatter method setUp.
@Override
@Before
public void setUp() throws Exception {
List<String> packages = ImmutableList.<String>builder().add("org.voltcore.network").add("org.voltcore.logging").add("org.voltdb.importer").add("org.voltdb.importer.formatter").add("org.apache.log4j").add("org.voltdb.client").add("org.slf4j").add("org.voltcore.utils").add("com.google_voltpatches.common.base").add("com.google_voltpatches.common.collect").add("com.google_voltpatches.common.net").add("com.google_voltpatches.common.io").add("com.google_voltpatches.common.util.concurrent").build();
String tmpFilePath = System.getProperty(VOLT_TMP_DIR, System.getProperty("java.io.tmpdir"));
//Create a directory in temp + username
File f = new File(tmpFilePath, System.getProperty("user.name"));
String systemPackagesSpec = FluentIterable.from(packages).transform(appendVersion).join(COMMA_JOINER);
Map<String, String> m_frameworkProps = ImmutableMap.<String, String>builder().put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, systemPackagesSpec).put("org.osgi.framework.storage.clean", "onFirstInit").put("felix.cache.rootdir", f.getAbsolutePath()).put("felix.cache.locking", Boolean.FALSE.toString()).build();
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
m_framework = frameworkFactory.newFramework(m_frameworkProps);
m_framework.start();
m_bundle = m_framework.getBundleContext().installBundle("file:" + System.getProperty("user.dir") + "/bundles/voltcsvformatter.jar");
m_bundle.start();
}
use of org.osgi.framework.launch.FrameworkFactory in project aries by apache.
the class AriesRepositoryGenerator method startFramework.
/**
* Start OSGi framework and install the necessary bundles
* @return
* @throws BundleException
*/
public BundleContext startFramework() throws BundleException {
ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader.load(FrameworkFactory.class, getClass().getClassLoader());
Iterator<FrameworkFactory> factoryIterator = factoryLoader.iterator();
//Map<String, String> osgiPropertyMap = new HashMap<String, String>();
if (!!!factoryIterator.hasNext()) {
System.out.println("Unable to locate the osgi jar");
}
try {
FrameworkFactory frameworkFactory = factoryIterator.next();
framework = frameworkFactory.newFramework(Collections.EMPTY_MAP);
} catch (ServiceConfigurationError sce) {
sce.printStackTrace();
}
framework.init();
framework.start();
// install the bundles in the current directory
Collection<Bundle> installedBundles = new ArrayList<Bundle>();
File bundleDir = new File(".");
File[] jars = bundleDir.listFiles();
try {
for (File jar : jars) {
if (jar.isFile() && (jar.getName().endsWith(".jar"))) {
String location = URLDecoder.decode(jar.toURI().toURL().toExternalForm(), "UTF-8");
if (shouldInstall(location, getIgnoreList())) {
installedBundles.add(framework.getBundleContext().installBundle("reference:" + location));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
ServiceReference paRef = framework.getBundleContext().getServiceReference(PackageAdmin.class.getCanonicalName());
if (paRef != null) {
try {
PackageAdmin admin = (PackageAdmin) framework.getBundleContext().getService(paRef);
admin.resolveBundles(installedBundles.toArray(new Bundle[installedBundles.size()]));
} finally {
framework.getBundleContext().ungetService(paRef);
}
} else {
System.out.println("Unable to find the service reference for package admin");
}
//loop through the list of installed bundles to start them
for (Bundle bundle : installedBundles) {
try {
if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
//start the bundle using its activiation policy
bundle.start(Bundle.START_ACTIVATION_POLICY);
} else {
//nothing to start, we have got a fragment
}
} catch (BundleException e) {
e.printStackTrace();
continue;
}
}
return framework.getBundleContext();
}
use of org.osgi.framework.launch.FrameworkFactory in project karaf by apache.
the class Main method launch.
public void launch() throws Exception {
if (config == null) {
config = new ConfigProperties();
}
config.performInit();
if (config.delayConsoleStart) {
System.out.println(config.startupMessage);
}
String log4jConfigPath = System.getProperty("karaf.etc") + "/org.ops4j.pax.logging.cfg";
BootstrapLogManager.setProperties(config.props, log4jConfigPath);
lockCallback = new KarafLockCallback();
InstanceHelper.updateInstancePid(config.karafHome, config.karafBase, true);
BootstrapLogManager.configureLogger(LOG);
for (String provider : config.securityProviders) {
addSecurityProvider(provider);
}
List<File> bundleDirs = getBundleRepos();
ArtifactResolver resolver = new SimpleMavenResolver(bundleDirs);
// Start up the OSGI framework
ClassLoader classLoader = createClassLoader(resolver);
FrameworkFactory factory = loadFrameworkFactory(classLoader);
framework = factory.newFramework(config.props);
setLogger();
framework.init();
framework.getBundleContext().addFrameworkListener(lockCallback);
framework.start();
FrameworkStartLevel sl = framework.adapt(FrameworkStartLevel.class);
sl.setInitialBundleStartLevel(config.defaultBundleStartlevel);
// If we have a clean state, install everything
if (framework.getBundleContext().getBundles().length == 1) {
LOG.info("Installing and starting initial bundles");
File startupPropsFile = new File(config.karafEtc, STARTUP_PROPERTIES_FILE_NAME);
List<BundleInfo> bundles = readBundlesFromStartupProperties(startupPropsFile);
installAndStartBundles(resolver, framework.getBundleContext(), bundles);
LOG.info("All initial bundles installed and set to start");
}
ServerInfo serverInfo = new ServerInfoImpl(args, config);
framework.getBundleContext().registerService(ServerInfo.class, serverInfo, null);
activatorManager = new KarafActivatorManager(classLoader, framework);
activatorManager.startKarafActivators();
setStartLevel(config.lockStartLevel);
// Progress bar
if (config.delayConsoleStart) {
new StartupListener(LOG, framework.getBundleContext());
}
monitor();
registerSignalHandler();
watchdog();
}
use of org.osgi.framework.launch.FrameworkFactory in project karaf by apache.
the class Main method loadFrameworkFactory.
private FrameworkFactory loadFrameworkFactory(ClassLoader classLoader) throws Exception {
String factoryClass = config.frameworkFactoryClass;
if (factoryClass == null) {
InputStream is = classLoader.getResourceAsStream("META-INF/services/" + FrameworkFactory.class.getName());
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
factoryClass = br.readLine();
br.close();
}
FrameworkFactory factory = (FrameworkFactory) classLoader.loadClass(factoryClass).newInstance();
return factory;
}
Aggregations