private File writeToTempFile()

in powershell-agent/src/main/java/jetbrains/buildServer/powershell/agent/ScriptGenerator.java [82:102]


  private File writeToTempFile(@NotNull final File buildTempDir,
                               @NotNull final String text,
                               @NotNull final Map<String, String> runnerParameters) throws RunBuildException {
    Closeable handle = null;
    File file;
    try {
      file = FileUtil.createTempFile(buildTempDir, "powershell", ".ps1", true);
      OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
      handle = w;
      if (PowerShellExecutionMode.PS1 == PowerShellExecutionMode.fromString(runnerParameters.get(RUNNER_EXECUTION_MODE))) {
        w.write(BOM);
      }
      w.write(text);
      return file;
    } catch (IOException e) {
      LOG.error("Error occurred while processing file for PowerShell script", e);
      throw new RunBuildException("Failed to generate temporary resulting PowerShell script due to exception", e);
    } finally {
      FileUtil.close(handle);
    }
  }