Пример #1
0
  private int executeScriptFile(
      CommandLine commandLine,
      String scriptName,
      String env,
      GantBinding binding,
      Resource scriptFile) {
    // We can now safely set the default environment
    String scriptFileName = getScriptNameFromFile(scriptFile);
    setRunningEnvironment(commandLine, env);
    binding.setVariable("scriptName", scriptFileName);

    // Setup the script to call.
    ScriptBindingInitializer bindingInitializer =
        new ScriptBindingInitializer(commandLine, settings, pluginPathSupport, isInteractive);
    Gant gant = new Gant(bindingInitializer.initBinding(binding, scriptName), classLoader);
    gant.setUseCache(true);
    gant.setCacheDirectory(scriptCacheDir);
    GantResult result = null;
    try {
      gant.loadScript(scriptFile.getURL());
      result = executeWithGantInstance(gant, DO_NOTHING_CLOSURE);
      return result.exitCode;
    } catch (IOException e) {
      console.error("I/O exception loading script [" + e.getMessage() + "]: " + e.getMessage());
      return 1;
    } finally {
      cleanup(result, binding);
    }
  }
Пример #2
0
  private int attemptPrecompiledScriptExecute(
      CommandLine commandLine,
      String scriptName,
      String env,
      GantBinding binding,
      List<File> allScripts) {
    console.updateStatus("Running pre-compiled script");

    // Must be called before the binding is initialised.
    setRunningEnvironment(commandLine, env);

    // Get Gant to load the class by name using our class loader.
    ScriptBindingInitializer bindingInitializer =
        new ScriptBindingInitializer(
            commandLine, classLoader, settings, pluginPathSupport, isInteractive);
    Gant gant = new Gant(bindingInitializer.initBinding(binding, scriptName), classLoader);

    try {
      loadScriptClass(gant, scriptName);
    } catch (ScriptNotFoundException e) {
      if (!isInteractive || InteractiveMode.isActive()) {
        throw e;
      }
      scriptName = fixScriptName(scriptName, allScripts);
      if (scriptName == null) {
        throw e;
      }

      try {
        loadScriptClass(gant, scriptName);
      } catch (ScriptNotFoundException ce) {
        return executeScriptWithCaching(commandLine, scriptName, env);
      }

      // at this point if they were calling a script that has a non-default
      // env (e.g. war or test-app) it wouldn't have been correctly set, so
      // set it now, but only if they didn't specify the env (e.g. "grails test war" -> "grails test
      // war")

      if (Boolean.TRUE.toString().equals(System.getProperty(Environment.DEFAULT))) {
        commandLine.setCommand(GrailsNameUtils.getScriptName(scriptName));
        env = commandLine.lookupEnvironmentForCommand();
        binding.setVariable("grailsEnv", env);
        settings.setGrailsEnv(env);
        System.setProperty(Environment.KEY, env);
        settings.setDefaultEnv(false);
        System.setProperty(Environment.DEFAULT, Boolean.FALSE.toString());
      }
    }

    return executeWithGantInstance(gant, DO_NOTHING_CLOSURE, binding).exitCode;
  }