// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/Constants.java
// public class Constants {
//     // Plugin's ids
//     public static final String BUILD_FEATURE_TYPE = "runAs-build-feature";
//     public static final String RUN_AS_TOOL_NAME = "runAs";
// 
//     // Parameter names
//     public static final String USER = "teamcity.runAs.username";
//     public static final String PASSWORD = "secure:teamcity.runAs.password";
//     public static final String CONFIG_PASSWORD = "teamcity.runAs.password";
//     public static final String ADDITIONAL_ARGS = "teamcity.runAs.additionalCommandLine";
//     public static final String RUN_AS_ENABLED = "teamcity.agent.runAs.enabled";
//     public static final String CREDENTIALS_PROFILE_ID = "teamcity.runAs.profileId";
//     public static final String WINDOWS_INTEGRITY_LEVEL = "teamcity.runAs.windowsIntegrityLlevel";
//     public static final String LOGGING_LEVEL = "teamcity.runAs.loggingLevel";
//     public static final String ALLOW_CUSTOM_CREDENTIALS = "teamcity.runAs.allowCustomCredentials";
//     public static final String ALLOW_PROFILE_ID_FROM_SERVER = "teamcity.runAs.allowProfileIdFromServer";
//     public static final String CREDENTIALS_DIRECTORY = "teamcity.runAs.configDir";
//     public static final String RUN_AS_UI_ENABLED = "teamcity.runAs.ui.enabled";
//     public static final String RUN_AS_UI_STEPS_ENABLED = "teamcity.runAs.ui.steps.enabled";
//     public static final String RUN_AS_LOG_ENABLED = "teamcity.runAs.log.enabled";
//     public static final String RUN_AS_ACL = "teamcity.runAs.acl";
//     public static final String RUN_AS_ACL_DEFAULTS_ENABLED = "teamcity.runAs.acl.defaults.enabled";
// }
// 
// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/Constants.java
// public class Constants {
//     @SuppressWarnings("SpellCheckingInspection")
//     public static final String ICACLS_TOOL_NAME = "ICACLS";
//     public static final String CHMOD_TOOL_NAME = "chmod";
//     public static final String SU_TOOL_NAME = "su";
//     public static final String RUN_AS_WIN32_TOOL_NAME = "JetBrains.runAs.exe";
// }
// 
// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/Constants.java
// public static final String RUN_AS_TOOL_NAME = "runAs";


import com.intellij.execution.ExecutionException;
import com.intellij.openapi.diagnostic.Logger;
import java.io.File;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import jetbrains.buildServer.ExecResult;
import jetbrains.buildServer.agent.*;
import jetbrains.buildServer.dotNet.buildRunner.agent.BuildRunnerContextProvider;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineArgument;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineResource;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineSetup;
import jetbrains.buildServer.runAs.common.Constants;
import jetbrains.buildServer.util.EventDispatcher;
import jetbrains.buildServer.util.StringUtil;
import jetbrains.buildServer.util.positioning.PositionAware;
import jetbrains.buildServer.util.positioning.PositionConstraint;
import org.jetbrains.annotations.NotNull;
import static jetbrains.buildServer.runAs.agent.Constants.*;
import static jetbrains.buildServer.runAs.common.Constants.RUN_AS_TOOL_NAME;
  }

  @NotNull
  @Override
  public PositionConstraint getConstraint() {
    return PositionConstraint.first();
  }

  @Override
  public void agentInitialized(@NotNull final BuildAgent agent) {
    updateIsRunAsEnabled(agent.getConfiguration());
    super.agentInitialized(agent);
  }

  @Override
  public void buildStarted(@NotNull final AgentRunningBuild runningBuild) {
    myBuildRunnerContextProvider.initialize(((AgentRunningBuildEx)runningBuild).getCurrentRunnerContext());
    protectProperties(runningBuild);
    super.buildStarted(runningBuild);
  }

  @Override
  public void buildFinished(@NotNull final AgentRunningBuild build, @NotNull final BuildFinishedStatus buildStatus) {
    super.buildFinished(build, buildStatus);
    myBuildFileAccessCacheManager.reset();
  }

  private void updateIsRunAsEnabled(final @NotNull BuildAgentConfiguration config) {
    myIsRunAsEnabled = false;

// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/Constants.java
// public class Constants {
//     // Plugin's ids
//     public static final String BUILD_FEATURE_TYPE = "runAs-build-feature";
//     public static final String RUN_AS_TOOL_NAME = "runAs";
// 
//     // Parameter names
//     public static final String USER = "teamcity.runAs.username";
//     public static final String PASSWORD = "secure:teamcity.runAs.password";
//     public static final String CONFIG_PASSWORD = "teamcity.runAs.password";
//     public static final String ADDITIONAL_ARGS = "teamcity.runAs.additionalCommandLine";
//     public static final String RUN_AS_ENABLED = "teamcity.agent.runAs.enabled";
//     public static final String CREDENTIALS_PROFILE_ID = "teamcity.runAs.profileId";
//     public static final String WINDOWS_INTEGRITY_LEVEL = "teamcity.runAs.windowsIntegrityLlevel";
//     public static final String LOGGING_LEVEL = "teamcity.runAs.loggingLevel";
//     public static final String ALLOW_CUSTOM_CREDENTIALS = "teamcity.runAs.allowCustomCredentials";
//     public static final String ALLOW_PROFILE_ID_FROM_SERVER = "teamcity.runAs.allowProfileIdFromServer";
//     public static final String CREDENTIALS_DIRECTORY = "teamcity.runAs.configDir";
//     public static final String RUN_AS_UI_ENABLED = "teamcity.runAs.ui.enabled";
//     public static final String RUN_AS_UI_STEPS_ENABLED = "teamcity.runAs.ui.steps.enabled";
//     public static final String RUN_AS_LOG_ENABLED = "teamcity.runAs.log.enabled";
//     public static final String RUN_AS_ACL = "teamcity.runAs.acl";
//     public static final String RUN_AS_ACL_DEFAULTS_ENABLED = "teamcity.runAs.acl.defaults.enabled";
// }
// 
// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/Constants.java
// public class Constants {
//     @SuppressWarnings("SpellCheckingInspection")
//     public static final String ICACLS_TOOL_NAME = "ICACLS";
//     public static final String CHMOD_TOOL_NAME = "chmod";
//     public static final String SU_TOOL_NAME = "su";
//     public static final String RUN_AS_WIN32_TOOL_NAME = "JetBrains.runAs.exe";
// }
// 
// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/Constants.java
// public static final String RUN_AS_TOOL_NAME = "runAs";


// Path: runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/RunAsPropertiesExtension.java
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.diagnostic.Logger;
import java.io.File;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import jetbrains.buildServer.ExecResult;
import jetbrains.buildServer.agent.*;
import jetbrains.buildServer.dotNet.buildRunner.agent.BuildRunnerContextProvider;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineArgument;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineResource;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineSetup;
import jetbrains.buildServer.runAs.common.Constants;
import jetbrains.buildServer.util.EventDispatcher;
import jetbrains.buildServer.util.StringUtil;
import jetbrains.buildServer.util.positioning.PositionAware;
import jetbrains.buildServer.util.positioning.PositionConstraint;
import org.jetbrains.annotations.NotNull;
import static jetbrains.buildServer.runAs.agent.Constants.*;
import static jetbrains.buildServer.runAs.common.Constants.RUN_AS_TOOL_NAME;

  }

  @NotNull
  @Override
  public PositionConstraint getConstraint() {
    return PositionConstraint.first();
  }

  @Override
  public void agentInitialized(@NotNull final BuildAgent agent) {
    updateIsRunAsEnabled(agent.getConfiguration());
    super.agentInitialized(agent);
  }

  @Override
  public void buildStarted(@NotNull final AgentRunningBuild runningBuild) {
    myBuildRunnerContextProvider.initialize(((AgentRunningBuildEx)runningBuild).getCurrentRunnerContext());
    protectProperties(runningBuild);
    super.buildStarted(runningBuild);
  }

  @Override
  public void buildFinished(@NotNull final AgentRunningBuild build, @NotNull final BuildFinishedStatus buildStatus) {
    super.buildFinished(build, buildStatus);
    myBuildFileAccessCacheManager.reset();
  }

  private void updateIsRunAsEnabled(final @NotNull BuildAgentConfiguration config) {
    myIsRunAsEnabled = false;

    final ToolProvider toolProvider = myToolProvidersRegistry.findToolProvider(RUN_AS_TOOL_NAME);