コード例 #1
0
 private static String _getString(String name, JSObject... places) {
   for (JSObject o : places) {
     if (o == null) continue;
     Object temp = o.get(name);
     if (temp == null) continue;
     return temp.toString();
   }
   return null;
 }
コード例 #2
0
  /**
   * updates the context to the correct branch based on environment and to the latest version of the
   * code if name or environemnt is missing, does nothing
   */
  public String updateCode() {

    if (!_git.isValid()) throw new RuntimeException(_rootFile + " is not a git repository");

    _logger.info("going to update code");
    _git.fullUpdate();

    if (_name == null || _environment == null) return getCurrentGitBranch();

    JSObject env = getEnvironmentObject();
    if (env == null) return null;

    String branch = env.get("branch").toString();
    _logger.info("updating to [" + branch + "]");

    _git.checkout(branch);
    Python.deleteCachedJythonFiles(_rootFile);

    return getCurrentGitBranch(true);
  }
コード例 #3
0
  private void _loadConfigFromCloudObject(JSObject o) {
    if (o == null) return;

    _configScope.putAll((JSObject) o.get("config"));
  }
コード例 #4
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);
      }
    }
  }