// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/Constants.java
// @SuppressWarnings("SpellCheckingInspection")
// public static final String ICACLS_TOOL_NAME = "ICACLS";


import static jetbrains.buildServer.runAs.agent.Constants.ICACLS_TOOL_NAME;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import jetbrains.buildServer.ExecResult;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineArgument;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineResource;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineSetup;
import jetbrains.buildServer.util.*;
import org.jetbrains.annotations.NotNull;
      grantedPermissionList.add("RX");
    }

    List<String> deniedPermissionList = new ArrayList<String>();
    if(permissions.contains(AccessPermissions.DenyRead)) {
      deniedPermissionList.add("R");
    }

    if(permissions.contains(AccessPermissions.DenyWrite)) {
      deniedPermissionList.add("W,D,DC");
    }

    if(permissions.contains(AccessPermissions.DenyExecute)) {
      deniedPermissionList.add("X");
    }

    if(grantedPermissionList.size() > 0) {
      args.add(new CommandLineArgument("/grant", CommandLineArgument.Type.PARAMETER));
      final boolean recursive = permissions.contains(AccessPermissions.Recursive);
      final String permissionsStr = username + ":" + (recursive ? "(OI)(CI)" : "") + "(" + StringUtil.join(grantedPermissionList, ",") + ")";
      args.add(new CommandLineArgument(permissionsStr, CommandLineArgument.Type.PARAMETER));
    }

    if(deniedPermissionList.size() > 0) {
      args.add(new CommandLineArgument("/deny", CommandLineArgument.Type.PARAMETER));
      final boolean recursive = permissions.contains(AccessPermissions.Recursive);
      final String permissionsStr = username + ":" + (recursive ? "(OI)(CI)" : "") + "(" + StringUtil.join(deniedPermissionList, ",") + ")";
      args.add(new CommandLineArgument(permissionsStr, CommandLineArgument.Type.PARAMETER));
    }

// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/Constants.java
// @SuppressWarnings("SpellCheckingInspection")
// public static final String ICACLS_TOOL_NAME = "ICACLS";


// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/WindowsFileAccessService.java
import static jetbrains.buildServer.runAs.agent.Constants.ICACLS_TOOL_NAME;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import jetbrains.buildServer.ExecResult;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineArgument;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineResource;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineSetup;
import jetbrains.buildServer.util.*;
import org.jetbrains.annotations.NotNull;

      grantedPermissionList.add("RX");
    }

    List<String> deniedPermissionList = new ArrayList<String>();
    if(permissions.contains(AccessPermissions.DenyRead)) {
      deniedPermissionList.add("R");
    }

    if(permissions.contains(AccessPermissions.DenyWrite)) {
      deniedPermissionList.add("W,D,DC");
    }

    if(permissions.contains(AccessPermissions.DenyExecute)) {
      deniedPermissionList.add("X");
    }

    if(grantedPermissionList.size() > 0) {
      args.add(new CommandLineArgument("/grant", CommandLineArgument.Type.PARAMETER));
      final boolean recursive = permissions.contains(AccessPermissions.Recursive);
      final String permissionsStr = username + ":" + (recursive ? "(OI)(CI)" : "") + "(" + StringUtil.join(grantedPermissionList, ",") + ")";
      args.add(new CommandLineArgument(permissionsStr, CommandLineArgument.Type.PARAMETER));
    }

    if(deniedPermissionList.size() > 0) {
      args.add(new CommandLineArgument("/deny", CommandLineArgument.Type.PARAMETER));
      final boolean recursive = permissions.contains(AccessPermissions.Recursive);
      final String permissionsStr = username + ":" + (recursive ? "(OI)(CI)" : "") + "(" + StringUtil.join(deniedPermissionList, ",") + ")";
      args.add(new CommandLineArgument(permissionsStr, CommandLineArgument.Type.PARAMETER));
    }

    final CommandLineSetup icaclsCommandLineSetup = new CommandLineSetup(ICACLS_TOOL_NAME, args, Collections.<CommandLineResource>emptyList());