@Override protected void setUp() throws Exception { tmp = IO.getFile("generated/tmp"); tmp.mkdirs(); IO.copy(IO.getFile("testdata/ws"), tmp); workspace = Workspace.getWorkspace(tmp); workspace.refresh(); InfoRepository repo = workspace.getPlugin(InfoRepository.class); t1 = create("bsn-1", new Version(1, 0, 0)); t2 = create("bsn-2", new Version(1, 0, 0)); repo.put(new FileInputStream(t1), null); repo.put(new FileInputStream(t2), null); t1 = repo.get("bsn-1", new Version(1, 0, 0), null); t2 = repo.get("bsn-2", new Version(1, 0, 0), null); repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null); workspace.getPlugins().add(repo); File storage = IO.getFile("generated/storage-1"); storage.mkdirs(); configuration = new HashMap<String, Object>(); configuration.put( Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath()); configuration.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2"); framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration); framework.init(); framework.start(); context = framework.getBundleContext(); location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString(); agent = context.installBundle(location); agent.start(); thread = new Thread() { @Override public void run() { try { Main.main( new String[] { "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et" }); } catch (Exception e) { e.printStackTrace(); } } }; thread.setDaemon(true); thread.start(); super.setUp(); }
@Override protected void tearDown() throws Exception { super.tearDown(); framework.stop(); IO.delete(tmp); Main.stop(); IO.delete(IO.getFile("generated/cache")); IO.delete(IO.getFile("generated/storage")); framework.waitForStop(100000); super.tearDown(); }
private void _setupScope() { if (_inScopeSetup) return; final Scope saveTLPref = _scope.getTLPreferred(); _scope.setTLPreferred(null); final Scope saveTL = Scope.getThreadLocal(); _scope.makeThreadLocal(); _inScopeSetup = true; try { Object fo = getConfigObject("framework"); if (fo != null) { Framework f = null; if (fo instanceof JSString) { f = Framework.byName(fo.toString(), null); // we allow people to just specify name _logger.info("Setting framework by name [" + fo.toString() + "]"); } else if (fo instanceof JSObjectBase) { JSObjectBase obj = (JSObjectBase) fo; if (obj.containsKey("name")) { String s = obj.getAsString("version"); f = Framework.byName(obj.getAsString("name"), s); _logger.info("Setting framework by name [" + obj.getAsString("name") + "]"); } else if (obj.containsKey("custom")) { Object o = obj.get("custom"); if (o instanceof JSObjectBase) { f = Framework.byCustom((JSObjectBase) o); _logger.info("Setting framework by custom [" + o + "]"); } else { throw new RuntimeException("Error - custom framework wasn't an object [" + o + "]"); } } else if (obj.containsKey("classname")) { f = Framework.byClass(obj.getAsString("classname")); _logger.info("Setting framework by class [" + obj.getAsString("classname") + "]"); } } if (f == null) { throw new RuntimeException("Error : can't find framework [" + fo + "]"); } f.install(this); } _runInitFiles(INIT_FILES); if (_adminContext != null) { _adminContext._scope.set("siteScope", _scope); _adminContext._setLocalObject(_localObject); } _lastScopeInitTime = _getScopeTime(); } catch (RuntimeException re) { _scopeInited = false; throw re; } catch (Exception e) { _scopeInited = false; throw new RuntimeException(e); } finally { _inScopeSetup = false; _scope.setTLPreferred(saveTLPref); if (saveTL != null) saveTL.makeThreadLocal(); this.approxSize(_rootContextReachable); } }