private static String _getVersionForLibrary(Scope s, String name, AppContext ctxt) { final JSObject o1 = ctxt == null ? null : (JSObject) (s.get("version_" + ctxt.getEnvironmentName())); final JSObject o2 = (JSObject) s.get("version"); _libraryLogger.debug(ctxt + "\t versionConfig:" + (o1 != null) + " config:" + (o2 != null)); String version = _getString(name, o1, o2); if (version != null) return version; if (ctxt == null || ctxt._nonAdminParent == null) return null; return ctxt._nonAdminParent.getVersionForLibrary(name); }
public static AppContext findThreadLocal() { AppContext context = _tl.get(); if (context != null) return context; AppRequest req = AppRequest.getThreadLocal(); if (req != null) return req._context; Scope s = Scope.getThreadLocal(); if (s != null) { Object foo = s.get("__instance__"); if (foo instanceof AppContext) return (AppContext) foo; } return null; }
private AppContext( String root, File rootFile, String name, String environment, AppContext nonAdminParent) { super(name + ":" + environment); if (root == null) throw new NullPointerException("AppContext root can't be null"); if (rootFile == null) throw new NullPointerException("AppContext rootFile can't be null"); if (name == null) name = guessNameAndEnv(root).name; if (name == null) throw new NullPointerException("how could name be null"); _root = root; _rootFile = rootFile; _git = new GitDir(_rootFile); _name = name; _environment = environment; _nonAdminParent = nonAdminParent; _admin = _nonAdminParent != null; _codePrefix = _admin ? "/~~/modules/admin/" : ""; _moduleRegistry = ModuleRegistry.getNewGlobalChild(); if (_git.isValid()) { _gitBranch = _git.getBranchOrTagName(); _gitHash = _git.getCurrentHash(); } _isGrid = name.equals("grid"); _scope = new Scope( "AppContext:" + root + (_admin ? ":admin" : ""), _isGrid ? ed.cloud.Cloud.getInstance().getScope() : Scope.newGlobal(), null, Language.JS(), _rootFile); _scope.setGlobal(true); _initScope = _scope.child("_init"); _usage = new UsageTracker(this); _baseScopeInit(); _adminContext = _admin ? null : new AppContext(root, rootFile, name, environment, this); _rootContextReachable = new SeenPath(); if (!_admin) _logger.info( "Started Context. root:" + _root + " environment:" + environment + " git branch: " + _gitBranch); }
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); } }