Пример #1
0
  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);
  }
Пример #2
0
  /**
   * Given a context and an environment, sets up the app context. This will setup the adapter type,
   * load and alias any packages, and run an init file if specified.
   *
   * @param context context object to set up
   * @param env environment to use
   * @param name name of environment (for logging purposes only)
   * @param version version of env (for logging purposes only)
   */
  protected void _setupContext(
      final AppContext context, final Env env, String name, String version) {
    /*
     *   first, set the adapter type directly
     */

    String s = env._adapterType;

    AdapterType at = context.getAdapterTypeFromString(s);

    if (at == null) {
      throw new RuntimeException(
          "Error - no valid adapter type ["
              + s
              + "] specified in environment ["
              + name
              + ", "
              + version
              + "]");
    }

    context.setStaticAdapterTypeValue(at);

    /*
     *  next, if there are any packages, set them as well
     */

    List<Package> pkgs = env._packages;

    if (pkgs.size() > 0) {
      JSObject packages = (JSObject) context.getConfigObject("packages");
      if (packages == null) {
        packages = new JSDict();
        context.setConfigObject("packages", packages);
      }

      for (Package p : pkgs) {
        JSDict d = new JSDict();
        d.set("module", p._module);
        d.set("path", p._path);
        packages.set(p._name, d); // how do I specify version???
      }
    }

    /*
     *  if there's an init file specified, give it a try...
     */

    if (env._initFile != null && !env._initFile.equals("")) {
      try {
        context.runInitFile(env._initFile);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      context.addInitRefreshHook(
          new JSFunctionCalls0() {
            public Object call(Scope s, Object[] extra) {
              try {
                context.runInitFile(env._initFile);
              } catch (IOException e) {
                throw new RuntimeException(e);
              }
              return null;
            }
          });
    }

    /*
     * setup any additional init dependencies (files that will cause the
     * init sequence to be rerun when changed)
     */
    for (String dependency : env._initDependencies) {
      try {
        File dep = context.getFile(dependency);
        if (!dep.exists()) {
          throw new FileNotFoundException();
        }
        context.addInitDependency(context.getFile(dependency));
      } catch (FileNotFoundException e) {
        context.getLogger("frameworks").warn("init dependency not found : " + dependency);
      }
    }
  }