コード例 #1
0
  protected void initOsgiRuntime() throws Exception {
    try {
      if (!restart) {
        Environment.setDefault(null);
        if (System.getProperties().remove("nuxeo.home") != null) {
          log.warn("Removed System property nuxeo.home.");
        }
        workingDir =
            File.createTempFile(
                "nxruntime-" + Thread.currentThread().getName() + "-", null, new File("target"));
        workingDir.delete();
      }
    } catch (IOException e) {
      log.error("Could not init working directory", e);
      throw e;
    }
    osgi = new OSGiAdapter(workingDir);
    BundleFile bf = new SystemBundleFile(workingDir);
    bundleLoader = new StandaloneBundleLoader(osgi, NXRuntimeTestCase.class.getClassLoader());
    SystemBundle systemBundle =
        new SystemBundle(osgi, bf, bundleLoader.getSharedClassLoader().getLoader());
    osgi.setSystemBundle(systemBundle);
    Thread.currentThread().setContextClassLoader(bundleLoader.getSharedClassLoader().getLoader());

    for (WorkingDirectoryConfigurator cfg : wdConfigs) {
      cfg.configure(this, workingDir);
    }

    bundleLoader.setScanForNestedJARs(false); // for now
    bundleLoader.setExtractNestedJARs(false);

    BundleFile bundleFile = lookupBundle("org.nuxeo.runtime");
    runtimeBundle =
        new RootRuntimeBundle(osgi, bundleFile, bundleLoader.getClass().getClassLoader(), true);
    runtimeBundle.start();

    runtime = handleNewRuntime((OSGiRuntimeService) Framework.getRuntime());

    assertNotNull(runtime);
  }