public Iterable build()

in runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/RunAsPlatformSpecificSetupBuilder.java [63:116]


  public Iterable<CommandLineSetup> build(@NotNull final CommandLineSetup commandLineSetup) {
    // Get userCredentials
    final UserCredentials userCredentials = myUserCredentialsService.tryGetUserCredentials();
    if(userCredentials == null) {
      return Collections.singleton(commandLineSetup);
    }

    if(!myRunAsAccessService.getIsRunAsEnabled()) {
      throw new BuildStartException("RunAs is not enabled");
    }

    // Resources
    final ArrayList<CommandLineResource> resources = new ArrayList<CommandLineResource>();
    resources.addAll(commandLineSetup.getResources());

    // Settings
    final File settingsFile = myFileService.getTempFileName(ARGS_EXT);
    resources.add(new CommandLineFile(myBeforeBuildPublisher, settingsFile.getAbsoluteFile(), myUserCredentialsGenerator.create(userCredentials)));

    // Command
    List<CommandLineArgument> cmdLineArgs = new ArrayList<CommandLineArgument>();
    cmdLineArgs.add(new CommandLineArgument(commandLineSetup.getToolPath(), CommandLineArgument.Type.PARAMETER));
    cmdLineArgs.addAll(commandLineSetup.getArgs());

    final RunAsParams params = new RunAsParams(cmdLineArgs);

    final File commandFile = myFileService.getTempFileName(myCommandFileExtension);
    resources.add(new CommandLineFile(myBeforeBuildPublisher, commandFile.getAbsoluteFile(), myRunAsCmdGenerator.create(params)));
    final ArrayList<AccessControlEntry> acl = new ArrayList<AccessControlEntry>();
    for (AccessControlEntry ace: myAccessControlListProvider.getAcl(userCredentials)) {
      acl.add(ace);
    }

    acl.add(new AccessControlEntry(commandFile, AccessControlAccount.forUser(userCredentials.getUser()), EnumSet.of(AccessPermissions.GrantExecute), AccessControlScope.Step));

    final File runAsToolPath = getTool();
    final AccessControlEntry runAsToolAce = new AccessControlEntry(runAsToolPath, AccessControlAccount.forUser(userCredentials.getUser()), EnumSet.of(AccessPermissions.GrantExecute), AccessControlScope.Build);
    acl.add(runAsToolAce);

    myAccessControlResource.setAcl(new AccessControlList(acl));
    resources.add(myAccessControlResource);

    final CommandLineSetup runAsCommandLineSetup = new CommandLineSetup(
      runAsToolPath.getAbsolutePath(),
      Arrays.asList(
        new CommandLineArgument(settingsFile.getAbsolutePath(), CommandLineArgument.Type.PARAMETER),
        new CommandLineArgument(commandFile.getAbsolutePath(), CommandLineArgument.Type.PARAMETER),
        new CommandLineArgument(myBuildAgentSystemInfo.bitness().toString(), CommandLineArgument.Type.PARAMETER),
        new CommandLineArgument(myArgumentConverter.convert(userCredentials.getPassword()), CommandLineArgument.Type.PARAMETER)),
      resources);

    myRunAsLogger.LogRunAs(userCredentials, commandLineSetup, runAsCommandLineSetup);
    return Collections.singleton(runAsCommandLineSetup);
  }