微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.osgi.framework.launch.FrameworkFactory的实例源码

项目:osgi-in-action    文件Main.java   
/**
 * Simple method to parse meta-inf/services file for framework factory.
 * Currently,it assumes the first non-commented line is the class name
 * of the framework factory implementation.
 * @return The created <tt>FrameworkFactory</tt> instance.
 * @throws Exception if any errors occur.
**/
private static FrameworkFactory getFrameworkFactory() throws Exception {
  URL url = Main.class.getClassLoader().getResource(
    "meta-inf/services/org.osgi.framework.launch.FrameworkFactory");
  if (url != null) {
    BufferedReader br =
      new BufferedReader(new InputStreamReader(url.openStream()));
    try {
      for (String s = br.readLine(); s != null; s = br.readLine()) {
        s = s.trim();
        // Try to load first non-empty,non-commented line.
        if ((s.length() > 0) && (s.charat(0) != '#')) {
          return (FrameworkFactory) Class.forName(s).newInstance();
        }
      }
    } finally {
      if (br != null) br.close();
    }
  }

  throw new Exception("Could not find framework factory.");
}
项目:motech    文件MotechNativeTestContainerFactory.java   
@Override
public TestContainer[] create(ExamSystem system) {
    // we use ServiceLoader to load the Osgi Framework Factory
    List<TestContainer> containers = new ArrayList<>();
    Iterator<FrameworkFactory> factories = ServiceLoader.load(FrameworkFactory.class)
            .iterator();
    boolean factoryFound = false;

    while (factories.hasNext()) {
        try {
            containers.add(new MotechNativeTestContainer(system,factories.next()));
            factoryFound = true;
        } catch (IOException e) {
            throw new TestContainerException("Problem initializing container.",e);
        }
    }

    if (!factoryFound) {
        throw new TestContainerException(
                "No service org.osgi.framework.launch.FrameworkFactory found in meta-inf/services on classpath");
    }

    return containers.toArray(new TestContainer[containers.size()]);
}
项目:guice    文件OsgiContainerTest.java   
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
    for (FrameworkFactory frameworkFactory : ServiceLoader.load(FrameworkFactory.class)) {
      Framework framework = frameworkFactory.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();
    }
  }
项目:osgi_in_action-    文件Main.java   
/**
 * Simple method to parse meta-inf/services file for framework factory.
 * Currently,non-commented line.
        if ((s.length() > 0) && (s.charat(0) != '#')) {
          return (FrameworkFactory) Class.forName(s).newInstance();
        }
      }
    } finally {
      if (br != null) br.close();
    }
  }

  throw new Exception("Could not find framework factory.");
}
项目:gocd    文件FelixGoPluginosgiFramework.java   
@Override
public void start() {
    List<FrameworkFactory> frameworkFactories = IteratorUtils.toList(ServiceLoader.load(FrameworkFactory.class).iterator());

    if (frameworkFactories.size() != 1) {
        throw new RuntimeException("One Osgi framework expected. Got " + frameworkFactories.size() + ": " + frameworkFactories);
    }

    try {
        framework = getFelixFramework(frameworkFactories);
        framework.start();
        registerInternalServices(framework.getBundleContext());
    } catch (BundleException e) {
        throw new RuntimeException("Failed to initialize Osgi framework",e);
    }
}
项目:felinx    文件FrameworkRunner.java   
private static FrameworkFactory getFrameworkFactory() throws Exception {
    java.net.URL url = FrameworkRunner.class.getClassLoader().getResource(
            "meta-inf/services/org.osgi.framework.launch.FrameworkFactory");
    if (url != null) {
        BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
        try {
            for (String s = br.readLine(); s != null; s = br.readLine()) {
                s = s.trim();
                // Try to load first non-empty,non-commented line.
                if ((s.length() > 0) && (s.charat(0) != '#')) {
                    Debug.message("> FrameworkFactory class name: " + s);
                    return (FrameworkFactory) Class.forName(s).newInstance();
                }
            }
        } finally {
            if (br != null)
                br.close();
        }
    }

    throw new Exception("Could not find framework factory.");
}
项目:ch.vorburger.minecraft.osgi    文件OsgiFrameworkWrapper.java   
@SuppressWarnings("deprecation")
public OsgiFrameworkWrapper(File frameworkStorageDirectory,File bootBundlesDirectory,File hotBundlesDirectory) throws IOException {
    Map<String,String> config = new HashMap<>();
    // https://svn.apache.org/repos/asf/Felix/releases/org.apache.Felix.main-1.2.0/doc/launching-and-embedding-apache-Felix.html#LaunchingandEmbeddingApacheFelix-configproperty
    config.put("Felix.embedded.execution","true");
    config.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT,"J2SE-1.8");
    config.put(Constants.FRAMEWORK_STORAGE_CLEAN,Constants.FRAMEWORK_STORAGE_CLEAN_ONFirstiniT);
    config.put(Constants.FRAMEWORK_STORAGE,frameworkStorageDirectory.getAbsolutePath());
    // not FRAMEWORK_SYstemPACKAGES but _EXTRA
    config.put(Constants.FRAMEWORK_SYstemPACKAGES_EXTRA,new PackagesBuilder()
            .addPackage("org.slf4j","1.7")
            .addPackage("ch.vorburger.minecraft.osgi.api")
            .addPackage("ch.vorburger.minecraft.utils")
            .addPackageWithSubPackages("com.google.common","17.0.0")
            .addPackageWithSubPackages("com.flowpowered.math")
            .addPackageWithSubPackages("org.spongepowered.api")
            .addPackage("javax.inject")
            .addPackageWithSubPackages("com.google.inject")
            .build()
        );

    FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
    framework = frameworkFactory.newFramework(config);

    this.bootBundlesDirectory = bootBundlesDirectory;
    this.hotBundlesDirectory = hotBundlesDirectory;
}
项目:gvnix1    文件Main.java   
/**
 * Simple method to parse meta-inf/services file for framework factory.
 * Currently,it assumes the first non-commented line is the class name
 * of the framework factory implementation.
 * @return The created <tt>FrameworkFactory</tt> instance.
 * @throws Exception if any errors occur.
**/
private static FrameworkFactory getFrameworkFactory() throws Exception
{
    URL url = Main.class.getClassLoader().getResource(
        "meta-inf/services/org.osgi.framework.launch.FrameworkFactory");
    if (url != null)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
        try
        {
            for (String s = br.readLine(); s != null; s = br.readLine())
            {
                s = s.trim();
                // Try to load first non-empty,non-commented line.
                if ((s.length() > 0) && (s.charat(0) != '#'))
                {
                    return (FrameworkFactory) Class.forName(s).newInstance();
                }
            }
        }
        finally
        {
            if (br != null) br.close();
        }
    }

    throw new Exception("Could not find framework factory.");
}
项目:Purifinity    文件AbstractBundleTest.java   
@BeforeClass
public static void startOsgiContainer() throws BundleException,IOException {
    assertNull("Osgi framework is expected to be stopped.",osgiFramework);
    removeStorageDirectory();
    Map<String,String> map = new HashMap<>();
    map.put(Constants.FRAMEWORK_STORAGE,STORAGE_DIRECTORY);
    ServiceLoader<FrameworkFactory> frameworkFactory = ServiceLoader
            .load(FrameworkFactory.class);
    osgiFramework = frameworkFactory.iterator().next().newFramework(map);
    osgiFramework.start();
}
项目:incubator-taverna-osgi    文件OsgiLauncher.java   
/**
 * Starts the Osgi framework,installs and starts the bundles.
 *
 * @throws BundleException
 *             if the framework Could not be started
 */
public void start() throws BundleException {
    logger.info("Loading the Osgi Framework Factory");
    FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator()
            .next();

    logger.info("Creating the Osgi Framework");
    framework = frameworkFactory.newFramework(frameworkConfiguration);
    logger.info("Starting the Osgi Framework");
    framework.start();

    context = framework.getBundleContext();
    context.addServiceListener(new ServiceListener() {
        public void serviceChanged(ServiceEvent event) {
            ServiceReference serviceReference = event.getServiceReference();
            if (event.getType() == ServiceEvent.REGISTERED) {
                Object property = serviceReference
                        .getProperty("org.springframework.context.service.name");
                if (property != null) {
                    addStartedSpringContext(property.toString());
                }
            }
            logger.fine((event.getType() == ServiceEvent.REGISTERED ? "Registering : "
                    : "Unregistering : ") + serviceReference);
        }
    });

    installedBundles = installBundles(bundlesToInstall);

    List<Bundle> bundlesToStart = new ArrayList<Bundle>();
    for (Bundle bundle : installedBundles) {
        if ("org.springframework.osgi.extender".equals(bundle.getSymbolicName())) {
            springOsgiExtender = bundle;
        } else {
            bundlesToStart.add(bundle);
        }
    }
    startBundles(bundlesToStart);
}
项目:sensorhub    文件TestOsgi.java   
protected Framework getFramework()
{
    Iterator<FrameworkFactory> it = ServiceLoader.load(org.osgi.framework.launch.FrameworkFactory.class).iterator();
    assertTrue("No Osgi implementation found in classpath",it.hasNext());

    Map<String,String> osgiConfig = new HashMap<String,String>();
    //osgiConfig.put(Autoprocessor.AUTO_DEPLOY_DIR_PROPERY,"");
    osgiConfig.put("org.osgi.framework.storage",CACHE_FOLDER);
    osgiConfig.put("org.osgi.framework.storage.clean","onFirstinit");
    Framework fw = it.next().newFramework(osgiConfig);

    return fw;
}
项目:androsgi    文件OsgiRuntime.java   
private void initFramework(Properties properties) throws Exception{
    String factoryClass = properties.getProperty(FrameworkFactory.class.getName());
    if(factoryClass == null)
        throw new Exception("No FrameworkFactory available!");

    FrameworkFactory frameworkFactory = (FrameworkFactory) Class.forName(factoryClass).newInstance();

    Map<String,String> config = new HashMap<String,String>();
    String runproperties = properties.getProperty("-runproperties");
    if(runproperties!=null){
        StringTokenizer st = new StringTokenizer(runproperties,",");
        while(st.hasMoretokens()){
            String runproperty = st.nextToken();
            int equalsIndex = runproperty.indexOf('=');
            if(equalsIndex!=-1){
                String key = runproperty.substring(0,equalsIndex);
                String value = runproperty.substring(equalsIndex+1);
                config.put(key,value);
            }
        }
    }

    // point storage dir to internal storage
    config.put("org.osgi.framework.storage",(String)properties.getProperty("cacheDir"));
    // add framework exports
    config.put("org.osgi.framework.system.packages.extra",(String)properties.get("-runsystempackages"));
    framework = frameworkFactory.newFramework(config);
    framework.start();
}
项目:carbon-kernel    文件CarbonServer.java   
/**
 * Starts a Carbon server instance. This method returns only after the server instance stops completely.
 *
 * @throws Exception if error occurred
 */
public void start() throws Exception {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE,"Starting Carbon server instance.");
    }

    // Sets the server start time.
    System.setProperty(CARBON_START_TIME,Long.toString(System.currentTimeMillis()));

    try {
        // Creates an Osgi framework instance.
        ClassLoader fwkClassLoader = createOsgiFwkClassLoader();
        FrameworkFactory fwkFactory = loadOsgiFwkFactory(fwkClassLoader);
        framework = fwkFactory.newFramework(config.getProperties());

        setServerCurrentStatus(ServerStatus.STARTING);
        // Notify Carbon server start.
        dispatchEvent(CarbonServerEvent.STARTING);

        // Initialize and start Osgi framework.
        initAndStartOsgiFramework(framework);

        // Loads initial bundles listed in the launch.properties file.
        loadInitialBundles(framework.getBundleContext());

        setServerCurrentStatus(ServerStatus.STARTED);
        // This thread waits until the Osgi framework comes to a complete shutdown.
        waitForServerStop(framework);

        setServerCurrentStatus(ServerStatus.STOPPING);
        // Notify Carbon server shutdown.
        dispatchEvent(CarbonServerEvent.STOPPING);

    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(),e);
    }
}
项目:carbon-kernel    文件CarbonServer.java   
/**
 * Creates a new service loader for the given service type and class loader.
 * Load Osgi framework factory for the given class loader.
 *
 * @param classLoader The class loader to be used to load provider-configurations
 * @return framework factory for creating framework instances
 */
private FrameworkFactory loadOsgiFwkFactory(ClassLoader classLoader) {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE,"Loading Osgi FrameworkFactory implementation class from the classpath.");
    }

    ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class,classLoader);
    if (!loader.iterator().hasNext()) {
        throw new RuntimeException("An implementation of the " + FrameworkFactory.class.getName() +
                " must be available in the classpath");
    }
    return loader.iterator().next();
}
项目:planetBot    文件Launcher.java   
private void initialize() throws BundleException,URISyntaxException {

        Map<String,String> configMap = loadProperties();
        System.setProperty(LOG_CONfig_FILE_PROPERTY,configMap.get(LOG_CONfig_FILE_PROPERTY));

        System.out.println("Building Osgi Framework");
        FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
        Framework framework = frameworkFactory.newFramework(configMap);

        framework.init();
        // (9) Use the system bundle context to process the auto-deploy
        // and auto-install/auto-start properties.
        Autoprocessor.process(configMap,framework.getBundleContext());
        // (10) Start the framework.
        System.out.println("Starting Osgi Framework");
        framework.start();

        BundleContext context = framework.getBundleContext();
        // declarative services dependency is necessary,otherwise they won't be picked up!
        loadScrBundle(context);

        try {
            framework.waitForStop(0);
        } catch (InterruptedException e) {
            appendToFile(e);
            showErrorMessage();
        }
        System.exit(0);
    }
项目:guice-old    文件OsgiContainerTest.java   
public void testGuiceWorksInOsgiContainer()
      throws Throwable {

    // ask framework to clear cache on startup
    Properties properties = new Properties();
    properties.setProperty("org.osgi.framework.storage","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();
    }
  }
项目:gocd    文件FelixGoPluginosgiFrameworkTest.java   
@Before
public void setUp() throws Exception {
    initMocks(this);
    FelixGoPluginosgiFramework goPluginosgiFramwork = new FelixGoPluginosgiFramework(registry,systemEnvironment);

    spy = spy(goPluginosgiFramwork);
    when(framework.getBundleContext()).thenReturn(bundleContext);
    when(registry.getPlugin(TEST_SYMBOLIC_NAME)).thenReturn(descriptor);
    doReturn(framework).when(spy).getFelixFramework(Matchers.<List<FrameworkFactory>>anyObject());
}
项目:google-guice    文件OsgiContainerTest.java   
public void testGuiceWorksInOsgiContainer()
      throws Throwable {

    // ask framework to clear cache on startup
    Properties properties = new Properties();
    properties.setProperty("org.osgi.framework.storage","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:" + GUICE_JAR);
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();

      framework.stop();
    }
  }
项目:neoscada    文件Starter.java   
public void start ( final String[] args ) throws Exception
{
    if ( this.started )
    {
        return;
    }
    this.started = true;

    this.debug = Boolean.getBoolean ( "org.eclipse.scada.utils.osgi.daemon.debug" ); //$NON-NLS-1$
    if ( this.debug )
    {
        this.logger = new Formatter ( System.out );
    }

    final ServiceLoader<FrameworkFactory> loader = ServiceLoader.load ( FrameworkFactory.class );
    final Iterator<FrameworkFactory> i = loader.iterator ();
    if ( !i.hasNext () )
    {
        throw new IllegalStateException ( "No FrameworkFactory found!" );
    }

    final FrameworkFactory factory = i.next ();

    this.properties = new HashMap<String,String> ();

    for ( final String arg : args )
    {
        final String[] toks = arg.split ( "=",2 );
        if ( toks.length >= 2 )
        {
            this.properties.put ( toks[0],toks[1] );
        }
        else
        {
            this.properties.put ( toks[0],null );
        }
    }

    this.properties.put ( Constants.FRAMEWORK_BEGINNING_STARTLEVEL,"4" );

    this.framework = factory.newFramework ( this.properties );

    this.framework.init ();

    try
    {
        loadStartBundles ( this.framework,this.properties );
    }
    catch ( final Exception e )
    {
        this.framework.stop ();
        throw e;
    }

    this.framework.start ();
}
项目:pathvisio    文件PathVisioMain.java   
public void start() 
{       
    frame = new SplashFrame();

    final SwingWorker<Void,Integer> worker = new SwingWorker<Void,Integer>() {
        protected Void doInBackground() throws Exception {
            try {
                String factoryClass = getFactoryClass();
                FrameworkFactory factory = (FrameworkFactory) Class.forName(factoryClass).newInstance();

                Framework framework = factory.newFramework(getLaunchProperties());
                framework.start();

                context = framework.getBundleContext();
                BundleLoader loader = new BundleLoader(context);

                /* load embedded bundles,i.e. all bundles that are inside pathvisio.jar */ 
                System.out.println("Installing bundles that are embedded in the jar.");

                Set<String> jarNames = loader.getResourceListing(PathVisioMain.class);
                int cnt = 0;
                int total = jarNames.size() + pluginLocations.size();

                for (String s : jarNames) 
                {
                    String text = (s.length() > 50) ? s.substring(0,50) : s;
                    frame.getTextLabel().setText("<html>Install " + text + ".</html>");
                    frame.repaint();
                    publish(100 * (++cnt) / total);
                    loader.installEmbeddedBundle(s);
                }

                frame.getTextLabel().setText("<html>Install active plugins.</html>");
                frame.repaint();
                System.out.println("Installing bundles from directories specified on the command-line.");
                for(String location : pluginLocations) {
                    publish(100 * (++cnt) / total);
                    loader.loadFromParameter(location);
                }

                startBundles(context,loader.getBundles());

                frame.getTextLabel().setText("Start application.");
                frame.repaint();
            } catch(Exception ex) {
                reportException("Startup Error",ex);
                ex.printstacktrace();
            }
            return null;
        }

        protected void process(List<Integer> chunks) {
            for (Integer chunk : chunks) {
                frame.getProgressBar().setString("Installing modules..." + chunk + "%");
                frame.getProgressBar().setValue(chunk);
                frame.repaint();
            }
        }

        protected void done() {
            frame.setVisible(false);
        }

    };

    worker.execute();
}
项目:motech    文件MotechNativeTestContainer.java   
public MotechNativeTestContainer(ExamSystem system,FrameworkFactory frameworkFactory) throws IOException {
    super(system,frameworkFactory);
    examSystem = system;
}
项目:cirrus    文件CirrusAgentManager.java   
private Framework createFramework() throws IOException {
    final ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader.load(FrameworkFactory.class);
    final Iterator<FrameworkFactory> iterator = factoryLoader.iterator();
    final FrameworkFactory next = iterator.next();
    return next.newFramework(ConfigUtil.createFrameworkConfiguration());
}
项目:myHealthHub    文件FelixService.java   
@Override
public void onCreate() {
    super.onCreate();

    if(D) Log.d(TAG,"Setting up a thread for Felix.");

    Thread FelixThread = new Thread() {

        @Override
        public void run() {

            File dexOutputDir = getApplicationContext().getDir("transformationmanager",0);

            // if default bundles were not installed already,install them
            File f = new File(dexOutputDir.getAbsolutePath()+"/bundle");
            if(!f.isDirectory()) {
                if(D) Log.i(TAG,"Installing default bundles...");
                unzipBundles(FelixService.this.getResources().openRawResource(R.raw.bundles),dexOutputDir.getAbsolutePath()+"/");                    
            }       

            FelixConfig FelixConfig = new FelixConfig(dexOutputDir.getAbsolutePath());
            Map<String,String> configProperties = FelixConfig.getProperties2();

            try {
                FrameworkFactory frameworkFactory = new org.apache.Felix.framework.FrameworkFactory();

                FelixFramework = frameworkFactory.newFramework(configProperties);
                FelixFramework.init();
                Autoprocessor.process(configProperties,FelixFramework.getBundleContext());
                FelixFramework.start();

                // Registering the android context as an osgi service
                Hashtable<String,String> properties = new Hashtable<String,String>();
                properties.put("platform","android");
                FelixFramework.getBundleContext().registerService(
                        Context.class.getName(),getApplicationContext(),properties);

            } catch (Exception ex) {                    
                Log.e(TAG,"Felix Could not be started",ex);
                ex.printstacktrace();
            }
        }
    };

    FelixThread.setDaemon(true);
    FelixThread.start();

    LocalbroadcastManager.getInstance(this).registerReceiver(downloadReceiver,new IntentFilter(Felix_SUCCESSFUL_WEB_REQUEST));
}
项目:gocd    文件FelixGoPluginosgiFramework.java   
Framework getFelixFramework(List<FrameworkFactory> frameworkFactories) {
    return frameworkFactories.get(0).newFramework(generateOsgiFrameworkConfig());
}
项目:eosgi-maven-plugin    文件AnalyzeMojo.java   
private Framework startOsgiContainer(final String[] bundleLocations,final String tempDirPath) throws BundleException {
  FrameworkFactory frameworkFactory = ServiceLoader
      .load(FrameworkFactory.class).iterator().next();

  Map<String,String>();
  config.put("org.osgi.framework.system.packages","");
  config.put("osgi.configuration.area",tempDirPath);
  config.put("osgi.baseConfiguration.area",tempDirPath);
  config.put("osgi.sharedConfiguration.area",tempDirPath);
  config.put("osgi.instance.area",tempDirPath);
  config.put("osgi.user.area",tempDirPath);
  config.put("osgi.hook.configurators.exclude","org.eclipse.core.runtime.internal.adaptor.EclipseLogHook");

  Framework framework = frameworkFactory.newFramework(config);
  framework.init();

  BundleContext systemBundleContext = framework.getBundleContext();

  org.apache.maven.artifact.Artifact equinoxCompatibilityStateArtifact =
      pluginArtifactMap.get("org.eclipse.tycho:org.eclipse.osgi.compatibility.state");

  URI compatibilityBundleURI = equinoxCompatibilityStateArtifact.getFile().toURI();

  systemBundleContext.installBundle("reference:" + compatibilityBundleURI.toString());

  framework.start();

  for (String bundleLocation : bundleLocations) {
    try {
      systemBundleContext.installBundle(bundleLocation);
    } catch (BundleException e) {
      getLog().warn("Could not install bundle " + bundleLocation,e);
    }
  }
  FrameworkWiring frameworkWiring = framework
      .adapt(FrameworkWiring.class);
  frameworkWiring.resolveBundles(null);

  return framework;
}
项目:osgiserver    文件StandaloneBootstrap.java   
private static void initFelixFramework() throws IOException,BundleException {
    Properties configProps = _loadOsgiConfigProperties();

    // configure Felix auto-deploy directory
    String sAutoDeployDir = configProps.getProperty(Autoprocessor.AUTO_DEPLOY_DIR_PROPERY);
    if (sAutoDeployDir == null) {
        throw new RuntimeException("Can not find configuration ["
                + Autoprocessor.AUTO_DEPLOY_DIR_PROPERY + "] in file "
                + OsgiSERVER_Osgi_PROPERTIES.getAbsolutePath());
    }
    File fAutoDeployDir = new File(OsgiSERVER_HOME,sAutoDeployDir);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(Autoprocessor.AUTO_DEPLOY_DIR_PROPERY + ": "
                + fAutoDeployDir.getAbsolutePath());
    }
    configProps.setProperty(Autoprocessor.AUTO_DEPLOY_DIR_PROPERY,fAutoDeployDir.getAbsolutePath());

    // configure Felix temp (storage) directory
    String sCacheDir = configProps.getProperty(Constants.FRAMEWORK_STORAGE);
    if (sCacheDir == null) {
        throw new RuntimeException("Can not find configuration [" + Constants.FRAMEWORK_STORAGE
                + "] in file " + OsgiSERVER_Osgi_PROPERTIES.getAbsolutePath());
    } else if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(Constants.FRAMEWORK_STORAGE + ": " + sCacheDir);
    }
    File fCacheDir = new File(OsgiSERVER_HOME,sCacheDir);
    configProps.setProperty(Constants.FRAMEWORK_STORAGE,fCacheDir.getAbsolutePath());

    // configure Felix's File Install watch directory
    final String PROP_Felix_FILE_INSTALL_DIR = "Felix.fileinstall.dir";
    String sMonitorDir = configProps.getProperty(PROP_Felix_FILE_INSTALL_DIR);
    if (sMonitorDir != null) {
        File fMonitorDir = new File(OsgiSERVER_HOME,sMonitorDir);
        configProps.setProperty(PROP_Felix_FILE_INSTALL_DIR,fMonitorDir.getAbsolutePath());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(PROP_Felix_FILE_INSTALL_DIR + ": " + fMonitorDir.getAbsolutePath());
        }
    }

    // check for Felix's Remote Shell listen IP & Port
    if (LOGGER.isDebugEnabled()) {
        String remoteShellListenIp = configProps.getProperty("osgi.shell.telnet.ip");
        String remoteShellListenPort = configProps.getProperty("osgi.shell.telnet.port");
        LOGGER.debug("Remote Shell: " + remoteShellListenIp + ":" + remoteShellListenPort);
    }

    Map<String,String>();
    for (Entry<Object,Object> entry : configProps.entrySet()) {
        config.put(entry.getKey().toString(),entry.getValue().toString());
    }
    FrameworkFactory factory = new org.apache.Felix.framework.FrameworkFactory();
    framework = factory.newFramework(config);
    framework.init();
    Autoprocessor.process(configProps,framework.getBundleContext());
    _autoDeployBundles(fAutoDeployDir,framework);
    framework.start();
}
项目:logging-log4j2    文件OsgiTestRule.java   
public OsgiTestRule(final FrameworkFactory factory) {
    this.factory = factory;
}
项目:logging-log4j2    文件FelixLoadApiBundleTest.java   
@Override
protected FrameworkFactory getFactory() {
    return new org.apache.Felix.framework.FrameworkFactory();
}
项目:logging-log4j2    文件EquinoxLoadApiBundleTest.java   
@Override
protected FrameworkFactory getFactory() {
    return new EquinoxFactory();
}
项目:logging-log4j2    文件AbstractOsgiTest.java   
protected abstract FrameworkFactory getFactory();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。