// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/Constants.java
// public static final String CHMOD_TOOL_NAME = "chmod";


import static jetbrains.buildServer.runAs.agent.Constants.CHMOD_TOOL_NAME;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.diagnostic.Logger;
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.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
          break;

        case All:
          permissionsList.add(0, "a-");
          break;
      }

      final Result<AccessControlEntry, Boolean> result = tryExecChmod(entry, permissionsList);
      if(result != null) {
        results.add(result);
      }
    }

    return results;
  }

  @Nullable
  private Result<AccessControlEntry, Boolean> tryExecChmod(@NotNull final AccessControlEntry entry, @NotNull final Iterable<String> chmodPermissions)
  {
    final String chmodPermissionsStr = StringUtil.join("", chmodPermissions);
    if(StringUtil.isEmptyOrSpaces(chmodPermissionsStr)) {
      return null;
    }

    final ArrayList<CommandLineArgument> args = new ArrayList<CommandLineArgument>();
    if (entry.getPermissions().contains(AccessPermissions.Recursive)) {
      args.add(new CommandLineArgument("-R", CommandLineArgument.Type.PARAMETER));
    }
    args.add(new CommandLineArgument(chmodPermissionsStr, CommandLineArgument.Type.PARAMETER));
    args.add(new CommandLineArgument(entry.getFile().getAbsolutePath(), CommandLineArgument.Type.PARAMETER));
// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/Constants.java
// public static final String CHMOD_TOOL_NAME = "chmod";


// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/LinuxFileAccessService.java
import static jetbrains.buildServer.runAs.agent.Constants.CHMOD_TOOL_NAME;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.diagnostic.Logger;
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.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

          break;

        case All:
          permissionsList.add(0, "a-");
          break;
      }

      final Result<AccessControlEntry, Boolean> result = tryExecChmod(entry, permissionsList);
      if(result != null) {
        results.add(result);
      }
    }

    return results;
  }

  @Nullable
  private Result<AccessControlEntry, Boolean> tryExecChmod(@NotNull final AccessControlEntry entry, @NotNull final Iterable<String> chmodPermissions)
  {
    final String chmodPermissionsStr = StringUtil.join("", chmodPermissions);
    if(StringUtil.isEmptyOrSpaces(chmodPermissionsStr)) {
      return null;
    }

    final ArrayList<CommandLineArgument> args = new ArrayList<CommandLineArgument>();
    if (entry.getPermissions().contains(AccessPermissions.Recursive)) {
      args.add(new CommandLineArgument("-R", CommandLineArgument.Type.PARAMETER));
    }
    args.add(new CommandLineArgument(chmodPermissionsStr, CommandLineArgument.Type.PARAMETER));
    args.add(new CommandLineArgument(entry.getFile().getAbsolutePath(), CommandLineArgument.Type.PARAMETER));
    final CommandLineSetup chmodCommandLineSetup = new CommandLineSetup(CHMOD_TOOL_NAME, args, Collections.<CommandLineResource>emptyList());