// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/base/BaseDeployerRunner.java
// public abstract class BaseDeployerRunner implements AgentBuildRunner {
//   protected final ExtensionHolder myExtensionHolder;
// 
//   public BaseDeployerRunner(@NotNull final ExtensionHolder extensionHolder) {
//     myExtensionHolder = extensionHolder;
//   }
// 
//   @NotNull
//   @Override
//   public BuildProcess createBuildProcess(@NotNull final AgentRunningBuild runningBuild,
//                                          @NotNull final BuildRunnerContext context) throws RunBuildException {
// 
//     final Map<String, String> runnerParameters = context.getRunnerParameters();
//     final String username = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_USERNAME));
//     final String password = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_PASSWORD));
//     final String target = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_TARGET_URL));
//     final String sourcePaths = runnerParameters.get(DeployerRunnerConstants.PARAM_SOURCE_PATH);
// 
//     final Collection<ArtifactsPreprocessor> preprocessors = myExtensionHolder.getExtensions(ArtifactsPreprocessor.class);
// 
//     final ArtifactsBuilder builder = new ArtifactsBuilder();
//     builder.setPreprocessors(preprocessors);
//     builder.setBaseDir(runningBuild.getCheckoutDirectory());
//     builder.setArtifactsPaths(sourcePaths);
// 
//     final List<ArtifactsCollection> artifactsCollections = builder.build();
// 
//     return getDeployerProcess(context, username, password, target, artifactsCollections);
//   }
// 
//   protected abstract BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context,
//                                                      @NotNull final String username,
//                                                      @NotNull final String password,
//                                                      @NotNull final String target,
//                                                      @NotNull final List<ArtifactsCollection> artifactsCollections) throws RunBuildException;
// 
//   @NotNull
//   @Override
//   public abstract AgentBuildRunnerInfo getRunnerInfo();
// }
// 
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SMBRunnerConstants.java
// public class SMBRunnerConstants {
//   public static final String DNS_ONLY_NAME_RESOLUTION = "jetbrains.buildServer.deployer.smb.dns_only";
//   public static final String SHOULD_ENFORCE_SMB1 = "teamcity.deployer.smb.enforceSMBv1";
// }


import com.intellij.openapi.util.SystemInfo;
import jetbrains.buildServer.ExtensionHolder;
import jetbrains.buildServer.agent.AgentBuildRunnerInfo;
import jetbrains.buildServer.agent.BuildProcess;
import jetbrains.buildServer.agent.BuildRunnerContext;
import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection;
import jetbrains.buildServer.agent.plugins.beans.PluginDescriptor;
import jetbrains.buildServer.deployer.agent.base.BaseDeployerRunner;
import jetbrains.buildServer.deployer.common.SMBRunnerConstants;
import jetbrains.buildServer.serverSide.TeamCityProperties;
import jetbrains.buildServer.util.CollectionsUtil;
import jetbrains.buildServer.util.Converter;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.List;
      final String actualUsername;

      if (username.indexOf('\\') > -1) {
        domain = username.substring(0, username.indexOf('\\'));
        actualUsername = username.substring(username.indexOf('\\') + 1);
      } else {
        domain = "";
        actualUsername = username;
      }

      if (shouldEnforceSMBv1(context)) {
        context.getBuild().getBuildLogger().warning("Enforced deprecated SMB v1 usage");
        return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections);
      }

      if (SystemInfo.isJavaVersionAtLeast("1.7.0")) {
          context.getBuild().getBuildLogger().message("Using SMB v2/v3 protocol");
          return getSmbV2Process(context, actualUsername, password, domain, target,artifactsCollections);
      } else {
        context.getBuild().getBuildLogger().warning("Falling back to deprecated SMB v1. Update jvm to 1.7+ to use SMB v2");
        return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections);
      }

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  private boolean shouldEnforceSMBv1(@NotNull final BuildRunnerContext context) {
    boolean shouldEnforceOnBuild =
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/base/BaseDeployerRunner.java
// public abstract class BaseDeployerRunner implements AgentBuildRunner {
//   protected final ExtensionHolder myExtensionHolder;
// 
//   public BaseDeployerRunner(@NotNull final ExtensionHolder extensionHolder) {
//     myExtensionHolder = extensionHolder;
//   }
// 
//   @NotNull
//   @Override
//   public BuildProcess createBuildProcess(@NotNull final AgentRunningBuild runningBuild,
//                                          @NotNull final BuildRunnerContext context) throws RunBuildException {
// 
//     final Map<String, String> runnerParameters = context.getRunnerParameters();
//     final String username = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_USERNAME));
//     final String password = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_PASSWORD));
//     final String target = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_TARGET_URL));
//     final String sourcePaths = runnerParameters.get(DeployerRunnerConstants.PARAM_SOURCE_PATH);
// 
//     final Collection<ArtifactsPreprocessor> preprocessors = myExtensionHolder.getExtensions(ArtifactsPreprocessor.class);
// 
//     final ArtifactsBuilder builder = new ArtifactsBuilder();
//     builder.setPreprocessors(preprocessors);
//     builder.setBaseDir(runningBuild.getCheckoutDirectory());
//     builder.setArtifactsPaths(sourcePaths);
// 
//     final List<ArtifactsCollection> artifactsCollections = builder.build();
// 
//     return getDeployerProcess(context, username, password, target, artifactsCollections);
//   }
// 
//   protected abstract BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context,
//                                                      @NotNull final String username,
//                                                      @NotNull final String password,
//                                                      @NotNull final String target,
//                                                      @NotNull final List<ArtifactsCollection> artifactsCollections) throws RunBuildException;
// 
//   @NotNull
//   @Override
//   public abstract AgentBuildRunnerInfo getRunnerInfo();
// }
// 
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SMBRunnerConstants.java
// public class SMBRunnerConstants {
//   public static final String DNS_ONLY_NAME_RESOLUTION = "jetbrains.buildServer.deployer.smb.dns_only";
//   public static final String SHOULD_ENFORCE_SMB1 = "teamcity.deployer.smb.enforceSMBv1";
// }


// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/smb/SmbDeployerRunner.java
import com.intellij.openapi.util.SystemInfo;
import jetbrains.buildServer.ExtensionHolder;
import jetbrains.buildServer.agent.AgentBuildRunnerInfo;
import jetbrains.buildServer.agent.BuildProcess;
import jetbrains.buildServer.agent.BuildRunnerContext;
import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection;
import jetbrains.buildServer.agent.plugins.beans.PluginDescriptor;
import jetbrains.buildServer.deployer.agent.base.BaseDeployerRunner;
import jetbrains.buildServer.deployer.common.SMBRunnerConstants;
import jetbrains.buildServer.serverSide.TeamCityProperties;
import jetbrains.buildServer.util.CollectionsUtil;
import jetbrains.buildServer.util.Converter;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.List;

      final String actualUsername;

      if (username.indexOf('\\') > -1) {
        domain = username.substring(0, username.indexOf('\\'));
        actualUsername = username.substring(username.indexOf('\\') + 1);
      } else {
        domain = "";
        actualUsername = username;
      }

      if (shouldEnforceSMBv1(context)) {
        context.getBuild().getBuildLogger().warning("Enforced deprecated SMB v1 usage");
        return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections);
      }

      if (SystemInfo.isJavaVersionAtLeast("1.7.0")) {
          context.getBuild().getBuildLogger().message("Using SMB v2/v3 protocol");
          return getSmbV2Process(context, actualUsername, password, domain, target,artifactsCollections);
      } else {
        context.getBuild().getBuildLogger().warning("Falling back to deprecated SMB v1. Update jvm to 1.7+ to use SMB v2");
        return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections);
      }

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  private boolean shouldEnforceSMBv1(@NotNull final BuildRunnerContext context) {
    boolean shouldEnforceOnBuild =
            StringUtil.isTrue(context.getBuild().getSharedConfigParameters().get(SMBRunnerConstants.SHOULD_ENFORCE_SMB1));