Example #1
0
  @Override
  protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();

    configuration = new HashMap<String, Object>();
    configuration.put(
        Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, new File(tmp, "fwstorage").getAbsolutePath());
    configuration.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.4");
    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    BundleContext context = framework.getBundleContext();

    String[] bundles = {
      "../cnf/repo/osgi.cmpn/osgi.cmpn-4.3.1.jar", "testdata/slf4j-simple-1.7.12.jar",
      "testdata/slf4j-api-1.7.12.jar", "testdata/org.apache.aries.util-1.1.0.jar",
      "testdata/org.apache.aries.jmx-1.1.1.jar", "generated/biz.aQute.remote.test.jmx.jar"
    };

    for (String bundle : bundles) {
      String location = "reference:" + IO.getFile(bundle).toURI().toString();
      Bundle b = context.installBundle(location);
      if (!bundle.contains("slf4j-simple")) {
        b.start();
      }
    }

    super.setUp();
  }
  public MiniFramework(Map<Object, Object> properties) {
    this.properties = new Properties(System.getProperties());
    this.properties.putAll(properties);

    bundles.put(new Long(0), this);
    last = loader = getClass().getClassLoader();
  }
  public Bundle installBundle(String location) throws BundleException {
    try {
      if (location.startsWith("reference:"))
        location = new File(new URL(location.substring("reference:".length())).toURI()).getPath();
      else if (location.startsWith("file:"))
        location = new File(location.substring("file:".length())).getPath();

      while (location.startsWith("//")) location = location.substring(1);

      Context c = new Context(this, last, ++ID, location);
      bundles.put(new Long(c.id), c);
      last = c;
      return c;
    } catch (Exception e) {
      throw new BundleException("Failed to install", e);
    }
  }
 public Bundle installBundle(String location, InputStream in) throws BundleException {
   Context c;
   try {
     in.close();
     try {
       @SuppressWarnings("unused")
       URL url = new URL(location);
     } catch (MalformedURLException e) {
       throw new BundleException(
           "For the mini framework, the location must be a proper URL even though this is not required by the specification "
               + location,
           e);
     }
     c = new Context(this, last, ++ID, location);
     bundles.put(new Long(c.id), c);
     last = c;
     return c;
   } catch (Exception e) {
     throw new BundleException("Can't install " + location, e);
   }
 }
 public Bundle[] getBundles() {
   Bundle[] bs = new Bundle[bundles.size()];
   return bundles.values().toArray(bs);
 }
 public Bundle getBundle(long id) {
   Long l = new Long(id);
   Bundle b = bundles.get(l);
   return b;
 }